Skip to content

Commit 6fdf075

Browse files
authored
azurerm_container_app_environment - fix update function for identity (hashicorp#30311)
[BUG] * `azurerm_container_app_environment` - fix an issue where `identity` was not set to the update request payload
1 parent a91ad45 commit 6fdf075

3 files changed

Lines changed: 53 additions & 10 deletions

File tree

internal/services/containerapps/azuresdkhacks/container_app_environment_update.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"net/http"
1010

11+
"github.com/hashicorp/go-azure-helpers/resourcemanager/identity"
1112
"github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata"
1213
"github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/managedenvironments"
1314
"github.com/hashicorp/go-azure-sdk/sdk/client"
@@ -79,14 +80,15 @@ func (c ManagedEnvironmentsClient) UpdateThenPoll(ctx context.Context, id manage
7980
}
8081

8182
type ManagedEnvironment struct {
82-
Id *string `json:"id,omitempty"`
83-
Kind *string `json:"kind,omitempty"`
84-
Location string `json:"location"`
85-
Name *string `json:"name,omitempty"`
86-
Properties *ManagedEnvironmentProperties `json:"properties,omitempty"`
87-
SystemData *systemdata.SystemData `json:"systemData,omitempty"`
88-
Tags *map[string]string `json:"tags,omitempty"`
89-
Type *string `json:"type,omitempty"`
83+
Id *string `json:"id,omitempty"`
84+
Identity *identity.LegacySystemAndUserAssignedMap `json:"identity,omitempty"`
85+
Kind *string `json:"kind,omitempty"`
86+
Location string `json:"location"`
87+
Name *string `json:"name,omitempty"`
88+
Properties *ManagedEnvironmentProperties `json:"properties,omitempty"`
89+
SystemData *systemdata.SystemData `json:"systemData,omitempty"`
90+
Tags *map[string]string `json:"tags,omitempty"`
91+
Type *string `json:"type,omitempty"`
9092
}
9193

9294
type ManagedEnvironmentProperties struct {

internal/services/containerapps/container_app_environment_resource.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,9 @@ func (r ContainerAppEnvironmentResource) Update() sdk.ResourceFunc {
475475
if metadata.ResourceData.HasChange("identity") {
476476
ident, err := identity.ExpandLegacySystemAndUserAssignedMapFromModel(state.Identity)
477477
if err != nil {
478-
return fmt.Errorf("expanding identity: %+v", err)
478+
return fmt.Errorf("expanding `identity`: %+v", err)
479479
}
480-
existing.Model.Identity = ident
480+
payload.Identity = ident
481481
}
482482

483483
if metadata.ResourceData.HasChange("workload_profile") {

internal/services/containerapps/container_app_environment_resource_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ func TestAccContainerAppEnvironment_updateIdentity(t *testing.T) {
6161
r := ContainerAppEnvironmentResource{}
6262

6363
data.ResourceTest(t, r, []acceptance.TestStep{
64+
{
65+
Config: r.basic(data),
66+
Check: acceptance.ComposeTestCheckFunc(
67+
check.That(data.ResourceName).ExistsInAzure(r),
68+
),
69+
},
70+
data.ImportStep(),
6471
{
6572
Config: r.withUserIdentity(data),
6673
Check: acceptance.ComposeTestCheckFunc(
@@ -75,6 +82,13 @@ func TestAccContainerAppEnvironment_updateIdentity(t *testing.T) {
7582
),
7683
},
7784
data.ImportStep(),
85+
{
86+
Config: r.withSystemAssignedUserAssignedIdentity(data),
87+
Check: acceptance.ComposeTestCheckFunc(
88+
check.That(data.ResourceName).ExistsInAzure(r),
89+
),
90+
},
91+
data.ImportStep(),
7892
{
7993
Config: r.basic(data),
8094
Check: acceptance.ComposeTestCheckFunc(
@@ -425,6 +439,33 @@ resource "azurerm_container_app_environment" "test" {
425439
`, r.template(data), data.RandomInteger)
426440
}
427441

442+
func (r ContainerAppEnvironmentResource) withSystemAssignedUserAssignedIdentity(data acceptance.TestData) string {
443+
return fmt.Sprintf(`
444+
provider "azurerm" {
445+
features {}
446+
}
447+
448+
%[1]s
449+
450+
resource "azurerm_user_assigned_identity" "test" {
451+
name = "acct-%[2]d"
452+
resource_group_name = azurerm_resource_group.test.name
453+
location = azurerm_resource_group.test.location
454+
}
455+
456+
resource "azurerm_container_app_environment" "test" {
457+
name = "acctest-CAEnv%[2]d"
458+
resource_group_name = azurerm_resource_group.test.name
459+
location = azurerm_resource_group.test.location
460+
461+
identity {
462+
type = "SystemAssigned, UserAssigned"
463+
identity_ids = [azurerm_user_assigned_identity.test.id]
464+
}
465+
}
466+
`, r.template(data), data.RandomInteger)
467+
}
468+
428469
func (r ContainerAppEnvironmentResource) basicNoProvider(data acceptance.TestData) string {
429470
return fmt.Sprintf(`
430471
%[1]s

0 commit comments

Comments
 (0)