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

New Resource: azurerm_key_vault_managed_hardware_security_module_key #25935

Merged
merged 9 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 2 additions & 0 deletions internal/features/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ func Default() UserFeatures {
PurgeSoftDeletedCertsOnDestroy: true,
PurgeSoftDeletedSecretsOnDestroy: true,
PurgeSoftDeletedHSMsOnDestroy: true,
PurgeSoftDeletedHSMKeysOnDestroy: true,
RecoverSoftDeletedKeyVaults: true,
RecoverSoftDeletedKeys: true,
RecoverSoftDeletedCerts: true,
RecoverSoftDeletedSecrets: true,
RecoverSoftDeletedHSMKeys: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we're supporting Key Vault Keys and Managed HSM Keys in the Provider - it'd probably be worth putting the Managed HSM stuff within managed_hsm - so whilst I realise we have the existing feature-flag here - can we add a TODO to fix this in 4.0?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

},
LogAnalyticsWorkspace: LogAnalyticsWorkspaceFeatures{
PermanentlyDeleteOnDestroy: true,
Expand Down
2 changes: 2 additions & 0 deletions internal/features/user_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ type KeyVaultFeatures struct {
PurgeSoftDeletedCertsOnDestroy bool
PurgeSoftDeletedSecretsOnDestroy bool
PurgeSoftDeletedHSMsOnDestroy bool
PurgeSoftDeletedHSMKeysOnDestroy bool
RecoverSoftDeletedKeyVaults bool
RecoverSoftDeletedKeys bool
RecoverSoftDeletedCerts bool
RecoverSoftDeletedSecrets bool
RecoverSoftDeletedHSMKeys bool
}

type TemplateDeploymentFeatures struct {
Expand Down
20 changes: 20 additions & 0 deletions internal/provider/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ func schemaFeatures(supportLegacyTestSuite bool) *pluginsdk.Schema {
Default: true,
},

"purge_soft_deleted_hardware_security_module_keys_on_destroy": {
Description: "When enabled soft-deleted `azurerm_key_vault_managed_hardware_security_module_key` resources will be permanently deleted (e.g purged), when destroyed",
Type: pluginsdk.TypeBool,
Optional: true,
Default: true,
},

"recover_soft_deleted_certificates": {
Description: "When enabled soft-deleted `azurerm_key_vault_certificate` resources will be restored, instead of creating new ones",
Type: pluginsdk.TypeBool,
Expand Down Expand Up @@ -156,6 +163,13 @@ func schemaFeatures(supportLegacyTestSuite bool) *pluginsdk.Schema {
Optional: true,
Default: true,
},

"recover_soft_deleted_hardware_security_module_keys": {
Description: "When enabled soft-deleted `azurerm_key_vault_managed_hardware_security_module_key` resources will be restored, instead of creating new ones",
Type: pluginsdk.TypeBool,
Optional: true,
Default: true,
},
},
},
},
Expand Down Expand Up @@ -438,6 +452,9 @@ func expandFeatures(input []interface{}) features.UserFeatures {
if v, ok := keyVaultRaw["purge_soft_deleted_hardware_security_modules_on_destroy"]; ok {
featuresMap.KeyVault.PurgeSoftDeletedHSMsOnDestroy = v.(bool)
}
if v, ok := keyVaultRaw["purge_soft_deleted_hardware_security_module_keys_on_destroy"]; ok {
featuresMap.KeyVault.PurgeSoftDeletedHSMKeysOnDestroy = v.(bool)
}
if v, ok := keyVaultRaw["recover_soft_deleted_certificates"]; ok {
featuresMap.KeyVault.RecoverSoftDeletedCerts = v.(bool)
}
Expand All @@ -450,6 +467,9 @@ func expandFeatures(input []interface{}) features.UserFeatures {
if v, ok := keyVaultRaw["recover_soft_deleted_secrets"]; ok {
featuresMap.KeyVault.RecoverSoftDeletedSecrets = v.(bool)
}
if v, ok := keyVaultRaw["recover_soft_deleted_hardware_security_module_keys"]; ok {
featuresMap.KeyVault.RecoverSoftDeletedHSMKeys = v.(bool)
}
}
}

Expand Down
92 changes: 56 additions & 36 deletions internal/provider/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ func TestExpandFeatures(t *testing.T) {
PurgeSoftDeletedSecretsOnDestroy: true,
PurgeSoftDeleteOnDestroy: true,
PurgeSoftDeletedHSMsOnDestroy: true,
PurgeSoftDeletedHSMKeysOnDestroy: true,
RecoverSoftDeletedCerts: true,
RecoverSoftDeletedKeys: true,
RecoverSoftDeletedKeyVaults: true,
RecoverSoftDeletedSecrets: true,
RecoverSoftDeletedHSMKeys: true,
},
LogAnalyticsWorkspace: features.LogAnalyticsWorkspaceFeatures{
PermanentlyDeleteOnDestroy: true,
Expand Down Expand Up @@ -112,15 +114,17 @@ func TestExpandFeatures(t *testing.T) {
},
"key_vault": []interface{}{
map[string]interface{}{
"purge_soft_deleted_certificates_on_destroy": true,
"purge_soft_deleted_keys_on_destroy": true,
"purge_soft_deleted_secrets_on_destroy": true,
"purge_soft_deleted_hardware_security_modules_on_destroy": true,
"purge_soft_delete_on_destroy": true,
"recover_soft_deleted_certificates": true,
"recover_soft_deleted_keys": true,
"recover_soft_deleted_key_vaults": true,
"recover_soft_deleted_secrets": true,
"purge_soft_deleted_certificates_on_destroy": true,
"purge_soft_deleted_keys_on_destroy": true,
"purge_soft_deleted_secrets_on_destroy": true,
"purge_soft_deleted_hardware_security_modules_on_destroy": true,
"purge_soft_deleted_hardware_security_module_keys_on_destroy": true,
"purge_soft_delete_on_destroy": true,
"recover_soft_deleted_certificates": true,
"recover_soft_deleted_keys": true,
"recover_soft_deleted_key_vaults": true,
"recover_soft_deleted_secrets": true,
"recover_soft_deleted_hardware_security_module_keys": true,
},
},
"log_analytics_workspace": []interface{}{
Expand Down Expand Up @@ -202,10 +206,12 @@ func TestExpandFeatures(t *testing.T) {
PurgeSoftDeletedSecretsOnDestroy: true,
PurgeSoftDeleteOnDestroy: true,
PurgeSoftDeletedHSMsOnDestroy: true,
PurgeSoftDeletedHSMKeysOnDestroy: true,
RecoverSoftDeletedCerts: true,
RecoverSoftDeletedKeys: true,
RecoverSoftDeletedKeyVaults: true,
RecoverSoftDeletedSecrets: true,
RecoverSoftDeletedHSMKeys: true,
},
LogAnalyticsWorkspace: features.LogAnalyticsWorkspaceFeatures{
PermanentlyDeleteOnDestroy: true,
Expand Down Expand Up @@ -273,15 +279,17 @@ func TestExpandFeatures(t *testing.T) {
},
"key_vault": []interface{}{
map[string]interface{}{
"purge_soft_deleted_certificates_on_destroy": false,
"purge_soft_deleted_keys_on_destroy": false,
"purge_soft_deleted_secrets_on_destroy": false,
"purge_soft_deleted_hardware_security_modules_on_destroy": false,
"purge_soft_delete_on_destroy": false,
"recover_soft_deleted_certificates": false,
"recover_soft_deleted_keys": false,
"recover_soft_deleted_key_vaults": false,
"recover_soft_deleted_secrets": false,
"purge_soft_deleted_certificates_on_destroy": false,
"purge_soft_deleted_keys_on_destroy": false,
"purge_soft_deleted_secrets_on_destroy": false,
"purge_soft_deleted_hardware_security_modules_on_destroy": false,
"purge_soft_deleted_hardware_security_module_keys_on_destroy": false,
"purge_soft_delete_on_destroy": false,
"recover_soft_deleted_certificates": false,
"recover_soft_deleted_keys": false,
"recover_soft_deleted_key_vaults": false,
"recover_soft_deleted_secrets": false,
"recover_soft_deleted_hardware_security_module_keys": false,
},
},
"log_analytics_workspace": []interface{}{
Expand Down Expand Up @@ -362,11 +370,13 @@ func TestExpandFeatures(t *testing.T) {
PurgeSoftDeletedKeysOnDestroy: false,
PurgeSoftDeletedSecretsOnDestroy: false,
PurgeSoftDeletedHSMsOnDestroy: false,
PurgeSoftDeletedHSMKeysOnDestroy: false,
PurgeSoftDeleteOnDestroy: false,
RecoverSoftDeletedCerts: false,
RecoverSoftDeletedKeys: false,
RecoverSoftDeletedKeyVaults: false,
RecoverSoftDeletedSecrets: false,
RecoverSoftDeletedHSMKeys: false,
},
LogAnalyticsWorkspace: features.LogAnalyticsWorkspaceFeatures{
PermanentlyDeleteOnDestroy: false,
Expand Down Expand Up @@ -708,10 +718,12 @@ func TestExpandFeaturesKeyVault(t *testing.T) {
PurgeSoftDeletedSecretsOnDestroy: true,
PurgeSoftDeleteOnDestroy: true,
PurgeSoftDeletedHSMsOnDestroy: true,
PurgeSoftDeletedHSMKeysOnDestroy: true,
RecoverSoftDeletedCerts: true,
RecoverSoftDeletedKeys: true,
RecoverSoftDeletedKeyVaults: true,
RecoverSoftDeletedSecrets: true,
RecoverSoftDeletedHSMKeys: true,
},
},
},
Expand All @@ -721,15 +733,17 @@ func TestExpandFeaturesKeyVault(t *testing.T) {
map[string]interface{}{
"key_vault": []interface{}{
map[string]interface{}{
"purge_soft_deleted_certificates_on_destroy": true,
"purge_soft_deleted_keys_on_destroy": true,
"purge_soft_deleted_secrets_on_destroy": true,
"purge_soft_deleted_hardware_security_modules_on_destroy": true,
"purge_soft_delete_on_destroy": true,
"recover_soft_deleted_certificates": true,
"recover_soft_deleted_keys": true,
"recover_soft_deleted_key_vaults": true,
"recover_soft_deleted_secrets": true,
"purge_soft_deleted_certificates_on_destroy": true,
"purge_soft_deleted_keys_on_destroy": true,
"purge_soft_deleted_secrets_on_destroy": true,
"purge_soft_deleted_hardware_security_modules_on_destroy": true,
"purge_soft_deleted_hardware_security_module_keys_on_destroy": true,
"purge_soft_delete_on_destroy": true,
"recover_soft_deleted_certificates": true,
"recover_soft_deleted_keys": true,
"recover_soft_deleted_key_vaults": true,
"recover_soft_deleted_secrets": true,
"recover_soft_deleted_hardware_security_module_keys": true,
},
},
},
Expand All @@ -740,11 +754,13 @@ func TestExpandFeaturesKeyVault(t *testing.T) {
PurgeSoftDeletedKeysOnDestroy: true,
PurgeSoftDeletedSecretsOnDestroy: true,
PurgeSoftDeletedHSMsOnDestroy: true,
PurgeSoftDeletedHSMKeysOnDestroy: true,
PurgeSoftDeleteOnDestroy: true,
RecoverSoftDeletedCerts: true,
RecoverSoftDeletedKeys: true,
RecoverSoftDeletedKeyVaults: true,
RecoverSoftDeletedSecrets: true,
RecoverSoftDeletedHSMKeys: true,
},
},
},
Expand All @@ -754,15 +770,17 @@ func TestExpandFeaturesKeyVault(t *testing.T) {
map[string]interface{}{
"key_vault": []interface{}{
map[string]interface{}{
"purge_soft_deleted_certificates_on_destroy": false,
"purge_soft_deleted_keys_on_destroy": false,
"purge_soft_deleted_secrets_on_destroy": false,
"purge_soft_deleted_hardware_security_modules_on_destroy": false,
"purge_soft_delete_on_destroy": false,
"recover_soft_deleted_certificates": false,
"recover_soft_deleted_keys": false,
"recover_soft_deleted_key_vaults": false,
"recover_soft_deleted_secrets": false,
"purge_soft_deleted_certificates_on_destroy": false,
"purge_soft_deleted_keys_on_destroy": false,
"purge_soft_deleted_secrets_on_destroy": false,
"purge_soft_deleted_hardware_security_modules_on_destroy": false,
"purge_soft_deleted_hardware_security_module_keys_on_destroy": false,
"purge_soft_delete_on_destroy": false,
"recover_soft_deleted_certificates": false,
"recover_soft_deleted_keys": false,
"recover_soft_deleted_key_vaults": false,
"recover_soft_deleted_secrets": false,
"recover_soft_deleted_hardware_security_module_keys": false,
},
},
},
Expand All @@ -774,10 +792,12 @@ func TestExpandFeaturesKeyVault(t *testing.T) {
PurgeSoftDeletedSecretsOnDestroy: false,
PurgeSoftDeleteOnDestroy: false,
PurgeSoftDeletedHSMsOnDestroy: false,
PurgeSoftDeletedHSMKeysOnDestroy: false,
RecoverSoftDeletedCerts: false,
RecoverSoftDeletedKeyVaults: false,
RecoverSoftDeletedKeys: false,
RecoverSoftDeletedSecrets: false,
RecoverSoftDeletedHSMKeys: false,
},
},
},
Expand Down
8 changes: 4 additions & 4 deletions internal/services/managedhsm/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Client struct {
ManagedHsmClient *managedhsms.ManagedHsmsClient

// Data Plane
DataPlaneClient *dataplane.BaseClient
DataPlaneKeysClient *dataplane.BaseClient
DataPlaneRoleAssignmentsClient *dataplane.RoleAssignmentsClient
DataPlaneRoleDefinitionsClient *dataplane.RoleDefinitionsClient
DataPlaneSecurityDomainsClient *dataplane.HSMSecurityDomainClient
Expand All @@ -36,8 +36,8 @@ func NewClient(o *common.ClientOptions) (*Client, error) {
}
o.Configure(managedHsmClient.Client, o.Authorizers.ResourceManager)

managementClient := dataplane.New()
o.ConfigureClient(&managementClient.Client, o.KeyVaultAuthorizer)
managementKeysClient := dataplane.New()
o.ConfigureClient(&managementKeysClient.Client, o.ManagedHSMAuthorizer)

securityDomainClient := dataplane.NewHSMSecurityDomainClient()
o.ConfigureClient(&securityDomainClient.Client, o.ManagedHSMAuthorizer)
Expand All @@ -53,7 +53,7 @@ func NewClient(o *common.ClientOptions) (*Client, error) {
ManagedHsmClient: managedHsmClient,

// Data Plane
DataPlaneClient: &managementClient,
DataPlaneKeysClient: &managementKeysClient,
DataPlaneSecurityDomainsClient: &securityDomainClient,
DataPlaneRoleDefinitionsClient: &roleDefinitionsClient,
DataPlaneRoleAssignmentsClient: &roleAssignmentsClient,
Expand Down
Loading
Loading