@cubocicloide/stack-react-fastapi 13.4.1 → 13.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/dist/index.js +2654 -329
  2. package/dist/index.js.map +1 -1
  3. package/package.json +2 -2
  4. package/templates/azure-aca/backend/Dockerfile.prod.hbs +29 -0
  5. package/templates/azure-aca/docs/docs/deploy.md.hbs +127 -0
  6. package/templates/azure-aca/frontend/Dockerfile.prod +36 -0
  7. package/templates/azure-aca/frontend/nginx.conf.template +47 -0
  8. package/templates/azure-aca/iac/README.md.hbs +286 -0
  9. package/templates/azure-aca/iac/_gitignore +19 -0
  10. package/templates/azure-aca/iac/runner/Dockerfile +51 -0
  11. package/templates/azure-aca/iac/terraform/bootstrap/main.tf.hbs +123 -0
  12. package/templates/azure-aca/iac/terraform/bootstrap/outputs.tf +24 -0
  13. package/templates/azure-aca/iac/terraform/bootstrap/variables.tf.hbs +23 -0
  14. package/templates/azure-aca/iac/terraform/environments/dev/backend.hcl.hbs +25 -0
  15. package/templates/azure-aca/iac/terraform/environments/dev/terraform.tfvars.hbs +69 -0
  16. package/templates/azure-aca/iac/terraform/main.tf.hbs +593 -0
  17. package/templates/azure-aca/iac/terraform/outputs.tf.hbs +72 -0
  18. package/templates/azure-aca/iac/terraform/providers.tf +16 -0
  19. package/templates/azure-aca/iac/terraform/variables.tf.hbs +200 -0
  20. package/templates/azure-aca/iac/terraform/versions.tf +21 -0
  21. package/templates/azure-aks/backend/Dockerfile.prod.hbs +29 -0
  22. package/templates/azure-aks/docs/docs/deploy.md.hbs +273 -0
  23. package/templates/azure-aks/frontend/Dockerfile.prod +32 -0
  24. package/templates/azure-aks/frontend/nginx.conf +20 -0
  25. package/templates/azure-aks/iac/README.md.hbs +472 -0
  26. package/templates/azure-aks/iac/_gitignore +29 -0
  27. package/templates/azure-aks/iac/helm/app/.helmignore +7 -0
  28. package/templates/azure-aks/iac/helm/app/Chart.yaml.hbs +6 -0
  29. package/templates/azure-aks/iac/helm/app/templates/NOTES.txt +32 -0
  30. package/templates/azure-aks/iac/helm/app/templates/backend-deployment.yaml +44 -0
  31. package/templates/azure-aks/iac/helm/app/templates/backend-service.yaml +16 -0
  32. package/templates/azure-aks/iac/helm/app/templates/celery-beat-deployment.yaml +34 -0
  33. package/templates/azure-aks/iac/helm/app/templates/celery-worker-deployment.yaml +31 -0
  34. package/templates/azure-aks/iac/helm/app/templates/configmap.yaml +15 -0
  35. package/templates/azure-aks/iac/helm/app/templates/flower-deployment.yaml +28 -0
  36. package/templates/azure-aks/iac/helm/app/templates/flower-service.yaml +19 -0
  37. package/templates/azure-aks/iac/helm/app/templates/frontend-deployment.yaml +34 -0
  38. package/templates/azure-aks/iac/helm/app/templates/frontend-service.yaml +16 -0
  39. package/templates/azure-aks/iac/helm/app/templates/helpers.tpl +90 -0
  40. package/templates/azure-aks/iac/helm/app/templates/hpa.yaml +23 -0
  41. package/templates/azure-aks/iac/helm/app/templates/ingress.yaml +35 -0
  42. package/templates/azure-aks/iac/helm/app/templates/migration-job.yaml +38 -0
  43. package/templates/azure-aks/iac/helm/app/templates/redis-deployment.yaml +33 -0
  44. package/templates/azure-aks/iac/helm/app/templates/redis-service.yaml +18 -0
  45. package/templates/azure-aks/iac/helm/app/templates/secret.yaml +17 -0
  46. package/templates/azure-aks/iac/helm/app/templates/serviceaccount.yaml +12 -0
  47. package/templates/azure-aks/iac/helm/app/values-dev.yaml.hbs +36 -0
  48. package/templates/azure-aks/iac/helm/app/values.yaml.hbs +147 -0
  49. package/templates/azure-aks/iac/runner/Dockerfile +61 -0
  50. package/templates/azure-aks/iac/terraform/bootstrap/main.tf.hbs +123 -0
  51. package/templates/azure-aks/iac/terraform/bootstrap/outputs.tf +24 -0
  52. package/templates/azure-aks/iac/terraform/bootstrap/variables.tf.hbs +23 -0
  53. package/templates/azure-aks/iac/terraform/environments/dev/backend.hcl.hbs +25 -0
  54. package/templates/azure-aks/iac/terraform/environments/dev/terraform.tfvars.hbs +65 -0
  55. package/templates/azure-aks/iac/terraform/main.tf.hbs +307 -0
  56. package/templates/azure-aks/iac/terraform/outputs.tf.hbs +57 -0
  57. package/templates/azure-aks/iac/terraform/providers.tf +35 -0
  58. package/templates/azure-aks/iac/terraform/variables.tf.hbs +157 -0
  59. package/templates/azure-aks/iac/terraform/versions.tf +29 -0
  60. package/templates/base/CLAUDE.md.hbs +7 -7
  61. package/templates/base/docs/docs/dude.md.hbs +1 -1
  62. package/templates/base/docs/docs/index.md.hbs +1 -1
  63. package/templates/base/docs/mkdocs.yml.hbs +1 -1
@@ -0,0 +1,123 @@
1
+ # Bootstrap — creates the project-wide shared resources: the Azure Storage
2
+ # account + blob container that hold Terraform remote state for every
3
+ # environment, and the container registry the app images are pushed to. These
4
+ # are SHARED across all environments (one image, promoted dev → staging → prod by
5
+ # tag), so they have a single owner here rather than being recreated by each
6
+ # per-env config — which would otherwise collide and let one env's `destroy`
7
+ # delete another env's registry. Run ONCE per project, with LOCAL state (this
8
+ # config has no remote backend on purpose).
9
+ #
10
+ # There is no lock table to create: the azurerm backend locks state with a blob
11
+ # lease, which the storage account below provides for free.
12
+ #
13
+ # dude iac bootstrap --state-prefix <your-org> --location northeurope --env dev --yes
14
+
15
+ terraform {
16
+ required_version = ">= 1.6.0"
17
+ required_providers {
18
+ azurerm = {
19
+ source = "hashicorp/azurerm"
20
+ version = "~> 4.14"
21
+ }
22
+ }
23
+ }
24
+
25
+ provider "azurerm" {
26
+ features {
27
+ resource_group {
28
+ # The state container and the registry both live in this group, and
29
+ # `dude iac destroy` only reaches here once no environment still uses
30
+ # them — so refusing to delete a non-empty group would just block the
31
+ # teardown it has already decided is safe.
32
+ prevent_deletion_if_contains_resources = false
33
+ }
34
+ }
35
+
36
+ # Left to ARM_SUBSCRIPTION_ID, which `dude iac` sets from the environment's
37
+ # `subscription_id` (or your `az` default). Pinning it here instead would mean
38
+ # every project hard-codes one subscription into a committed file.
39
+ subscription_id = var.subscription_id != "" ? var.subscription_id : null
40
+ }
41
+
42
+ # Storage account and registry names are globally unique across Azure and accept
43
+ # only lowercase letters and digits — no hyphens, 24 chars max for the storage
44
+ # account. Hence the strip-and-truncate rather than a plain interpolation.
45
+ locals {
46
+ slug = lower(replace("${var.state_prefix}${var.project_name}", "/[^a-zA-Z0-9]/", ""))
47
+ storage_account = substr("${local.slug}tfstate", 0, 24)
48
+ registry_name = substr("${local.slug}acr", 0, 50)
49
+ resource_group = "${var.project_name}-shared-rg"
50
+ }
51
+
52
+ resource "azurerm_resource_group" "shared" {
53
+ name = local.resource_group
54
+ location = var.location
55
+
56
+ tags = {
57
+ Project = var.project_name
58
+ ManagedBy = "terraform"
59
+ Scope = "shared"
60
+ }
61
+ }
62
+
63
+ resource "azurerm_storage_account" "state" {
64
+ name = local.storage_account
65
+ resource_group_name = azurerm_resource_group.shared.name
66
+ location = azurerm_resource_group.shared.location
67
+ account_tier = "Standard"
68
+ account_replication_type = "LRS"
69
+
70
+ # Terraform state records every attribute of every resource — including the
71
+ # generated database password — so it is never reachable anonymously and never
72
+ # over plaintext HTTP.
73
+ https_traffic_only_enabled = true
74
+ min_tls_version = "TLS1_2"
75
+ allow_nested_items_to_be_public = false
76
+ shared_access_key_enabled = true
77
+
78
+ blob_properties {
79
+ # Versioning is what makes a corrupted or truncated state recoverable; 30
80
+ # days of retention is enough to notice and roll back.
81
+ versioning_enabled = true
82
+ delete_retention_policy {
83
+ days = 30
84
+ }
85
+ }
86
+
87
+ tags = {
88
+ Project = var.project_name
89
+ ManagedBy = "terraform"
90
+ Scope = "shared"
91
+ }
92
+ }
93
+
94
+ resource "azurerm_storage_container" "state" {
95
+ name = "tfstate"
96
+ storage_account_id = azurerm_storage_account.state.id
97
+ container_access_type = "private"
98
+ }
99
+
100
+ # Shared container registry — one per project, used by every environment. Per-env
101
+ # Terraform reads it by name via a data source; it is created/destroyed only
102
+ # here, with the rest of the shared bootstrap.
103
+ resource "azurerm_container_registry" "shared" {
104
+ name = local.registry_name
105
+ resource_group_name = azurerm_resource_group.shared.name
106
+ location = azurerm_resource_group.shared.location
107
+
108
+ # Basic is enough for a registry that one project pushes to: the features Standard
109
+ # and Premium add (geo-replication, larger included storage, tag immutability,
110
+ # private endpoints) cost real money and none of them is on this path.
111
+ sku = "Basic"
112
+
113
+ # Image pulls authenticate as the cluster's managed identity (an AcrPull role
114
+ # assignment in the per-env config), so the registry never needs the shared
115
+ # admin username/password that would otherwise end up in a Kubernetes secret.
116
+ admin_enabled = false
117
+
118
+ tags = {
119
+ Project = var.project_name
120
+ ManagedBy = "terraform"
121
+ Scope = "shared"
122
+ }
123
+ }
@@ -0,0 +1,24 @@
1
+ output "resource_group_name" {
2
+ description = "Set this as `resource_group_name` in every environment's backend.hcl."
3
+ value = azurerm_resource_group.shared.name
4
+ }
5
+
6
+ output "storage_account_name" {
7
+ description = "Set this as `storage_account_name` in every environment's backend.hcl."
8
+ value = azurerm_storage_account.state.name
9
+ }
10
+
11
+ output "container_name" {
12
+ description = "Set this as `container_name` in every environment's backend.hcl."
13
+ value = azurerm_storage_container.state.name
14
+ }
15
+
16
+ output "acr_name" {
17
+ description = "Shared container registry name — set as `acr_name` in each environment's terraform.tfvars."
18
+ value = azurerm_container_registry.shared.name
19
+ }
20
+
21
+ output "acr_login_server" {
22
+ description = "Shared container registry login server (the image registry host)."
23
+ value = azurerm_container_registry.shared.login_server
24
+ }
@@ -0,0 +1,23 @@
1
+ variable "project_name" {
2
+ description = "Project slug — used to name the shared resource group."
3
+ type = string
4
+ default = "{{projectName}}"
5
+ }
6
+
7
+ variable "location" {
8
+ description = "Azure region for the shared state storage account + container registry. See the note on `location` in the per-environment variables: some regions are closed to new subscriptions."
9
+ type = string
10
+ default = "northeurope"
11
+ }
12
+
13
+ variable "state_prefix" {
14
+ description = "Prefix making the storage account and registry names globally unique (e.g. your org slug). Lowercase letters/digits only."
15
+ type = string
16
+ default = "changeme"
17
+ }
18
+
19
+ variable "subscription_id" {
20
+ description = "Azure subscription to create the shared resources in. Empty = whatever ARM_SUBSCRIPTION_ID / your az default resolves to."
21
+ type = string
22
+ default = ""
23
+ }
@@ -0,0 +1,25 @@
1
+ # Remote state for the `dev` environment.
2
+ # These resources are created once by `iac/terraform/bootstrap` — run
3
+ # `dude iac bootstrap` and it fills in the three CHANGE-ME values below for you.
4
+ # The same backend works locally and from CI/CD.
5
+ #
6
+ # Each environment uses a distinct `key`, so adding `staging`/`prod` is just a
7
+ # new folder with its own backend.hcl + terraform.tfvars.
8
+ #
9
+ # There is no lock table: the azurerm backend takes a lease on the state blob,
10
+ # which is the lock.
11
+
12
+ resource_group_name = "CHANGE-ME-{{projectName}}-shared-rg"
13
+ storage_account_name = "CHANGE-ME"
14
+ container_name = "tfstate"
15
+ key = "{{projectName}}/dev/terraform.tfstate"
16
+
17
+ # Terraform reaches the state blob with the storage account's access key, which
18
+ # it looks up through ARM using the subscription `dude iac` exports for the
19
+ # environment. That works for anyone with Contributor on the subscription.
20
+ #
21
+ # Setting `use_azuread_auth = true` instead authenticates as the signed-in user,
22
+ # which is tighter — but is NOT a drop-in: being Owner of the subscription grants
23
+ # control-plane rights only, so every person and pipeline would also need the
24
+ # data-plane role "Storage Blob Data Contributor" on the storage account, or
25
+ # `terraform init` fails with AuthorizationPermissionMismatch.
@@ -0,0 +1,65 @@
1
+ # dev environment — small, cost-conscious defaults.
2
+ # Copy this folder to add a new environment (`dude iac new-env --env prod`) and
3
+ # bump the sizing / durability knobs there.
4
+
5
+ environment = "dev"
6
+
7
+ # Several popular regions — West Europe notably — are capacity-closed to NEW
8
+ # subscriptions and reject resource creation with "RequestDisallowedByAzure: the
9
+ # selected region is currently not accepting new customers". North Europe is the
10
+ # default because it is reliably open. Before switching, create something cheap
11
+ # there first, or check https://aka.ms/locationineligible.
12
+ location = "northeurope"
13
+
14
+ # Azure subscription this environment deploys into. Leave empty to use whichever
15
+ # subscription `az account show` reports; pin it here once you know the id, so
16
+ # two environments can never land in the same place by accident.
17
+ # `dude iac login --env dev` prints the id to paste in.
18
+ subscription_id = ""
19
+
20
+ # Shared container registry — filled in by `dude iac bootstrap`.
21
+ acr_name = "CHANGE-ME"
22
+ acr_resource_group = "{{projectName}}-shared-rg"
23
+
24
+ # Public hostname: Azure serves the app at
25
+ # <dns_label>.<location>.cloudapp.azure.com
26
+ # The label is free, needs no domain, but must be unique within the region.
27
+ # Change it if `dude iac apply` reports the name is already taken.
28
+ dns_label = "{{projectName}}-dev"
29
+
30
+ # HTTPS (optional) — leave EMPTY unless a domain you own points at the ingress.
31
+ # Azure's own *.cloudapp.azure.com hostname cannot get a Let's Encrypt
32
+ # certificate (see iac/README.md, "HTTPS / TLS"), so setting this without a real
33
+ # domain only installs cert-manager and fails to issue.
34
+ letsencrypt_email = ""
35
+
36
+ # Network
37
+ vnet_cidr = "10.0.0.0/16"
38
+ aks_subnet_cidr = "10.0.0.0/20"
39
+ {{#if withPostgres}}
40
+ db_subnet_cidr = "10.0.16.0/24"
41
+ {{/if}}
42
+
43
+ # AKS — leave kubernetes_version empty to track whatever Azure defaults to in
44
+ # this region (always a supported version); pin it for reproducible upgrades.
45
+ #
46
+ # Before changing node_vm_size, check the quota for the family you are moving to:
47
+ # az vm list-usage --location northeurope -o table
48
+ # A brand-new subscription typically gets 10 vCPUs for Dsv3 and BS, and *zero*
49
+ # for newer families like DASv5 — an unavailable family fails the apply several
50
+ # minutes in, not at plan time.
51
+ kubernetes_version = ""
52
+ node_vm_size = "Standard_D2s_v3"
53
+ node_count = 2
54
+ node_min_count = 2
55
+ node_max_count = 4
56
+ {{#if withPostgres}}
57
+
58
+ # Azure Database for PostgreSQL (Flexible Server)
59
+ # Burstable (B_) is the cheap dev tier; move to GP_Standard_* for production —
60
+ # zone-redundant HA is not available on Burstable.
61
+ db_sku_name = "B_Standard_B1ms"
62
+ db_storage_mb = 32768
63
+ db_backup_retention_days = 7
64
+ db_high_availability = false
65
+ {{/if}}
@@ -0,0 +1,307 @@
1
+ locals {
2
+ name = "${var.project_name}-${var.environment}"
3
+
4
+ # Azure publishes the app at <dns_label>.<location>.cloudapp.azure.com. The
5
+ # label is free and needs no domain registration, but it must be unique within
6
+ # the region — override `dns_label` in terraform.tfvars if `apply` reports the
7
+ # name is taken.
8
+ dns_label = var.dns_label != "" ? var.dns_label : local.name
9
+ app_host = "${local.dns_label}.${var.location}.cloudapp.azure.com"
10
+
11
+ tags = {
12
+ Project = var.project_name
13
+ Environment = var.environment
14
+ ManagedBy = "terraform"
15
+ }
16
+ }
17
+
18
+ resource "azurerm_resource_group" "this" {
19
+ name = "${local.name}-rg"
20
+ location = var.location
21
+ tags = local.tags
22
+ }
23
+
24
+ # ── Network ───────────────────────────────────────────────────────────────────
25
+ resource "azurerm_virtual_network" "this" {
26
+ name = "${local.name}-vnet"
27
+ resource_group_name = azurerm_resource_group.this.name
28
+ location = azurerm_resource_group.this.location
29
+ address_space = [var.vnet_cidr]
30
+ tags = local.tags
31
+ }
32
+
33
+ resource "azurerm_subnet" "aks" {
34
+ name = "${local.name}-aks-snet"
35
+ resource_group_name = azurerm_resource_group.this.name
36
+ virtual_network_name = azurerm_virtual_network.this.name
37
+ address_prefixes = [var.aks_subnet_cidr]
38
+ }
39
+ {{#if withPostgres}}
40
+
41
+ # Flexible Server with VNet integration requires a subnet delegated exclusively
42
+ # to it — the database gets a private address inside the VNet and is never
43
+ # exposed to the internet.
44
+ resource "azurerm_subnet" "db" {
45
+ name = "${local.name}-db-snet"
46
+ resource_group_name = azurerm_resource_group.this.name
47
+ virtual_network_name = azurerm_virtual_network.this.name
48
+ address_prefixes = [var.db_subnet_cidr]
49
+
50
+ service_endpoints = ["Microsoft.Storage"]
51
+
52
+ delegation {
53
+ name = "postgres"
54
+ service_delegation {
55
+ name = "Microsoft.DBforPostgreSQL/flexibleServers"
56
+ actions = [
57
+ "Microsoft.Network/virtualNetworks/subnets/join/action",
58
+ ]
59
+ }
60
+ }
61
+ }
62
+ {{/if}}
63
+
64
+ # ── AKS cluster ───────────────────────────────────────────────────────────────
65
+ resource "azurerm_kubernetes_cluster" "this" {
66
+ name = local.name
67
+ resource_group_name = azurerm_resource_group.this.name
68
+ location = azurerm_resource_group.this.location
69
+ dns_prefix = local.name
70
+
71
+ # Empty string would be rejected, so null (= "let Azure pick") is the way to
72
+ # express "no opinion"; pin `kubernetes_version` in tfvars for a reproducible
73
+ # control-plane version.
74
+ kubernetes_version = var.kubernetes_version != "" ? var.kubernetes_version : null
75
+
76
+ # Free tier: a best-effort control-plane SLA, which is what a dev/PoC cluster
77
+ # wants. Set this to "Standard" in a production environment's tfvars.
78
+ sku_tier = "Free"
79
+
80
+ default_node_pool {
81
+ name = "system"
82
+ vm_size = var.node_vm_size
83
+ node_count = var.node_count
84
+ auto_scaling_enabled = true
85
+ min_count = var.node_min_count
86
+ max_count = var.node_max_count
87
+ vnet_subnet_id = azurerm_subnet.aks.id
88
+ orchestrator_version = var.kubernetes_version != "" ? var.kubernetes_version : null
89
+
90
+ upgrade_settings {
91
+ max_surge = "10%"
92
+ }
93
+ }
94
+
95
+ identity {
96
+ type = "SystemAssigned"
97
+ }
98
+
99
+ # Overlay mode keeps pod IPs out of the VNet address space, so the subnet only
100
+ # has to be large enough for nodes — the usual way an Azure CNI cluster runs out
101
+ # of addresses and stops scheduling.
102
+ network_profile {
103
+ network_plugin = "azure"
104
+ network_plugin_mode = "overlay"
105
+ network_policy = "calico"
106
+ load_balancer_sku = "standard"
107
+ outbound_type = "loadBalancer"
108
+ }
109
+
110
+ # `node_count` is the INITIAL size only: the autoscaler owns it afterwards, and
111
+ # without this every plan would try to reset a scaled-out cluster.
112
+ lifecycle {
113
+ ignore_changes = [default_node_pool[0].node_count]
114
+ }
115
+
116
+ tags = local.tags
117
+ }
118
+
119
+ # ── Container registry access ─────────────────────────────────────────────────
120
+ # The registry is shared across environments and owned by the bootstrap config
121
+ # (one image, promoted dev → staging → prod by tag), so it is read here, never
122
+ # created. Granting AcrPull to the cluster's kubelet identity is what lets pods
123
+ # pull without an imagePullSecret.
124
+ data "azurerm_container_registry" "shared" {
125
+ name = var.acr_name
126
+ resource_group_name = var.acr_resource_group
127
+ }
128
+
129
+ resource "azurerm_role_assignment" "acr_pull" {
130
+ scope = data.azurerm_container_registry.shared.id
131
+ role_definition_name = "AcrPull"
132
+ principal_id = azurerm_kubernetes_cluster.this.kubelet_identity[0].object_id
133
+ skip_service_principal_aad_check = true
134
+ }
135
+
136
+ # ── Ingress controller + the public hostname ──────────────────────────────────
137
+ # ingress-nginx's Service asks the Azure cloud-controller for a public IP and —
138
+ # via the annotation below — for a DNS label on it. That is what makes the app
139
+ # reachable at a real hostname without owning a domain or touching DNS: Azure
140
+ # serves <dns_label>.<location>.cloudapp.azure.com for free.
141
+ #
142
+ # The IP itself is deliberately NOT a Terraform resource. A pre-created IP has to
143
+ # live in a resource group the cluster identity can write to, which costs an
144
+ # extra role assignment and an annotation that has to agree with it; letting the
145
+ # controller create the IP in the node resource group avoids all of that, and the
146
+ # IP is released automatically when the cluster goes away.
147
+ resource "helm_release" "ingress_nginx" {
148
+ name = "ingress-nginx"
149
+ repository = "https://kubernetes.github.io/ingress-nginx"
150
+ chart = "ingress-nginx"
151
+ namespace = "ingress-nginx"
152
+ create_namespace = true
153
+ version = var.ingress_nginx_chart_version
154
+
155
+ # The load balancer, its public IP and the DNS label take a minute or two to
156
+ # settle; without waiting, `apply` finishes before the hostname resolves and
157
+ # the first deploy looks broken.
158
+ wait = true
159
+ timeout = 900
160
+
161
+ set {
162
+ name = "controller.service.annotations.service\\.beta\\.kubernetes\\.io/azure-dns-label-name"
163
+ value = local.dns_label
164
+ }
165
+ set {
166
+ name = "controller.service.externalTrafficPolicy"
167
+ value = "Local"
168
+ }
169
+ set {
170
+ name = "controller.replicaCount"
171
+ value = "2"
172
+ }
173
+
174
+ depends_on = [azurerm_kubernetes_cluster.this]
175
+ }
176
+
177
+ # ── TLS (optional — enabled when var.letsencrypt_email is set) ────────────────
178
+ # cert-manager + a Let's Encrypt ClusterIssuer, for when a domain you own points
179
+ # at the ingress. It is off by default because Azure's own *.cloudapp.azure.com
180
+ # hostname cannot get a trusted certificate: that suffix is not on the Public
181
+ # Suffix List, so Let's Encrypt attributes every certificate to `azure.com` and
182
+ # the shared rate limit refuses yours. See iac/README.md, "HTTPS / TLS".
183
+ resource "helm_release" "cert_manager" {
184
+ count = var.letsencrypt_email == "" ? 0 : 1
185
+ name = "cert-manager"
186
+ repository = "https://charts.jetstack.io"
187
+ chart = "cert-manager"
188
+ namespace = "cert-manager"
189
+ create_namespace = true
190
+ version = var.cert_manager_chart_version
191
+
192
+ set {
193
+ name = "crds.enabled"
194
+ value = "true"
195
+ }
196
+
197
+ depends_on = [azurerm_kubernetes_cluster.this]
198
+ }
199
+
200
+ resource "kubernetes_manifest" "letsencrypt_issuer" {
201
+ count = var.letsencrypt_email == "" ? 0 : 1
202
+
203
+ manifest = {
204
+ apiVersion = "cert-manager.io/v1"
205
+ kind = "ClusterIssuer"
206
+ metadata = {
207
+ name = "letsencrypt-prod"
208
+ }
209
+ spec = {
210
+ acme = {
211
+ server = "https://acme-v02.api.letsencrypt.org/directory"
212
+ email = var.letsencrypt_email
213
+ privateKeySecretRef = {
214
+ name = "letsencrypt-prod-account-key"
215
+ }
216
+ solvers = [
217
+ {
218
+ http01 = {
219
+ ingress = {
220
+ ingressClassName = "nginx"
221
+ }
222
+ }
223
+ },
224
+ ]
225
+ }
226
+ }
227
+ }
228
+
229
+ depends_on = [helm_release.cert_manager, helm_release.ingress_nginx]
230
+ }
231
+ {{#if withPostgres}}
232
+
233
+ # ── Azure Database for PostgreSQL (Flexible Server) ───────────────────────────
234
+ # The admin password is generated here and surfaced through the `database_url`
235
+ # output (sensitive) — there is no Azure Key Vault in this path. `special = false`
236
+ # keeps it URL- and `helm --set`-safe (no characters that need escaping).
237
+ resource "random_password" "db" {
238
+ length = 32
239
+ special = false
240
+ }
241
+
242
+ # The server has no public endpoint: it is reachable only from inside the VNet,
243
+ # which is resolved through this private zone linked to it.
244
+ resource "azurerm_private_dns_zone" "postgres" {
245
+ name = "${local.name}.postgres.database.azure.com"
246
+ resource_group_name = azurerm_resource_group.this.name
247
+ tags = local.tags
248
+ }
249
+
250
+ resource "azurerm_private_dns_zone_virtual_network_link" "postgres" {
251
+ name = "${local.name}-pg-link"
252
+ resource_group_name = azurerm_resource_group.this.name
253
+ private_dns_zone_name = azurerm_private_dns_zone.postgres.name
254
+ virtual_network_id = azurerm_virtual_network.this.id
255
+ registration_enabled = false
256
+ tags = local.tags
257
+ }
258
+
259
+ resource "azurerm_postgresql_flexible_server" "this" {
260
+ name = "${local.name}-pg"
261
+ resource_group_name = azurerm_resource_group.this.name
262
+ location = azurerm_resource_group.this.location
263
+
264
+ version = var.db_version
265
+ sku_name = var.db_sku_name
266
+ storage_mb = var.db_storage_mb
267
+
268
+ administrator_login = var.db_username
269
+ administrator_password = random_password.db.result
270
+
271
+ backup_retention_days = var.db_backup_retention_days
272
+
273
+ delegated_subnet_id = azurerm_subnet.db.id
274
+ private_dns_zone_id = azurerm_private_dns_zone.postgres.id
275
+ public_network_access_enabled = false
276
+
277
+ dynamic "high_availability" {
278
+ for_each = var.db_high_availability ? [1] : []
279
+ content {
280
+ mode = "ZoneRedundant"
281
+ }
282
+ }
283
+
284
+ # `zone` is assigned by Azure when it isn't pinned, and it then shows up as a
285
+ # diff on every subsequent plan.
286
+ lifecycle {
287
+ ignore_changes = [zone]
288
+ }
289
+
290
+ tags = local.tags
291
+
292
+ depends_on = [azurerm_private_dns_zone_virtual_network_link.postgres]
293
+ }
294
+
295
+ resource "azurerm_postgresql_flexible_server_database" "app" {
296
+ name = var.db_name
297
+ server_id = azurerm_postgresql_flexible_server.this.id
298
+ collation = "en_US.utf8"
299
+ charset = "utf8"
300
+
301
+ # Dropping the database would take the application's data with it; Terraform
302
+ # removing the *server* is the deliberate, `dude iac destroy` path.
303
+ lifecycle {
304
+ prevent_destroy = false
305
+ }
306
+ }
307
+ {{/if}}
@@ -0,0 +1,57 @@
1
+ output "location" {
2
+ description = "Azure region the environment runs in."
3
+ value = var.location
4
+ }
5
+
6
+ output "resource_group_name" {
7
+ description = "Resource group holding this environment (use with `az aks get-credentials`)."
8
+ value = azurerm_resource_group.this.name
9
+ }
10
+
11
+ output "cluster_name" {
12
+ description = "AKS cluster name (use with `az aks get-credentials`)."
13
+ value = azurerm_kubernetes_cluster.this.name
14
+ }
15
+
16
+ output "acr_login_server" {
17
+ description = "Shared container registry host (owned by the bootstrap config)."
18
+ value = data.azurerm_container_registry.shared.login_server
19
+ }
20
+
21
+ output "acr_backend_repository_url" {
22
+ description = "Registry repository for the backend image."
23
+ value = "${data.azurerm_container_registry.shared.login_server}/${var.project_name}-backend"
24
+ }
25
+
26
+ output "acr_frontend_repository_url" {
27
+ description = "Registry repository for the frontend image."
28
+ value = "${data.azurerm_container_registry.shared.login_server}/${var.project_name}-frontend"
29
+ }
30
+
31
+ output "app_host" {
32
+ description = "Public hostname Azure serves the app on. `dude iac deploy` wires this into the Ingress automatically."
33
+ value = local.app_host
34
+ }
35
+
36
+ output "app_url" {
37
+ description = "Public URL of the application."
38
+ value = "${var.letsencrypt_email == "" ? "http" : "https"}://${local.app_host}/"
39
+ }
40
+ {{#if withPostgres}}
41
+
42
+ output "postgres_fqdn" {
43
+ description = "Private FQDN of the PostgreSQL Flexible Server (reachable from inside the VNet only)."
44
+ value = azurerm_postgresql_flexible_server.this.fqdn
45
+ }
46
+
47
+ output "database_name" {
48
+ description = "Initial database name."
49
+ value = var.db_name
50
+ }
51
+
52
+ output "database_url" {
53
+ description = "Full PostgreSQL connection string for the app. `dude iac ship`/`deploy` wires this into the Helm release automatically."
54
+ value = "postgresql://${var.db_username}:${random_password.db.result}@${azurerm_postgresql_flexible_server.this.fqdn}:5432/${var.db_name}?sslmode=require"
55
+ sensitive = true
56
+ }
57
+ {{/if}}
@@ -0,0 +1,35 @@
1
+ provider "azurerm" {
2
+ features {
3
+ resource_group {
4
+ # `dude iac destroy` tears an environment down as a whole, and AKS adds
5
+ # resources to the group that Terraform does not track. Without this, the
6
+ # destroy fails on "resource group is not empty" for resources Terraform
7
+ # itself cannot name.
8
+ prevent_deletion_if_contains_resources = false
9
+ }
10
+ }
11
+
12
+ # Empty = fall back to ARM_SUBSCRIPTION_ID, which `dude iac` exports from the
13
+ # environment's resolved subscription. Set `subscription_id` in the env's
14
+ # terraform.tfvars to pin it instead.
15
+ subscription_id = var.subscription_id != "" ? var.subscription_id : null
16
+ }
17
+
18
+ # Authenticate the kubernetes/helm providers against the cluster created in this
19
+ # same configuration, using the admin-free user credentials AKS returns. No
20
+ # kubeconfig file is required, so the flow is identical locally and in CI.
21
+ provider "kubernetes" {
22
+ host = azurerm_kubernetes_cluster.this.kube_config.0.host
23
+ client_certificate = base64decode(azurerm_kubernetes_cluster.this.kube_config.0.client_certificate)
24
+ client_key = base64decode(azurerm_kubernetes_cluster.this.kube_config.0.client_key)
25
+ cluster_ca_certificate = base64decode(azurerm_kubernetes_cluster.this.kube_config.0.cluster_ca_certificate)
26
+ }
27
+
28
+ provider "helm" {
29
+ kubernetes {
30
+ host = azurerm_kubernetes_cluster.this.kube_config.0.host
31
+ client_certificate = base64decode(azurerm_kubernetes_cluster.this.kube_config.0.client_certificate)
32
+ client_key = base64decode(azurerm_kubernetes_cluster.this.kube_config.0.client_key)
33
+ cluster_ca_certificate = base64decode(azurerm_kubernetes_cluster.this.kube_config.0.cluster_ca_certificate)
34
+ }
35
+ }