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

r/key_vault: defaulting soft_delete_enabled on to match the updated API behaviour #10088

Merged
merged 8 commits into from
Jan 8, 2021

Conversation

tombuildsstuff
Copy link
Contributor

This PR updates the azurerm_key_vault resource to match the updated API behaviour rolled out over late last month / the new year. Whilst #10007 provides one solution to this, after extensive testing there was ultimately more necessary to make this work, as such this PR includes:

  • Data Source: azurerm_key_vault - deprecating the field soft_delete_enabled (and conditionally removing this should 3.0 mode be enabled)
  • Resource: azurerm_key_vault - deprecating the field soft_delete_enabled and defaulting this to true (conditionally removing this should 3.0 mode be enabled). Notably this PR removes the error when attempting to disable/enable this - but since this is hard-coded to true in the Read function, operators can update their configurations (or remove the field) to clear this diff.
    • Resource: azurerm_key_vault - defaulting the field soft_delete_retention_days to 90 days, to match the API behaviour. Notably it's only possible to set this value a single time (either during create, or one-time during update) at which point it's immutable - so a state migration was necessary to default this if not explicitly set - as it's defaulted in the API but not returned unless explicitly configured.

As such this PR supersedes #10007 but fixes #9988 (albeit in a slightly different manner).

This is done with a 3.0 toggle so this is unavailable when running with the
3.0 functionality enabled.
…etention_days` to 90

This commit conditionally deprecates the `soft_delete_enabled` field and removes it entirely
if we're running in 3.0 mode. This also defaults `soft_delete_retention_days` to 90 matching
the default value used in the Azure API here, based only on the docs, since this isn't returned
if it's not configured by the user.
…_delete_retention_days`

cannot be changed after being initially set, due to the behaviour of the Azure API.

It's unfortunate we can't make this ForceNew, but this appears to be the least-bad way
of supporting this behaviour.
This is required to work around the default that's not returned from the Azure API.
These require it:

> === RUN   TestAccKeyVaultKey_basicRSAHSM
> === PAUSE TestAccKeyVaultKey_basicRSAHSM
> === CONT  TestAccKeyVaultKey_basicRSAHSM
> testing.go:684: Step 0 error: errors during apply:
> Error: Error Creating Key: keyvault.BaseClient#CreateKey: Failure responding to request: StatusCode=403 -- Original Error: autorest/azure: Service returned an error. Status=403 Code="Forbidden" Message="Hardware key operation not allowed on standard vault" InnerError={"code":"HardwareKeysNotSupported"}

> === RUN   TestAccKeyVaultKey_basicECHSM
> === PAUSE TestAccKeyVaultKey_basicECHSM
> === CONT  TestAccKeyVaultKey_basicECHSM
> testing.go:684: Step 0 error: errors during apply:
> Error: Error Creating Key: keyvault.BaseClient#CreateKey: Failure responding to request: StatusCode=403 -- Original Error: autorest/azure: Service returned an error. Status=403 Code="Forbidden" Message="Hardware key operation not allowed on standard vault" InnerError={"code":"HardwareKeysNotSupported"}
This can no longer be disabled, and is defaulted on - so this is unnecessary
@tombuildsstuff
Copy link
Contributor Author

For the changelog:

BREAKING CHANGES

* `azurerm_key_vault` - the field `soft_delete_enabled` is now defaulted to `true` to match the breaking change in the Azure API where Key Vaults now have Soft Delete enabled by default, which cannot be disabled. This property is now non-functional, defaults to `true` and will be removed in version 3.0 of the Azure Provider. [GH-10088]
* `azurerm_key_vault` - the field `soft_delete_retention_days` is now defaulted to `90` days to match the Azure API behaviour, as the Azure API does not return a value for this field when not explicitly configured, so defaulting this removes a diff with `0`. [GH-10088]

IMPROVEMENTS

* `azurerm_key_vault` - the field `soft_delete_enabled` is now defaulted to `true` to match the Azure API behaviour where Soft Delete is force-enabled and can no longer be disabled. This field is deprecated, can be safely removed from your Terraform Configuration, and will be removed in version 3.0 of the Azure Provider. [GH-10088]

BUG FIXES

* `azurerm_key_vault` - the field `soft_delete_retention_days` is now defaulted to `90` days to match the Azure API behaviour. [GH-10088]

@tombuildsstuff
Copy link
Contributor Author

Ignoring one failing test in a destroy function due to some recent refactoring (which'll be fixed separately) - the tests pass:

Screenshot 2021-01-07 at 21 37 27

Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@katbyte katbyte merged commit c7e7543 into master Jan 8, 2021
@katbyte katbyte deleted the f/key-vault-soft-delete branch January 8, 2021 00:14
katbyte added a commit that referenced this pull request Jan 8, 2021
@ghost
Copy link

ghost commented Jan 8, 2021

This has been released in version 2.42.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.42.0"
}
# ... other configuration ...

@ghost
Copy link

ghost commented Feb 7, 2021

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 👉 [email protected]. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Feb 7, 2021
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.

Azure Key Vault now requires Soft Deleted to be Enabled
2 participants