Skip to content

Commit a0cb197

Browse files
authored
Merge pull request #2 from kewalaka/feat/single-instance-avm-alignment
make container apps a single instance resource + add Dapr example
2 parents 693b74a + 30ccf54 commit a0cb197

File tree

11 files changed

+184
-145
lines changed

11 files changed

+184
-145
lines changed

README.md

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ The following providers are used by this module:
4949
The following resources are used by this module:
5050

5151
- [azapi_resource.container_app](https://registry.terraform.io/providers/Azure/azapi/1.9.0/docs/resources/resource) (resource)
52+
- [azurerm_management_lock.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/management_lock) (resource)
5253
- [azurerm_resource_group_template_deployment.telemetry](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group_template_deployment) (resource)
54+
- [azurerm_role_assignment.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/role_assignment) (resource)
5355
- [random_id.telem](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/id) (resource)
5456
- [azurerm_resource_group.rg](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/resource_group) (data source)
5557

@@ -58,20 +60,14 @@ The following resources are used by this module:
5860

5961
The following input variables are required:
6062

61-
### <a name="input_container_app_environment_resource_id"></a> [container\_app\_environment\_resource\_id](#input\_container\_app\_environment\_resource\_id)
62-
63-
Description: Resource ID of environment.
64-
65-
Type: `string`
66-
67-
### <a name="input_container_apps"></a> [container\_apps](#input\_container\_apps)
63+
### <a name="input_container_app"></a> [container\_app](#input\_container\_app)
6864

6965
Description: Specifies the container apps in the managed environment.
7066

7167
Type:
7268

7369
```hcl
74-
list(object({
70+
object({
7571
name = string
7672
revision_mode = optional(string, "Single")
7773
@@ -255,9 +251,15 @@ list(object({
255251
storageType = string
256252
})))
257253
})
258-
}))
254+
})
259255
```
260256

257+
### <a name="input_container_app_environment_resource_id"></a> [container\_app\_environment\_resource\_id](#input\_container\_app\_environment\_resource\_id)
258+
259+
Description: Resource ID of environment.
260+
261+
Type: `string`
262+
261263
### <a name="input_name"></a> [name](#input\_name)
262264

263265
Description: Name for the resource.
@@ -292,6 +294,42 @@ Type: `string`
292294

293295
Default: `null`
294296

297+
### <a name="input_lock"></a> [lock](#input\_lock)
298+
299+
Description: The lock level to apply to the Container App. Default is `None`. Possible values are `None`, `CanNotDelete`, and `ReadOnly`.
300+
301+
Type:
302+
303+
```hcl
304+
object({
305+
name = optional(string, null)
306+
kind = optional(string, "None")
307+
308+
})
309+
```
310+
311+
Default: `{}`
312+
313+
### <a name="input_role_assignments"></a> [role\_assignments](#input\_role\_assignments)
314+
315+
Description: required AVM interfaces
316+
317+
Type:
318+
319+
```hcl
320+
map(object({
321+
role_definition_id_or_name = string
322+
principal_id = string
323+
description = optional(string, null)
324+
skip_service_principal_aad_check = optional(bool, true)
325+
condition = optional(string, null)
326+
condition_version = optional(string, "2.0")
327+
delegated_managed_identity_resource_id = optional(string)
328+
}))
329+
```
330+
331+
Default: `{}`
332+
295333
### <a name="input_tags"></a> [tags](#input\_tags)
296334

297335
Description: Custom tags to apply to the resource.

examples-not-working/dapr/README.md renamed to examples/dapr/README.md

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ resource "azapi_resource" "managed_environment" {
6161
}
6262
6363
# This is the module call
64-
module "container-app" {
64+
module "node-app" {
6565
source = "../../"
6666
# source = "Azure/avm-<res/ptn>-<name>/azurerm"
67-
name = replace(azurerm_resource_group.this.name, "rg-", "ca-") # TODO remove workaround pending PR - https://github.com/Azure/terraform-azurerm-naming/pull/103
67+
name = replace(azurerm_resource_group.this.name, "rg-", "ca-nodeapp-") # TODO remove workaround pending PR - https://github.com/Azure/terraform-azurerm-naming/pull/103
6868
resource_group_name = azurerm_resource_group.this.name
6969
container_app_environment_resource_id = azapi_resource.managed_environment.id
7070
7171
workload_profile_name = ""
72-
container_apps = [{
72+
container_app = {
7373
name = "nodeapp"
7474
configuration = {
7575
ingress = {
@@ -101,30 +101,40 @@ module "container-app" {
101101
maxReplicas = 1
102102
}
103103
}
104-
},
105-
{
106-
name = "pythonapp"
107-
configuration = {
108-
dapr = {
109-
enabled = true
110-
appId = "pythonapp"
111-
}
104+
}
105+
}
106+
107+
module "python-app" {
108+
source = "../../"
109+
# source = "Azure/avm-<res/ptn>-<name>/azurerm"
110+
name = replace(azurerm_resource_group.this.name, "rg-", "ca-pythonapp-") # TODO remove workaround pending PR - https://github.com/Azure/terraform-azurerm-naming/pull/103
111+
resource_group_name = azurerm_resource_group.this.name
112+
container_app_environment_resource_id = azapi_resource.managed_environment.id
113+
114+
workload_profile_name = ""
115+
container_app = {
116+
name = "pythonapp"
117+
configuration = {
118+
dapr = {
119+
enabled = true
120+
appId = "pythonapp"
112121
}
113-
template = {
114-
containers = [{
115-
image = "dapriosamples/hello-k8s-python:latest"
116-
name = "hello-k8s-python"
117-
resources = {
118-
cpu = 0.5
119-
memory = "1.0Gi"
120-
}
121-
}]
122-
scale = {
123-
minReplicas = 1
124-
maxReplicas = 1
122+
}
123+
template = {
124+
containers = [{
125+
image = "dapriosamples/hello-k8s-python:latest"
126+
name = "hello-k8s-python"
127+
resources = {
128+
cpu = 0.5
129+
memory = "1.0Gi"
125130
}
131+
}]
132+
scale = {
133+
minReplicas = 1
134+
maxReplicas = 1
126135
}
127-
}]
136+
}
137+
}
128138
}
129139
```
130140

@@ -181,17 +191,23 @@ No outputs.
181191

182192
The following Modules are called:
183193

184-
### <a name="module_container-app"></a> [container-app](#module\_container-app)
194+
### <a name="module_naming"></a> [naming](#module\_naming)
195+
196+
Source: Azure/naming/azurerm
197+
198+
Version: 0.3.0
199+
200+
### <a name="module_node-app"></a> [node-app](#module\_node-app)
185201

186202
Source: ../../
187203

188204
Version:
189205

190-
### <a name="module_naming"></a> [naming](#module\_naming)
206+
### <a name="module_python-app"></a> [python-app](#module\_python-app)
191207

192-
Source: Azure/naming/azurerm
208+
Source: ../../
193209

194-
Version: 0.3.0
210+
Version:
195211

196212
<!-- markdownlint-disable-next-line MD041 -->
197213
## Data Collection
File renamed without changes.
File renamed without changes.

examples-not-working/dapr/main.tf renamed to examples/dapr/main.tf

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ resource "azapi_resource" "managed_environment" {
5555
}
5656

5757
# This is the module call
58-
module "container-app" {
58+
module "node-app" {
5959
source = "../../"
6060
# source = "Azure/avm-<res/ptn>-<name>/azurerm"
61-
name = replace(azurerm_resource_group.this.name, "rg-", "ca-") # TODO remove workaround pending PR - https://github.com/Azure/terraform-azurerm-naming/pull/103
61+
name = replace(azurerm_resource_group.this.name, "rg-", "ca-nodeapp-") # TODO remove workaround pending PR - https://github.com/Azure/terraform-azurerm-naming/pull/103
6262
resource_group_name = azurerm_resource_group.this.name
6363
container_app_environment_resource_id = azapi_resource.managed_environment.id
6464

6565
workload_profile_name = ""
66-
container_apps = [{
66+
container_app = {
6767
name = "nodeapp"
6868
configuration = {
6969
ingress = {
@@ -95,28 +95,38 @@ module "container-app" {
9595
maxReplicas = 1
9696
}
9797
}
98-
},
99-
{
100-
name = "pythonapp"
101-
configuration = {
102-
dapr = {
103-
enabled = true
104-
appId = "pythonapp"
105-
}
98+
}
99+
}
100+
101+
module "python-app" {
102+
source = "../../"
103+
# source = "Azure/avm-<res/ptn>-<name>/azurerm"
104+
name = replace(azurerm_resource_group.this.name, "rg-", "ca-pythonapp-") # TODO remove workaround pending PR - https://github.com/Azure/terraform-azurerm-naming/pull/103
105+
resource_group_name = azurerm_resource_group.this.name
106+
container_app_environment_resource_id = azapi_resource.managed_environment.id
107+
108+
workload_profile_name = ""
109+
container_app = {
110+
name = "pythonapp"
111+
configuration = {
112+
dapr = {
113+
enabled = true
114+
appId = "pythonapp"
106115
}
107-
template = {
108-
containers = [{
109-
image = "dapriosamples/hello-k8s-python:latest"
110-
name = "hello-k8s-python"
111-
resources = {
112-
cpu = 0.5
113-
memory = "1.0Gi"
114-
}
115-
}]
116-
scale = {
117-
minReplicas = 1
118-
maxReplicas = 1
116+
}
117+
template = {
118+
containers = [{
119+
image = "dapriosamples/hello-k8s-python:latest"
120+
name = "hello-k8s-python"
121+
resources = {
122+
cpu = 0.5
123+
memory = "1.0Gi"
119124
}
125+
}]
126+
scale = {
127+
minReplicas = 1
128+
maxReplicas = 1
120129
}
121-
}]
130+
}
131+
}
122132
}

examples/default/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ module "container_app" {
5656
container_app_environment_resource_id = azurerm_container_app_environment.this.id
5757
5858
workload_profile_name = "Consumption"
59-
container_apps = [{
59+
container_app = {
6060
name = "helloworld"
6161
configuration = {
6262
ingress = {
@@ -77,8 +77,7 @@ module "container_app" {
7777
maxReplicas = 1
7878
}
7979
}
80-
}
81-
]
80+
}
8281
}
8382
```
8483

examples/default/main.tf

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ module "container_app" {
5050
container_app_environment_resource_id = azurerm_container_app_environment.this.id
5151

5252
workload_profile_name = "Consumption"
53-
container_apps = [{
53+
container_app = {
5454
name = "helloworld"
5555
configuration = {
5656
ingress = {
@@ -71,6 +71,5 @@ module "container_app" {
7171
maxReplicas = 1
7272
}
7373
}
74-
}
75-
]
74+
}
7675
}

locals.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
locals {
2-
location = var.location != null ? var.location : data.azurerm_resource_group.rg.location
2+
location = var.location != null ? var.location : data.azurerm_resource_group.rg.location
3+
role_definition_resource_substring = "/providers/Microsoft.Authorization/roleDefinitions"
34
}

main.tf

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ data "azurerm_resource_group" "rg" {
33
}
44

55
resource "azapi_resource" "container_app" {
6-
for_each = { for app in var.container_apps : app.name => app }
76
type = "Microsoft.App/containerApps@2023-05-01"
87
schema_validation_enabled = false
98
name = var.name
@@ -18,38 +17,38 @@ resource "azapi_resource" "container_app" {
1817
body = jsonencode({
1918
properties = {
2019
configuration = {
21-
activeRevisionsMode = try(each.value.revision_mode, "Single")
22-
dapr = try(each.value.dapr, null)
23-
ingress = try(each.value.ingress, null)
24-
maxInactiveRevisions = try(each.value.maxInactiveRevisions, null)
25-
registries = try(each.value.registries, null)
26-
secrets = try(each.value.secrets, null)
27-
service = try(each.value.service, null)
20+
activeRevisionsMode = try(var.container_app.revision_mode, "Single")
21+
dapr = try(var.container_app.dapr, null)
22+
ingress = try(var.container_app.ingress, null)
23+
maxInactiveRevisions = try(var.container_app.maxInactiveRevisions, null)
24+
registries = try(var.container_app.registries, null)
25+
secrets = try(var.container_app.secrets, null)
26+
service = try(var.container_app.service, null)
2827
}
2928
environmentId = var.container_app_environment_resource_id
30-
template = each.value.template
29+
template = var.container_app.template
3130
workloadProfileName = var.workload_profile_name
3231
}
3332
})
3433

3534
response_export_values = ["identity"]
3635
}
3736

38-
# resource "azurerm_management_lock" "this" {
39-
# count = var.lock.kind != "None" ? 1 : 0
40-
# name = coalesce(var.lock.name, "lock-${var.name}")
41-
# scope = azapi_resource.container_app.id
42-
# lock_level = var.lock.kind
43-
# }
37+
resource "azurerm_management_lock" "this" {
38+
count = var.lock.kind != "None" ? 1 : 0
39+
name = coalesce(var.lock.name, "lock-${var.name}")
40+
scope = azapi_resource.container_app.id
41+
lock_level = var.lock.kind
42+
}
4443

45-
# resource "azurerm_role_assignment" "this" {
46-
# for_each = var.role_assignments
47-
# scope = azapi_resource.container_app.id
48-
# role_definition_id = strcontains(lower(each.value.role_definition_id_or_name), lower(local.role_definition_resource_substring)) ? each.value.role_definition_id_or_name : null
49-
# role_definition_name = strcontains(lower(each.value.role_definition_id_or_name), lower(local.role_definition_resource_substring)) ? null : each.value.role_definition_id_or_name
50-
# principal_id = each.value.principal_id
51-
# condition = each.value.condition
52-
# condition_version = each.value.condition_version
53-
# skip_service_principal_aad_check = each.value.skip_service_principal_aad_check
54-
# delegated_managed_identity_resource_id = each.value.delegated_managed_identity_resource_id
55-
# }
44+
resource "azurerm_role_assignment" "this" {
45+
for_each = var.role_assignments
46+
scope = azapi_resource.container_app.id
47+
role_definition_id = strcontains(lower(each.value.role_definition_id_or_name), lower(local.role_definition_resource_substring)) ? each.value.role_definition_id_or_name : null
48+
role_definition_name = strcontains(lower(each.value.role_definition_id_or_name), lower(local.role_definition_resource_substring)) ? null : each.value.role_definition_id_or_name
49+
principal_id = each.value.principal_id
50+
condition = each.value.condition
51+
condition_version = each.value.condition_version
52+
skip_service_principal_aad_check = each.value.skip_service_principal_aad_check
53+
delegated_managed_identity_resource_id = each.value.delegated_managed_identity_resource_id
54+
}

0 commit comments

Comments
 (0)