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_storage_encryption_scope: Allow versionless key_vault_key_id #14085

Merged
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
14 changes: 14 additions & 0 deletions internal/services/keyvault/validate/child_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,17 @@ func KeyVaultChildID(i interface{}, k string) (warnings []string, errors []error

return warnings, errors
}

func KeyVaultChildIDWithOptionalVersion(i interface{}, k string) (warnings []string, errors []error) {
v, ok := i.(string)
if !ok {
errors = append(errors, fmt.Errorf("expected type of %q to be string", k))
return warnings, errors
}

if _, err := parse.ParseOptionallyVersionedNestedItemID(v); err != nil {
errors = append(errors, fmt.Errorf("can not parse %q as a Key Vault Child resource id: %v", k, err))
}

return warnings, errors
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func resourceStorageEncryptionScope() *pluginsdk.Resource {
"key_vault_key_id": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: keyVaultValidate.KeyVaultChildID,
ValidateFunc: keyVaultValidate.KeyVaultChildIDWithOptionalVersion,
},

"infrastructure_encryption_required": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ func TestAccStorageEncryptionScope_keyVaultKey(t *testing.T) {
})
}

func TestAccStorageEncryptionScope_keyVaultKeyVersionless(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_storage_encryption_scope", "test")
r := StorageEncryptionScopeResource{}
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.keyVaultKeyVersionless(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("source").HasValue("Microsoft.KeyVault"),
),
},
data.ImportStep(),
})
}

func TestAccStorageEncryptionScope_keyVaultKeyRequireInfrastructureEncryption(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_storage_encryption_scope", "test")
r := StorageEncryptionScopeResource{}
Expand Down Expand Up @@ -206,6 +221,28 @@ resource "azurerm_storage_encryption_scope" "test" {
`, template, data.RandomInteger)
}

func (t StorageEncryptionScopeResource) keyVaultKeyVersionless(data acceptance.TestData) string {
template := t.template(data)
return fmt.Sprintf(`
provider "azurerm" {
features {
key_vault {
purge_soft_delete_on_destroy = false
}
}
}

%s

resource "azurerm_storage_encryption_scope" "test" {
name = "acctestES%d"
storage_account_id = azurerm_storage_account.test.id
source = "Microsoft.KeyVault"
key_vault_key_id = azurerm_key_vault_key.first.versionless_id
}
`, template, data.RandomInteger)
}

func (t StorageEncryptionScopeResource) keyVaultKeyUpdated(data acceptance.TestData) string {
template := t.template(data)
return fmt.Sprintf(`
Expand Down