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_synapse_workspace_key: deprecate cusomter_managed_key_name in favour of the correctly spelled customer_managed_key_name #13881

Merged
merged 7 commits into from
Oct 29, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/acceptance/testcase.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func (td TestData) DataSourceTestInSequence(t *testing.T, steps []TestStep) {
td.runAcceptanceSequentialTest(t, testCase)
}

// lintignore:AT001
func (td TestData) ResourceTest(t *testing.T, testResource types.TestResource, steps []TestStep) {
testCase := resource.TestCase{
PreCheck: func() { PreCheck(t) },
Expand Down
41 changes: 34 additions & 7 deletions internal/services/synapse/synapse_workspace_key_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,26 @@ func resourceSynapseWorkspaceKey() *pluginsdk.Resource {
},

"cusomter_managed_key_name": {
Type: pluginsdk.TypeString,
Required: true,
Type: pluginsdk.TypeString,
Optional: true,
Computed: true,
Deprecated: "As this property name contained a typo originally, please switch to using 'customer_managed_key_name' instead.",
AtLeastOneOf: []string{
"cusomter_managed_key_name",
"customer_managed_key_name",
},
ConflictsWith: []string{"customer_managed_key_name"},
},

"customer_managed_key_name": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

sadly as mistaken as this name is the typo needs to be gracefully deprecated :( could we add a new property with the correct name and deprecate the old one? thanks

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sigh... Sure :)

Type: pluginsdk.TypeString,
Optional: true,
Computed: true,
ConflictsWith: []string{"cusomter_managed_key_name"},
AtLeastOneOf: []string{
"cusomter_managed_key_name",
"customer_managed_key_name",
},
},

"customer_managed_key_versionless_id": {
Expand Down Expand Up @@ -75,7 +93,8 @@ func resourceSynapseWorkspaceKeysCreateUpdate(d *pluginsdk.ResourceData, meta in
}

key := d.Get("customer_managed_key_versionless_id")
keyName := d.Get("cusomter_managed_key_name").(string)
keyName := d.Get("customer_managed_key_name").(string)
keyNameTypoed := d.Get("cusomter_managed_key_name").(string)
isActiveCMK := d.Get("active").(bool)

log.Printf("[INFO] Is active CMK: %t", isActiveCMK)
Expand All @@ -89,7 +108,14 @@ func resourceSynapseWorkspaceKeysCreateUpdate(d *pluginsdk.ResourceData, meta in
KeyProperties: &keyProperties,
}

keyresult, err := client.CreateOrUpdate(ctx, workspaceId.ResourceGroup, workspaceId.Name, keyName, synapseKey)
actualKeyName := ""
if keyName != "" {
actualKeyName = keyName
} else {
actualKeyName = keyNameTypoed
}

keyresult, err := client.CreateOrUpdate(ctx, workspaceId.ResourceGroup, workspaceId.Name, actualKeyName, synapseKey)
if err != nil {
return fmt.Errorf("creating Synapse Workspace Key %q (Workspace %q): %+v", workspaceId.Name, workspaceId.Name, err)
}
Expand All @@ -100,14 +126,14 @@ func resourceSynapseWorkspaceKeysCreateUpdate(d *pluginsdk.ResourceData, meta in

// If the state of the key in the response (from Azure) is not equal to the desired target state (from plan/config), we'll wait until that change is complete
if isActiveCMK != *keyresult.KeyProperties.IsActiveCMK {
updateWait := synapseKeysWaitForStateChange(ctx, meta, d.Timeout(pluginsdk.TimeoutUpdate), workspaceId.ResourceGroup, workspaceId.Name, keyName, strconv.FormatBool(*keyresult.KeyProperties.IsActiveCMK), strconv.FormatBool(isActiveCMK))
updateWait := synapseKeysWaitForStateChange(ctx, meta, d.Timeout(pluginsdk.TimeoutUpdate), workspaceId.ResourceGroup, workspaceId.Name, actualKeyName, strconv.FormatBool(*keyresult.KeyProperties.IsActiveCMK), strconv.FormatBool(isActiveCMK))

if _, err := updateWait.WaitForStateContext(ctx); err != nil {
return fmt.Errorf("waiting for Synapse Keys to finish updating '%q' (Workspace Group %q): %v", keyName, workspaceId.Name, err)
return fmt.Errorf("waiting for Synapse Keys to finish updating '%q' (Workspace Group %q): %v", actualKeyName, workspaceId.Name, err)
}
}

id := parse.NewWorkspaceKeysID(workspaceId.SubscriptionId, workspaceId.ResourceGroup, workspaceId.Name, keyName)
id := parse.NewWorkspaceKeysID(workspaceId.SubscriptionId, workspaceId.ResourceGroup, workspaceId.Name, actualKeyName)
d.SetId(id.ID())

return resourceSynapseWorkspaceKeyRead(d, meta)
Expand All @@ -134,6 +160,7 @@ func resourceSynapseWorkspaceKeyRead(d *pluginsdk.ResourceData, meta interface{}
// Set the properties
d.Set("synapse_workspace_id", workspaceID.ID())
d.Set("active", resp.KeyProperties.IsActiveCMK)
d.Set("customer_managed_key_name", id.KeyName)
d.Set("cusomter_managed_key_name", id.KeyName)
d.Set("customer_managed_key_versionless_id", resp.KeyProperties.KeyVaultURL)

Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/synapse_workspace_keys.html.markdown
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
subcategory: "Synapse"
layout: "azurerm"
page_title: "Azure Resource Manager: azurerm_synapse_workspace_keys"
page_title: "Azure Resource Manager: azurerm_synapse_workspace_key"
description: |-
Manages Synapse Workspace Keys
---
Expand Down Expand Up @@ -116,7 +116,7 @@ resource "azurerm_synapse_workspace_key" "example" {

The following arguments are supported:

* `key_name` - (Required) Specifies the name of the workspace key. Should match the name of the key in the synapse workspace.
* `customer_managed_key_name` - (Required) Specifies the name of the workspace key. Should match the name of the key in the synapse workspace.

* `customer_managed_key_versionless_id` - (Required) The Azure Key Vault Key Versionless ID to be used as the Customer Managed Key (CMK) for double encryption

Expand Down