Skip to content

Commit 3c1bb3d

Browse files
authored
Merge pull request #4 from data-platform-hq/fix/fix-usage-with-user-identity
fix: update code for usage of user assigned identity
2 parents 4d0e073 + 452f24c commit 3c1bb3d

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@ No modules.
3232
| Name | Description | Type | Default | Required |
3333
|------|-------------|------|---------|:--------:|
3434
| <a name="input_container_instance_name"></a> [container\_instance\_name](#input\_container\_instance\_name) | Specifies the name of the Container Group. | `string` | n/a | yes |
35-
| <a name="input_containers"></a> [containers](#input\_containers) | List of objects to configure containers | <pre>list(object({<br> name = string<br> image = string<br> cpu = number<br> memory = number<br> environment_variables = optional(map(string))<br> commands = optional(list(string))<br> ports_tcp = optional(set(string), [])<br> ports_udp = optional(set(string), [])<br> volumes = optional(list(object({<br> mount_path = string<br> name = string<br> storage_account_name = optional(string)<br> storage_account_key = optional(string)<br> share_name = optional(string)<br> })), [])<br> }))</pre> | n/a | yes |
35+
| <a name="input_containers"></a> [containers](#input\_containers) | List of objects to configure containers | <pre>list(object({<br/> name = string<br/> image = string<br/> cpu = number<br/> memory = number<br/> environment_variables = optional(map(string))<br/> commands = optional(list(string))<br/> ports_tcp = optional(set(string), [])<br/> ports_udp = optional(set(string), [])<br/> volumes = optional(list(object({<br/> mount_path = string<br/> name = string<br/> storage_account_name = optional(string)<br/> storage_account_key = optional(string)<br/> share_name = optional(string)<br/> })), [])<br/> }))</pre> | n/a | yes |
3636
| <a name="input_dns_config_nameservers"></a> [dns\_config\_nameservers](#input\_dns\_config\_nameservers) | A list of nameservers the containers will search out to resolve requests. | `list(string)` | `[]` | no |
37+
| <a name="input_enable_system_assigned_identity"></a> [enable\_system\_assigned\_identity](#input\_enable\_system\_assigned\_identity) | Specifies whether to enable System Assigned identity for container instance or not | `bool` | `false` | no |
3738
| <a name="input_exposed_ports_tcp"></a> [exposed\_ports\_tcp](#input\_exposed\_ports\_tcp) | Set of ports to expose with TCP protocol | `set(string)` | `[]` | no |
3839
| <a name="input_exposed_ports_udp"></a> [exposed\_ports\_udp](#input\_exposed\_ports\_udp) | Set of ports to expose with UDP protocol | `set(string)` | `[]` | no |
3940
| <a name="input_identity_ids"></a> [identity\_ids](#input\_identity\_ids) | Specifies a list of User Assigned Managed Identity IDs to be assigned to this Container Group. | `list(string)` | `null` | no |
40-
| <a name="input_image_registry_credential"></a> [image\_registry\_credential](#input\_image\_registry\_credential) | List of objects to configure connection to private registry | <pre>list(object({<br> server = string<br> username = string<br> password = string<br> }))</pre> | `[]` | no |
41+
| <a name="input_image_registry_credential"></a> [image\_registry\_credential](#input\_image\_registry\_credential) | List of objects to configure connection to private registry | <pre>list(object({<br/> server = string<br/> username = optional(string)<br/> password = optional(string)<br/> user_assigned_identity_id = optional(string)<br/> }))</pre> | `[]` | no |
4142
| <a name="input_ip_address_type"></a> [ip\_address\_type](#input\_ip\_address\_type) | Specifies the IP address type of the container. Public, Private or None. | `string` | `"Public"` | no |
4243
| <a name="input_location"></a> [location](#input\_location) | Specifies the supported Azure location where the resource exists. | `string` | n/a | yes |
4344
| <a name="input_os_type"></a> [os\_type](#input\_os\_type) | The OS for the container group. Allowed values are Linux and Windows. | `string` | `"Linux"` | no |

main.tf

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,25 @@ resource "azurerm_container_group" "this" {
99
subnet_ids = var.subnet_ids
1010
tags = var.tags
1111

12-
identity {
13-
type = var.identity_ids == null ? "SystemAssigned" : "SystemAssigned, UserAssigned"
14-
identity_ids = var.identity_ids
12+
dynamic "identity" {
13+
for_each = (var.enable_system_assigned_identity || var.identity_ids != null) ? [1] : []
14+
15+
content {
16+
type = join(", ", compact([
17+
var.enable_system_assigned_identity ? "SystemAssigned" : "",
18+
var.identity_ids != null ? "UserAssigned" : ""
19+
]))
20+
identity_ids = var.identity_ids
21+
}
1522
}
1623

1724
dynamic "image_registry_credential" {
1825
for_each = var.image_registry_credential
1926
content {
20-
server = image_registry_credential.value.server
21-
username = image_registry_credential.value.username
22-
password = image_registry_credential.value.password
27+
server = image_registry_credential.value.server
28+
username = image_registry_credential.value.username
29+
password = image_registry_credential.value.password
30+
user_assigned_identity_id = image_registry_credential.value.user_assigned_identity_id
2331
}
2432
}
2533

variables.tf

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ variable "restart_policy" {
3737
default = "Never"
3838
}
3939

40+
variable "enable_system_assigned_identity" {
41+
type = bool
42+
description = "Specifies whether to enable System Assigned identity for container instance or not"
43+
default = false
44+
}
45+
4046
variable "identity_ids" {
4147
type = list(string)
4248
description = "Specifies a list of User Assigned Managed Identity IDs to be assigned to this Container Group."
@@ -69,9 +75,10 @@ variable "exposed_ports_udp" {
6975

7076
variable "image_registry_credential" {
7177
type = list(object({
72-
server = string
73-
username = string
74-
password = string
78+
server = string
79+
username = optional(string)
80+
password = optional(string)
81+
user_assigned_identity_id = optional(string)
7582
}))
7683
description = "List of objects to configure connection to private registry"
7784
default = []

0 commit comments

Comments
 (0)