Skip to content

Commit

Permalink
azurerm_recovery_vaults: fix creation with `SystemAssigned, UserAss…
Browse files Browse the repository at this point in the history
…igned` identity (hashicorp#24978)

* do additional update for identity

* update code
  • Loading branch information
ziyeqf authored Feb 26, 2024
1 parent 9fc6681 commit a8f5ddd
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,18 @@ func resourceRecoveryServicesVaultCreate(d *pluginsdk.ResourceData, meta interfa
vault.Properties.SecuritySettings = expandRecoveryServicesVaultSecuritySettings(immutability)
}

// Async Operaation of creation with `UserAssigned` identity is returned with 404
// Tracked on https://github.com/Azure/azure-rest-api-specs/issues/27869
// `SystemAssigned, UserAssigned` Identity require an additional update to work
// Trakced on https://github.com/Azure/azure-rest-api-specs/issues/27851
if expandedIdentity.Type == identity.TypeUserAssigned || expandedIdentity.Type == identity.TypeSystemAssignedUserAssigned {
requireAdditionalUpdate = true
updatePatch.Identity = expandedIdentity
vault.Identity = &identity.SystemAndUserAssignedMap{
Type: identity.TypeNone,
}
}

err = client.CreateOrUpdateThenPoll(ctx, id, vault)
if err != nil {
return fmt.Errorf("creating %s: %+v", id.String(), err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func TestAccRecoveryServicesVault_SystemAssignedIdentity(t *testing.T) {
})
}

func TestAccRecoveryServicesVault_UserAssignedIdentity(t *testing.T) {
func TestAccRecoveryServicesVault_Identity(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_recovery_services_vault", "test")
r := RecoveryServicesVaultResource{}

Expand All @@ -185,6 +185,13 @@ func TestAccRecoveryServicesVault_UserAssignedIdentity(t *testing.T) {
),
},
data.ImportStep(),
{
Config: r.basicWithSystemAssignedUserAssignedIdentity(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

Expand Down Expand Up @@ -738,6 +745,41 @@ resource "azurerm_recovery_services_vault" "test" {
`, data.RandomInteger, data.Locations.Primary)
}

func (RecoveryServicesVaultResource) basicWithSystemAssignedUserAssignedIdentity(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_user_assigned_identity" "test" {
name = "acctest-uai-%[1]d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-recovery-%[1]d"
location = "%[2]s"
}
resource "azurerm_recovery_services_vault" "test" {
name = "acctest-Vault-%[1]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
sku = "Standard"
identity {
type = "SystemAssigned, UserAssigned"
identity_ids = [
azurerm_user_assigned_identity.test.id,
]
}
soft_delete_enabled = false
}
`, data.RandomInteger, data.Locations.Primary)
}

func (RecoveryServicesVaultResource) basicWithImmutability(data acceptance.TestData, immutability string) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down

0 comments on commit a8f5ddd

Please sign in to comment.