Skip to content

Commit 96ae911

Browse files
author
Artem Vovchenko
committed
Improve managed identity logic
1 parent 8fb986b commit 96ae911

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

main.tf

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,16 @@ 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" {

variables.tf

Lines changed: 9 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."
@@ -70,9 +76,9 @@ variable "exposed_ports_udp" {
7076
variable "image_registry_credential" {
7177
type = list(object({
7278
server = string
73-
username = string
74-
password = string
75-
user_assigned_identity_id = string
79+
username = optional(string)
80+
password = optional(string)
81+
user_assigned_identity_id = optional(string)
7682
}))
7783
description = "List of objects to configure connection to private registry"
7884
default = []

0 commit comments

Comments
 (0)