Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_container_groups - allow windows container groups to be created with a User Assigned Identity #26308

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions internal/services/containers/container_group_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -796,15 +796,11 @@ func resourceContainerGroupCreate(d *pluginsdk.ResourceData, meta interface{}) e
Zones: &zones,
}

// Container Groups with OS Type Windows do not support managed identities but the API also does not accept Identity Type: None
// https://github.com/Azure/azure-rest-api-specs/issues/18122
if OSType != string(containerinstance.OperatingSystemTypesWindows) {
expandedIdentity, err := identity.ExpandSystemAndUserAssignedMap(d.Get("identity").([]interface{}))
if err != nil {
return fmt.Errorf("expanding `identity`: %+v", err)
}
containerGroup.Identity = expandedIdentity
expandedIdentity, err := identity.ExpandSystemAndUserAssignedMap(d.Get("identity").([]interface{}))
if err != nil {
return fmt.Errorf("expanding `identity`: %+v", err)
}
containerGroup.Identity = expandedIdentity

if IPAddressType != "None" {
containerGroup.Properties.IPAddress = &containerinstance.IPAddress{
Expand Down
14 changes: 13 additions & 1 deletion internal/services/containers/container_group_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1835,6 +1835,13 @@ resource "azurerm_log_analytics_solution" "test" {
}
}

resource "azurerm_user_assigned_identity" "test" {
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location

name = "acctest%s"
}

resource "azurerm_container_group" "test" {
name = "acctestcontainergroup-%d"
location = azurerm_resource_group.test.location
Expand All @@ -1844,6 +1851,11 @@ resource "azurerm_container_group" "test" {
os_type = "Windows"
restart_policy = "Never"

identity {
type = "UserAssigned"
identity_ids = [azurerm_user_assigned_identity.test.id]
}

container {
name = "windowsservercore"
image = "mcr.microsoft.com/windows/servercore/iis:20210810-windowsservercore-ltsc2019"
Expand Down Expand Up @@ -1911,7 +1923,7 @@ resource "azurerm_container_group" "test" {
environment = "Testing"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger)
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomString, data.RandomInteger, data.RandomInteger)
}

func (ContainerGroupResource) linuxComplete(data acceptance.TestData) string {
Expand Down
Loading