Skip to content

Commit

Permalink
azurerm_key_vault - can now be created without subscription level per…
Browse files Browse the repository at this point in the history
…missions (fixes #6059) (#6260)

fixes #6059
  • Loading branch information
Jawvig committed Apr 29, 2020
1 parent 9104e81 commit bad075e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
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

0 comments on commit bad075e

Please sign in to comment.