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

Enhancement: azurerm_key_vault: Add support for soft delete, purge protection, and purge on destroy #5344

Merged
merged 40 commits into from
Feb 21, 2020

Conversation

WodansSon
Copy link
Collaborator

@WodansSon WodansSon commented Jan 8, 2020

Porting features from closed #1805 to new code base
Original: #1517
Dependent PR: #4366 #5668

(fixes #1329)

@WodansSon WodansSon requested a review from katbyte January 8, 2020 23:30
Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @WodansSon

Thanks for porting this PR over to the new structure.

Taking a look though this mostly LGTM - if we can fix up the comments then this should otherwise be good to go out in 2.0 👍

Thanks!

Optional: true,
Default: false,
ConflictsWith: []string{"enabled_for_purge_protection"},
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can't go in the resource unfortunately, since the config isn't necessarily available during a destroy (e.g. if the users removed the code, this property won't be accessible) - instead it'll need to be in the provider block (which wants a little design work) - probably something like this:

provider "azurerm" {
  # ...
  purge_on_delete {
    key_vault = true
  }
}

the reason for doing this as a nested block is this also applies to some other resources (recovery services) so we may as well use the same (design) approach for both

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, moved it into the features section of the provider block.

"enabled_for_purge_protection": {
Type: schema.TypeBool,
Optional: true,
ValidateFunc: validate.BoolIsTrue(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(same here)

Suggested change
ValidateFunc: validate.BoolIsTrue(),

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

parameters.Properties.EnableSoftDelete = &enabledForSoftDelete
}

// This setting can only be set if it is true, if set when value is false API returns errors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's an issue tracking disabling purge protection: Azure/azure-rest-api-specs#8075

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...it still throws an error, maybe in future they will fix this and we can re-address the behavior.

@@ -277,6 +298,16 @@ func resourceArmKeyVaultCreateUpdate(d *schema.ResourceData, meta interface{}) e
Tags: tags.Expand(t),
}

// This setting can only be set if it is true, if set when value is false API returns errors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is no longer true - soft delete can be enabled/disabled?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope... it still throws an error, maybe in future they will fix this and we can re-address the behavior.

@@ -461,6 +494,22 @@ func resourceArmKeyVaultDelete(d *schema.ResourceData, meta interface{}) error {
}
}

if d.Get("purge_on_delete").(bool) && d.Get("enabled_for_soft_delete").(bool) && err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(as above) we'll need to pull this from the provider block instead unfortunately

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

website/docs/r/key_vault.html.markdown Outdated Show resolved Hide resolved
@@ -84,6 +84,12 @@ The following arguments are supported:

* `enabled_for_template_deployment` - (Optional) Boolean flag to specify whether Azure Resource Manager is permitted to retrieve secrets from the key vault. Defaults to `false`.

* `enabled_for_soft_delete` - (Optional) Boolean flag to specify whether the key vault is enabled for soft delete. Once enabled you can not disable this setting.

* `purge_on_delete` - (Optional) Boolean flag to specify if the KeyVault should be purged on delete. This purges KeyVaults enabled for soft delete on resource deletition.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(as above) we'll need to move this into the provider block

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

website/docs/r/key_vault.html.markdown Outdated Show resolved Hide resolved
WodansSon and others added 5 commits January 23, 2020 14:16
Co-Authored-By: Tom Harvey <tombuildsstuff@users.noreply.github.com>
Co-Authored-By: Tom Harvey <tombuildsstuff@users.noreply.github.com>
Co-Authored-By: Tom Harvey <tombuildsstuff@users.noreply.github.com>
@ghost ghost added size/XL and removed size/L labels Feb 1, 2020
@WodansSon WodansSon changed the title Key Vault: support for soft delete Enhancement: azurerm_key_vault: Add support for soft delete, purge protection, and purge on destroy Feb 7, 2020
Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @WodansSon

Thanks for porting this PR over to the refactored structure - I've taken a look through and left some comments inline but this otherwise LGTM; as discussed offline I'm going to push a few commits to resolve the issues highlighted below, but this otherwise looks good to me 👍

Thanks!

website/docs/r/key_vault.html.markdown Outdated Show resolved Hide resolved
website/docs/r/key_vault.html.markdown Outdated Show resolved Hide resolved
azurerm/helpers/validate/bool_test.go Outdated Show resolved Hide resolved
azurerm/helpers/azure/key_vault.go Outdated Show resolved Hide resolved
@ghost ghost added size/XXL and removed size/XL labels Feb 20, 2020
@tombuildsstuff tombuildsstuff removed the request for review from katbyte February 20, 2020 19:32
@WodansSon
Copy link
Collaborator Author

I'm not sure what to do for the test cases where soft delete is enabled, when the test finishes and it destroys the test resources, the key vault will still be there just soft deleted. My workaround for this was to add an extra test step pointing the config to the testAccAzureRMKeyVault_softDeletePurge config which then forces the resource to destroy the key vault by triggering the purge on destroy code path, else we will have a bunch of key vaults hanging out in the soft delete state for 90 days.

I also think we need to update the exists function in the tests to verify that the key vault is:

  1. Deleted, cannot be found with a normal client.Get
  2. Not in the soft delete state, cannot be found with a client.GetDeleted

WDYT?

Copy link
Collaborator Author

@WodansSon WodansSon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is one change that I think needs to be made, other than that I think this is good to go!

@tombuildsstuff
Copy link
Contributor

Tests pass:

Screenshot 2020-02-21 at 16 54 19

@tombuildsstuff tombuildsstuff merged commit 2e17f74 into master Feb 21, 2020
@tombuildsstuff tombuildsstuff deleted the e_keyvault_puge_softdelete branch February 21, 2020 17:46
tombuildsstuff added a commit that referenced this pull request Feb 21, 2020
@ghost
Copy link

ghost commented Feb 24, 2020

This has been released in version 2.0.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "azurerm" {
    version = "~> 2.0.0"
}
# ... other configuration ...

@ghost
Copy link

ghost commented Mar 28, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing soft delete option in azurerm_key_vault
2 participants