Skip to content

Commit 1fe09a1

Browse files
committed
Manage prowlarr via opentofu provider
1 parent 0160311 commit 1fe09a1

11 files changed

+813
-861
lines changed

apps/starr/prowlarr/base/main.k

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import file
2+
import json
23

34
import konfig.models.frontend
45
import konfig.models.frontend.secret
@@ -7,6 +8,7 @@ import konfig.files
78

89
import starr
910
import charts.prowlarr
11+
import charts.opentofu.api.v1beta1 as opentofu
1012

1113
_values = files.read_yaml(file.current(), "values.yaml")
1214

@@ -30,6 +32,78 @@ _prowlarrOIDCClient = secret.ExternalSecret {
3032
}
3133
}
3234

35+
_tfVars = secret.ExternalSecret {
36+
name = "prowlarr-tfvars"
37+
data: {
38+
SONARR_AUTH_APIKEY = {}
39+
RADARR_AUTH_APIKEY = {}
40+
PROWLARR_TV_MOVIE_INDEXER_IMPLEMENTATION = {}
41+
PROWLARR_TV_MOVIE_INDEXER_CONFIG_CONTRACT = {}
42+
PROWLARR_TV_MOVIE_INDEXER_BASE_URL = {}
43+
PROWLARR_TV_MOVIE_INDEXER_USERNAME = {}
44+
PROWLARR_TV_MOVIE_INDEXER_PASSWORD = {}
45+
PROWLARR_TV_MOVIE_INDEXER_PID = {}
46+
}
47+
target.template.data: {
48+
".auto.tfvars.json" = json.encode({
49+
"sonarr_auth_apikey" = "{{.SONARR_AUTH_APIKEY}}"
50+
"radarr_auth_apikey" = "{{.RADARR_AUTH_APIKEY}}"
51+
"tv_movie_indexer_implementation" = "{{.PROWLARR_TV_MOVIE_INDEXER_IMPLEMENTATION}}"
52+
"tv_movie_indexer_config_contract" = "{{.PROWLARR_TV_MOVIE_INDEXER_CONFIG_CONTRACT}}"
53+
"tv_movie_indexer_base_url" = "{{.PROWLARR_TV_MOVIE_INDEXER_BASE_URL}}"
54+
"tv_movie_indexer_username" = "{{.PROWLARR_TV_MOVIE_INDEXER_USERNAME}}"
55+
"tv_movie_indexer_password" = "{{.PROWLARR_TV_MOVIE_INDEXER_PASSWORD}}"
56+
"tv_movie_indexer_pid" = "{{.PROWLARR_TV_MOVIE_INDEXER_PID}}"
57+
})
58+
}
59+
}
60+
61+
tofuProvider = opentofu.ProviderConfig {
62+
metadata: {
63+
name = "prowlarr"
64+
namespace = "starr-prowlarr"
65+
}
66+
spec: {
67+
credentials = [{
68+
filename = "prowlarr-apikey"
69+
source = "Secret"
70+
secretRef: {
71+
namespace = "starr-prowlarr"
72+
name = _prowlarrCreds.name
73+
key = "PROWLARR_AUTH_APIKEY"
74+
}
75+
}]
76+
configuration = files.read_file(file.current(), "tofu/providers.tf")
77+
}
78+
}
79+
80+
tofuWorkspace = opentofu.Workspace {
81+
metadata: {
82+
name = "prowlarr"
83+
namespace = "starr-prowlarr"
84+
}
85+
spec: {
86+
providerConfigRef: {
87+
kind = "ProviderConfig"
88+
name = "prowlarr"
89+
}
90+
forProvider: {
91+
initArgs = ["-upgrade=true"]
92+
varFiles = [{
93+
source = "SecretKey"
94+
format = "JSON"
95+
secretKeyRef: {
96+
name = _tfVars.name
97+
key = ".auto.tfvars.json"
98+
}
99+
}]
100+
vars = []
101+
source = "Inline"
102+
module = files.read_file(file.current(), "tofu/main.tf")
103+
}
104+
}
105+
}
106+
33107
app = frontend.App {
34108
name = "prowlarr"
35109
tenantName = starr.tenant.name
@@ -38,6 +112,7 @@ app = frontend.App {
38112
externalSecrets: {
39113
prowlarrCreds = _prowlarrCreds
40114
prowlarrOIDCClient = _prowlarrOIDCClient
115+
prowlarrTFVars = _tfVars
41116
}
42117

43118
charts.prowlarr = prowlarr.Chart {
@@ -61,4 +136,9 @@ app = frontend.App {
61136
oidcIssuer = starr.tenant.oidcIssuer
62137
}
63138
}
139+
140+
extraResources: {
141+
tofuProvider = tofuProvider
142+
tofuWorkspace = tofuWorkspace
143+
}
64144
}
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
variable "sonarr_auth_apikey" {
2+
type = string
3+
sensitive = true
4+
}
5+
6+
variable "radarr_auth_apikey" {
7+
type = string
8+
sensitive = true
9+
}
10+
11+
variable "tv_movie_indexer_implementation" {
12+
type = string
13+
}
14+
15+
variable "tv_movie_indexer_config_contract" {
16+
type = string
17+
}
18+
19+
variable "tv_movie_indexer_base_url" {
20+
type = string
21+
}
22+
23+
variable "tv_movie_indexer_username" {
24+
type = string
25+
}
26+
27+
variable "tv_movie_indexer_password" {
28+
type = string
29+
sensitive = true
30+
}
31+
32+
variable "tv_movie_indexer_pid" {
33+
type = string
34+
sensitive = true
35+
}
36+
37+
locals {
38+
prowlarr_url = "http://prowlarr.starr-prowlarr.svc.cluster.local:9696"
39+
40+
tv_categories = [
41+
5000, # TV
42+
5010, # TV/WEB-DL
43+
5020, # TV/Foreign
44+
5030, # TV/SD
45+
5040, # TV/HD
46+
5045, # TV/UHD
47+
5050, # TV/Other
48+
5060, # TV/Sport
49+
5080, # TV/Documentary
50+
5090, # TV/x265
51+
]
52+
53+
anime_categories = [
54+
5070, # TV/Anime
55+
]
56+
57+
movie_categories = [
58+
2000, # Movies
59+
2010, # Movies/Foreign
60+
2020, # Movies/Other
61+
2030, # Movies/SD
62+
2040, # Movies/HD
63+
2045, # Movies/UHD
64+
2050, # Movies/BluRay
65+
2060, # Movies/3D
66+
2070, # Movies/DVD
67+
2080, # Movies/WEB-DL
68+
2090, # Movies/x265
69+
]
70+
}
71+
72+
resource "prowlarr_application_sonarr" "sonarr" {
73+
name = "Sonarr"
74+
sync_level = "fullSync"
75+
base_url = "http://sonarr.starr-sonarr.svc.cluster.local:8989"
76+
prowlarr_url = local.prowlarr_url
77+
api_key = var.sonarr_auth_apikey
78+
sync_categories = local.tv_categories
79+
anime_sync_categories = local.anime_categories
80+
}
81+
82+
resource "prowlarr_application_radarr" "radarr" {
83+
name = "Radarr"
84+
sync_level = "fullSync"
85+
base_url = "http://radarr.starr-radarr.svc.cluster.local:7878"
86+
prowlarr_url = local.prowlarr_url
87+
api_key = var.radarr_auth_apikey
88+
sync_categories = local.movie_categories
89+
}
90+
91+
resource "prowlarr_indexer" "tv_movie" {
92+
enable = true
93+
name = var.tv_movie_indexer_implementation
94+
implementation = var.tv_movie_indexer_implementation
95+
config_contract = var.tv_movie_indexer_config_contract
96+
app_profile_id = 1
97+
protocol = "torrent"
98+
99+
fields = [
100+
{
101+
name = "baseUrl"
102+
text_value = var.tv_movie_indexer_base_url
103+
},
104+
{
105+
name = "username"
106+
text_value = var.tv_movie_indexer_username
107+
},
108+
{
109+
name = "password"
110+
sensitive_value = var.tv_movie_indexer_password
111+
},
112+
{
113+
name = "pid"
114+
sensitive_value = var.tv_movie_indexer_pid
115+
},
116+
{
117+
name = "freeleechOnly"
118+
bool_value = false
119+
},
120+
{
121+
name = "baseSettings.queryLimit"
122+
number_value = 100
123+
},
124+
{
125+
name = "baseSettings.grabLimit"
126+
number_value = 25
127+
},
128+
{
129+
name = "baseSettings.limitsUnit"
130+
number_value = 0 # Days
131+
},
132+
{
133+
name = "torrentBaseSettings.appMinimumSeeders"
134+
number_value = 1
135+
},
136+
{
137+
name = "torrentBaseSettings.seedRatio"
138+
number_value = 2
139+
},
140+
{
141+
name = "torrentBaseSettings.seedTime"
142+
number_value = 129600
143+
},
144+
{
145+
name = "torrentBaseSettings.packSeedTime"
146+
number_value = 129600
147+
},
148+
{
149+
name = "torrentBaseSettings.preferMagnetUrl"
150+
bool_value = false
151+
}
152+
]
153+
}
154+
155+
resource "prowlarr_download_client_qbittorrent" "qbt_tv" {
156+
enable = true
157+
name = "qBittorrent-TV"
158+
host = "qbt-tv-web.starr-qbt-tv.svc.cluster.local"
159+
port = 8080
160+
161+
priority = 1 # Client Priority
162+
item_priority = 0 # Last
163+
initial_state = 0 # Start
164+
category = "tv-prowlarr"
165+
# categories = [{
166+
# name = "TV"
167+
# categories = local.tv_categories
168+
# }]
169+
}
170+
171+
resource "prowlarr_download_client_qbittorrent" "qbt_movies" {
172+
enable = true
173+
name = "qBittorrent-Movies"
174+
host = "qbt-movies-web.starr-qbt-movies.svc.cluster.local"
175+
port = 8080
176+
177+
priority = 1 # Client Priority
178+
item_priority = 0 # Last
179+
initial_state = 0 # Start
180+
category = "movies-prowlarr"
181+
# categories = [{
182+
# name = "Movies"
183+
# categories = local.movie_categories
184+
# }]
185+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
terraform {
2+
backend "kubernetes" {
3+
secret_suffix = "providerconfig"
4+
namespace = "starr-prowlarr"
5+
in_cluster_config = true
6+
}
7+
required_providers {
8+
prowlarr = {
9+
source = "devopsarr/prowlarr"
10+
version = "3.0.2"
11+
}
12+
}
13+
}
14+
15+
provider "prowlarr" {
16+
url = "http://prowlarr.starr-prowlarr.svc.cluster.local:9696"
17+
api_key = file("${path.module}/prowlarr-apikey")
18+
}

charts/charts.k

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,9 @@ charts: helm.Charts = {
342342
schemaGenerator = "NONE"
343343
crdGenerator = "PATH"
344344
crdPaths = [
345-
"https://doc.crds.dev/raw/github.com/upbound/provider-opentofu@v0.2.7"
345+
"https://raw.githubusercontent.com/upbound/provider-opentofu/refs/tags/v1.0.0/package/crds/opentofu.m.upbound.io_clusterproviderconfigs.yaml"
346+
"https://raw.githubusercontent.com/upbound/provider-opentofu/refs/tags/v1.0.0/package/crds/opentofu.m.upbound.io_providerconfigs.yaml"
347+
"https://raw.githubusercontent.com/upbound/provider-opentofu/refs/tags/v1.0.0/package/crds/opentofu.m.upbound.io_workspaces.yaml"
346348
]
347349
}
348350
truecommand: {

0 commit comments

Comments
 (0)