diff --git a/internal/services/containers/container_group_resource.go b/internal/services/containers/container_group_resource.go index 225f109cdf7d..ef6ae9545013 100644 --- a/internal/services/containers/container_group_resource.go +++ b/internal/services/containers/container_group_resource.go @@ -840,13 +840,29 @@ func resourceContainerGroupUpdate(d *pluginsdk.ResourceData, meta interface{}) e return err } - t := d.Get("tags").(map[string]interface{}) + existing, err := client.ContainerGroupsGet(ctx, *id) + if err != nil { + return fmt.Errorf("reading %s: %v", id, err) + } + if existing.Model == nil { + return fmt.Errorf("reading %s: `model` was nil", id) + } + + model := *existing.Model + + if d.HasChange("identity") { + expandedIdentity, err := identity.ExpandSystemAndUserAssignedMap(d.Get("identity").([]interface{})) + if err != nil { + return fmt.Errorf("expanding `identity`: %+v", err) + } + model.Identity = expandedIdentity + } - parameters := containerinstance.Resource{ - Tags: tags.Expand(t), + if d.HasChange("tags") { + model.Tags = tags.Expand(d.Get("tags").(map[string]interface{})) } - if _, err := client.ContainerGroupsUpdate(ctx, *id, parameters); err != nil { + if err := client.ContainerGroupsCreateOrUpdateThenPoll(ctx, *id, model); err != nil { return fmt.Errorf("updating %s: %+v", *id, err) } diff --git a/internal/services/containers/container_group_resource_test.go b/internal/services/containers/container_group_resource_test.go index 1d7542256ffd..c5352d6200a9 100644 --- a/internal/services/containers/container_group_resource_test.go +++ b/internal/services/containers/container_group_resource_test.go @@ -152,6 +152,41 @@ func TestAccContainerGroup_multipleAssignedIdentities(t *testing.T) { }) } +func TestAccContainerGroup_AssignedIdentityUpdate(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_container_group", "test") + r := ContainerGroupResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.SystemAssignedIdentity(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("identity.0.type").HasValue("SystemAssigned"), + check.That(data.ResourceName).Key("identity.0.identity_ids.#").HasValue("0"), + check.That(data.ResourceName).Key("identity.0.principal_id").IsUUID(), + ), + }, + { + Config: r.UserAssignedIdentity(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("identity.0.type").HasValue("UserAssigned"), + check.That(data.ResourceName).Key("identity.0.identity_ids.#").HasValue("1"), + check.That(data.ResourceName).Key("identity.0.principal_id").HasValue(""), + ), + }, + { + Config: r.MultipleAssignedIdentities(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("identity.0.type").HasValue("SystemAssigned, UserAssigned"), + check.That(data.ResourceName).Key("identity.0.identity_ids.#").HasValue("1"), + check.That(data.ResourceName).Key("identity.0.principal_id").IsUUID(), + ), + }, + }) +} + func TestAccContainerGroup_imageRegistryCredentials(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_container_group", "test") r := ContainerGroupResource{}