Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_cosmosdb_account: include key vault id in update requests to work with azure policies #9966

Merged
merged 3 commits into from
Dec 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions azurerm/internal/services/cosmos/cosmosdb_account_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,15 @@ func resourceArmCosmosDbAccountUpdate(d *schema.ResourceData, meta interface{})
Tags: tags.Expand(t),
}

if keyVaultKeyIDRaw, ok := d.GetOk("key_vault_key_id"); ok {
keyVaultKey, err := azure.ParseKeyVaultChildIDVersionOptional(keyVaultKeyIDRaw.(string))
if err != nil {
return fmt.Errorf("could not parse Key Vault Key ID: %+v", err)
}
keyVaultKeyURI := fmt.Sprintf("%skeys/%s", keyVaultKey.KeyVaultBaseUrl, keyVaultKey.Name)
account.DatabaseAccountCreateUpdateProperties.KeyVaultKeyURI = utils.String(keyVaultKeyURI)
}

if _, err = resourceArmCosmosDbAccountApiUpsert(client, ctx, resourceGroup, name, account, d); err != nil {
return fmt.Errorf("Error updating CosmosDB Account %q properties (Resource Group %q): %+v", name, resourceGroup, err)
}
Expand Down
32 changes: 27 additions & 5 deletions azurerm/internal/services/cosmos/cosmosdb_account_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,26 @@ func testAccAzureRMCosmosDBAccount_public_network_access_enabled(t *testing.T, k
})
}

func TestAccAzureRMCosmosDBAccount_key_vault_uri(t *testing.T) {
testAccAzureRMCosmosDBAccount_key_vault_uri(t, documentdb.MongoDB, documentdb.Strong)
func TestAccCosmosDBAccount_keyVaultUri(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy,
Steps: []resource.TestStep{
{
Config: checkAccAzureRMCosmosDBAccount_key_vault_uri(data, documentdb.MongoDB, documentdb.Strong),
Check: resource.ComposeAggregateTestCheckFunc(
checkAccAzureRMCosmosDBAccount_basic(data, documentdb.Strong, 1),
),
},
data.ImportStep(),
},
})
}

func testAccAzureRMCosmosDBAccount_key_vault_uri(t *testing.T, kind documentdb.DatabaseAccountKind, consistency documentdb.DefaultConsistencyLevel) {
func TestAccCosmosDBAccount_keyVaultUriUpdateConsistancy(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test")

resource.ParallelTest(t, resource.TestCase{
Expand All @@ -110,9 +125,16 @@ func testAccAzureRMCosmosDBAccount_key_vault_uri(t *testing.T, kind documentdb.D
CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy,
Steps: []resource.TestStep{
{
Config: checkAccAzureRMCosmosDBAccount_key_vault_uri(data, kind, consistency),
Config: checkAccAzureRMCosmosDBAccount_key_vault_uri(data, documentdb.MongoDB, documentdb.Strong),
Check: resource.ComposeAggregateTestCheckFunc(
checkAccAzureRMCosmosDBAccount_basic(data, consistency, 1),
checkAccAzureRMCosmosDBAccount_basic(data, documentdb.Strong, 1),
),
},
data.ImportStep(),
{
Config: checkAccAzureRMCosmosDBAccount_key_vault_uri(data, documentdb.MongoDB, documentdb.Session),
Check: resource.ComposeAggregateTestCheckFunc(
checkAccAzureRMCosmosDBAccount_basic(data, documentdb.Strong, 1),
),
},
data.ImportStep(),
Expand Down