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_key_vault - can now be created without subscription level permissions (fixes #6059) #6260

Merged
merged 8 commits into from Apr 29, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions azurerm/internal/services/keyvault/resource_arm_key_vault.go
Expand Up @@ -216,14 +216,16 @@ func resourceArmKeyVaultCreate(d *schema.ResourceData, meta interface{}) error {
// before creating check to see if the key vault exists in the soft delete state
softDeletedKeyVault, err := client.GetDeleted(ctx, name, location)
if err != nil {
if !utils.ResponseWasNotFound(softDeletedKeyVault.Response) {
// If Terraform lacks permission to read at the Subscription we'll get 409, not 404
if !utils.ResponseWasNotFound(softDeletedKeyVault.Response) && !utils.ResponseWasForbidden(softDeletedKeyVault.Response) {
return fmt.Errorf("Error checking for the presence of an existing Soft-Deleted Key Vault %q (Location %q): %+v", name, location, err)
}
}

// if so, does the user want us to recover it?

recoverSoftDeletedKeyVault := false
if !utils.ResponseWasNotFound(softDeletedKeyVault.Response) {
if !utils.ResponseWasNotFound(softDeletedKeyVault.Response) && !utils.ResponseWasForbidden(softDeletedKeyVault.Response) {
if !meta.(*clients.Client).Features.KeyVault.RecoverSoftDeletedKeyVaults {
// this exists but the users opted out so they must import this it out-of-band
return fmt.Errorf(optedOutOfRecoveringSoftDeletedKeyVaultErrorFmt(name, location))
Expand Down
4 changes: 4 additions & 0 deletions azurerm/utils/response.go
Expand Up @@ -11,6 +11,10 @@ func ResponseWasNotFound(resp autorest.Response) bool {
return ResponseWasStatusCode(resp, http.StatusNotFound)
}

func ResponseWasForbidden(resp autorest.Response) bool {
return ResponseWasStatusCode(resp, http.StatusForbidden)
}

func ResponseErrorIsRetryable(err error) bool {
if arerr, ok := err.(autorest.DetailedError); ok {
err = arerr.Original
Expand Down