Skip to content

Commit

Permalink
allow windows container groups to be created with a managed identity (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
stephybun committed Jun 13, 2024
1 parent d8a5e89 commit d883408
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
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

0 comments on commit d883408

Please sign in to comment.