Skip to content

Commit

Permalink
including #22609 fixes #22466
Browse files Browse the repository at this point in the history
* Initial Check-in...

* Typo fix

---------

Co-authored-by: Tom Bamford <[email protected]>
  • Loading branch information
WodansSon and manicminer authored Jul 20, 2023
1 parent dbe0a3a commit 0501e75
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
10 changes: 9 additions & 1 deletion internal/services/cosmos/cosmosdb_account_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,12 @@ func resourceCosmosDbAccountUpdate(d *pluginsdk.ResourceData, meta interface{})
updateDefaultIdentity = true
}

// adding 'DefaultIdentity' to avoid causing it to fallback
// to "FirstPartyIdentity" on update(s), issue #22466
if v, ok := d.GetOk("default_identity_type"); ok {
accountProps.DefaultIdentity = pointer.To(v.(string))
}

// we need the following in the accountProps even if they have not changed...
if v, ok := d.GetOk("analytical_storage"); ok {
accountProps.AnalyticalStorageConfiguration = expandCosmosDBAccountAnalyticalStorageConfiguration(v.([]interface{}))
Expand Down Expand Up @@ -1206,7 +1212,7 @@ func resourceCosmosDbAccountUpdate(d *pluginsdk.ResourceData, meta interface{})
if identityChanged {
log.Printf("[INFO] Updating AzureRM Cosmos DB Account: Updating 'DefaultIdentity' to %q because the 'Identity' was changed to %q", configDefaultIdentity, expandedIdentity.Type)
} else {
log.Printf("[INFO] Updating AzureRM Cosmos DB Account: Updating 'DefaultIdentity' to %q", configDefaultIdentity)
log.Printf("[INFO] Updating AzureRM Cosmos DB Account: Updating 'DefaultIdentity' to %q because 'default_identity_type' was changed", configDefaultIdentity)
}

// PATCH instead of PUT...
Expand All @@ -1221,6 +1227,8 @@ func resourceCosmosDbAccountUpdate(d *pluginsdk.ResourceData, meta interface{})
if err != nil {
return fmt.Errorf("updating 'default_identity_type' %q: %+v", id, err)
}
} else {
log.Printf("[INFO] [SKIP] AzureRM Cosmos DB Account: Updating 'DefaultIdentity' [NO CHANGE]")
}
}

Expand Down
73 changes: 73 additions & 0 deletions internal/services/cosmos/cosmosdb_account_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,29 @@ func TestAccCosmosDBAccount_keyVaultUriUpdateConsistancy(t *testing.T) {
})
}

func TestAccCosmosDBAccount_updateTagsWithUserAssignedDefaultIdentity(t *testing.T) {
// Regression test case for issue #22466
data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test")
r := CosmosDBAccountResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.updateTagWithUserAssignedDefaultIdentity(data, "Production"),
Check: acceptance.ComposeAggregateTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.updateTagWithUserAssignedDefaultIdentity(data, "Sandbox"),
Check: acceptance.ComposeAggregateTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccCosmosDBAccount_updateDefaultIdentity(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test")
r := CosmosDBAccountResource{}
Expand Down Expand Up @@ -4125,3 +4148,53 @@ resource "azurerm_cosmosdb_account" "test" {
}
`, r.vNetFiltersPreReqs(data), data.RandomInteger)
}

func (CosmosDBAccountResource) updateTagWithUserAssignedDefaultIdentity(data acceptance.TestData, tag string) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-cosmos-%[1]d"
location = "westeurope"
}
resource "azurerm_user_assigned_identity" "test" {
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
name = "acctest-user-example"
}
resource "azurerm_cosmosdb_account" "test" {
name = "acctest-ca-%[1]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
offer_type = "Standard"
kind = "GlobalDocumentDB"
consistency_policy {
consistency_level = "BoundedStaleness"
max_interval_in_seconds = 5
max_staleness_prefix = 100
}
geo_location {
location = azurerm_resource_group.test.location
failover_priority = 0
}
default_identity_type = join("=", ["UserAssignedIdentity", azurerm_user_assigned_identity.test.id])
identity {
type = "SystemAssigned, UserAssigned"
identity_ids = [azurerm_user_assigned_identity.test.id]
}
tags = {
environment = "%[2]s",
created_date = "2023-07-18"
}
}
`, data.RandomInteger, tag)
}

0 comments on commit 0501e75

Please sign in to comment.