-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
data_source_key_vault, resource_arm_key_vault, resource_arm_automation_account, resource_arm_notification_hub_namespace, resource_arm_relay_namespace: Flatten SKU #3119
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jeffreyCline,
Thank you for the PR, i've left a number of comments inline that need to be addressed before merging.
azurerm/data_source_key_vault.go
Outdated
@@ -177,7 +177,7 @@ func dataSourceArmKeyVaultRead(d *schema.ResourceData, meta interface{}) error { | |||
d.Set("enabled_for_template_deployment", props.EnabledForTemplateDeployment) | |||
d.Set("vault_uri", props.VaultURI) | |||
|
|||
if err := d.Set("sku", flattenKeyVaultDataSourceSku(props.Sku)); err != nil { | |||
if err := d.Set("sku_name", flattenKeyVaultDataSourceSku(props.Sku)); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a mistake? there is no property sku_name
in the schema for this resource
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it is not a mistake... the property coming from Azure will still be props.Sku, so I need to read that and then convert it to the new property sku_name
azurerm/data_source_key_vault.go
Outdated
|
||
return []interface{}{result} | ||
func flattenKeyVaultDataSourceSku(sku *keyvault.Sku) string { | ||
return string(sku.Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here,
also we don't need a function to do a simple return string(sku.Name)
, i would have removed this entire function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made it a function just in case there is more that needs to be done in the future, I will go ahead and remove the function.
@@ -221,9 +262,21 @@ func flattenAutomationAccountSku(sku *automation.Sku) []interface{} { | |||
} | |||
|
|||
func expandAutomationAccountSku(d *schema.ResourceData) *automation.Sku { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for backward compatibility when both sku
and sku_name
exist side by side...
@@ -140,6 +158,7 @@ func resourceArmAutomationAccountRead(d *schema.ResourceData, meta interface{}) | |||
} | |||
resGroup := id.ResourceGroup | |||
name := id.Path["automationAccounts"] | |||
skuName := d.Get("sku_name").(string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What you can do is mark both as computed until 2.0 and just set both instead of doing tricky logic like this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would that cause issues when we totally remove sku
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't as at that point we'll only be setting the required one.
@@ -169,8 +188,21 @@ func resourceArmAutomationAccountRead(d *schema.ResourceData, meta interface{}) | |||
d.Set("location", azureRMNormalizeLocation(*location)) | |||
} | |||
|
|||
if err := d.Set("sku", flattenAutomationAccountSku(resp.Sku)); err != nil { | |||
return fmt.Errorf("Error setting `sku`: %+v", err) | |||
if skuName == "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What you can do is mark both as computed until 2.0 and just set both instead of doing tricky logic like this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would that cause issues when we totally remove sku
?
sku { | ||
name = "Free" | ||
} | ||
sku = "Free" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be sku_name
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
sku { | ||
name = "Free" | ||
} | ||
sku = "Free" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be sku_name
?
sku { | ||
name = "premium" | ||
} | ||
sku = "premium" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be sku_name
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
sku { | ||
name = "premium" | ||
} | ||
sku = "premium" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be sku_name
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
sku { | ||
name = "standard" | ||
} | ||
sku = "standard" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be sku_name
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
Co-Authored-By: kt <kt@katbyte.me>
Co-Authored-By: kt <kt@katbyte.me>
Co-Authored-By: kt <kt@katbyte.me>
Co-Authored-By: kt <kt@katbyte.me>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes @jeffreyCline,
In addition to the comments i've left inline could you add these properties to the Upgrading to 2.0 guide deprecations section?
Also whilst running the tests i notices they are all failing with:
Test ended in panic.
------- Stdout: -------
=== RUN TestAccAzureRMKeyVaultKey_basicRSAHSM
=== PAUSE TestAccAzureRMKeyVaultKey_basicRSAHSM
=== CONT TestAccAzureRMKeyVaultKey_basicRSAHSM
------- Stderr: -------
panic: sku: '': source data must be an array or slice, got string
goroutine 254 [running]:
github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform/helper/schema.(*ResourceData).Set(0xc000a57650, 0x3775576, 0x3, 0x322d320, 0x3e02840, 0x0, 0x0)
/opt/teamcity-agent/work/458e5e4800bd94f6/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform/helper/schema/resource_data.go:193 +0x334
github.com/terraform-providers/terraform-provider-azurerm/azurerm.resourceArmKeyVaultRead(0xc000a57650, 0x36a0e20, 0xc0010ba000, 0x0, 0x0)
/opt/teamcity-agent/work/458e5e4800bd94f6/src/github.com/terraform-providers/terraform-provider-azurerm/azurerm/resource_arm_key_vault.go:372 +0xa38
github.com/terraform-providers/terraform-provider-azurerm/azurerm.resourceArmKeyVaultCreateUpdate(0xc000a57650, 0x36a0e20, 0xc0010ba000, 0x0, 0x0)
/opt/teamcity-agent/work/458e5e4800bd94f6/src/github.com/terraform-providers/terraform-provider-azurerm/azurerm/resource_arm_key_vault.go:323 +0xf2f
github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform/helper/schema.(*Resource).Apply(0xc000171700, 0xc000c3c460, 0xc0005e5580, 0x36a0e20, 0xc0010ba000, 0x32dcf01, 0xc001773e98, 0xc001370db0)
/opt/teamcity-agent/work/458e5e4800bd94f6/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform/helper/schema/resource.go:286 +0x363
github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform/helper/schema.(*Provider).Apply(0xc00054b200, 0xc00066fa00, 0xc000c3c460, 0xc0005e5580, 0xc001773f08, 0xc000a1b428, 0x32dfd40)
/opt/teamcity-agent/work/458e5e4800bd94f6/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform/helper/schema/provider.go:285 +0x9c
github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform/helper/plugin.(*GRPCProviderServer).ApplyResourceChange(0xc0000b3b30, 0x3e3dbe0, 0xc001084780, 0xc0007622a0, 0xc0000b3b30, 0xc0010846f0, 0x3342380)
/opt/teamcity-agent/work/458e5e4800bd94f6/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform/helper/plugin/grpc_provider.go:842 +0x87a
github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform/internal/tfplugin5._Provider_ApplyResourceChange_Handler(0x3613640, 0xc0000b3b30, 0x3e3dbe0, 0xc001084780, 0xc000c3c0f0, 0x0, 0x0, 0x0, 0xc0009e1200, 0x463)
/opt/teamcity-agent/work/458e5e4800bd94f6/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/github.com/hashicorp/terraform/internal/tfplugin5/tfplugin5.pb.go:3019 +0x23e
github.com/terraform-providers/terraform-provider-azurerm/vendor/google.golang.org/grpc.(*Server).processUnaryRPC(0xc000e82180, 0x3e5b8e0, 0xc000e82600, 0xc000c9df00, 0xc00109f4d0, 0x6cb14e0, 0x0, 0x0, 0x0)
/opt/teamcity-agent/work/458e5e4800bd94f6/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/google.golang.org/grpc/server.go:966 +0x4a2
github.com/terraform-providers/terraform-provider-azurerm/vendor/google.golang.org/grpc.(*Server).handleStream(0xc000e82180, 0x3e5b8e0, 0xc000e82600, 0xc000c9df00, 0x0)
/opt/teamcity-agent/work/458e5e4800bd94f6/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/google.golang.org/grpc/server.go:1245 +0xd61
github.com/terraform-providers/terraform-provider-azurerm/vendor/google.golang.org/grpc.(*Server).serveStreams.func1.1(0xc000f89a90, 0xc000e82180, 0x3e5b8e0, 0xc000e82600, 0xc000c9df00)
/opt/teamcity-agent/work/458e5e4800bd94f6/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/google.golang.org/grpc/server.go:685 +0x9f
created by github.com/terraform-providers/terraform-provider-azurerm/vendor/google.golang.org/grpc.(*Server).serveStreams.func1
/opt/teamcity-agent/work/458e5e4800bd94f6/src/github.com/terraform-providers/terraform-provider-azurerm/vendor/google.golang.org/grpc/server.go:683 +0xa1
azurerm/data_source_key_vault.go
Outdated
@@ -26,17 +26,9 @@ func dataSourceArmKeyVault() *schema.Resource { | |||
|
|||
"location": azure.SchemaLocationForDataSource(), | |||
|
|||
"sku": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we keep this in untill 2.0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not in the data source, since it is read only... when it writes to the state file it will persist the new attribute instead of the deprecated attribute to be consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However if someone is relying on this property currently it will break them in weird and wonderful ways with no deprecation notice. We should keep it around until 2.0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As about we should be setting both sku
and sku_name
here
@@ -140,6 +158,7 @@ func resourceArmAutomationAccountRead(d *schema.ResourceData, meta interface{}) | |||
} | |||
resGroup := id.ResourceGroup | |||
name := id.Path["automationAccounts"] | |||
skuName := d.Get("sku_name").(string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't as at that point we'll only be setting the required one.
azurerm/resource_arm_key_vault.go
Outdated
Required: true, | ||
Type: schema.TypeString, | ||
Required: true, | ||
DiffSuppressFunc: suppress.CaseDifference, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we changing this to suppress case differences?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has always been the case for sku
... I'm not changing anything as I understand it.
azurerm/resource_arm_key_vault.go
Outdated
ValidateFunc: validation.StringInSlice([]string{ | ||
string(keyvault.Standard), | ||
string(keyvault.Premium), | ||
}, true), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is a new property could we not ignore case here? All enums should be case sensitive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, yup, that was my bad... I missed that one.
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Default: string(automation.Basic), | ||
Required: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we changing this to required instead of leaving it as optional? this will break peoples configurations?
@@ -306,7 +354,7 @@ func TestAccAzureRMKeyVault_justCert(t *testing.T) { | |||
{ | |||
ResourceName: resourceName, | |||
ImportState: true, | |||
ImportStateVerify: true, | |||
ImportStateVerify: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as before
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
DiffSuppressFunc: suppress.CaseDifference, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we changing the case sensitivity here?
), | ||
}, | ||
{ | ||
ResourceName: resourceName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerify: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as above. if they are computed and you are setting both on read they will.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated inline comments
azurerm/data_source_key_vault.go
Outdated
@@ -26,17 +26,9 @@ func dataSourceArmKeyVault() *schema.Resource { | |||
|
|||
"location": azure.SchemaLocationForDataSource(), | |||
|
|||
"sku": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However if someone is relying on this property currently it will break them in weird and wonderful ways with no deprecation notice. We should keep it around until 2.0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes @jeffreyCline,
Just a couple minor comments left to address
azurerm/data_source_key_vault.go
Outdated
@@ -26,17 +26,9 @@ func dataSourceArmKeyVault() *schema.Resource { | |||
|
|||
"location": azure.SchemaLocationForDataSource(), | |||
|
|||
"sku": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As about we should be setting both sku
and sku_name
here
Co-Authored-By: kt <kt@katbyte.me>
Co-Authored-By: kt <kt@katbyte.me>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the revisions @jeffreyCline, aside from the last 2 comments this LGTM
azurerm/data_source_key_vault.go
Outdated
if err := d.Set("sku", flattenKeyVaultDataSourceSku(props.Sku)); err != nil { | ||
return fmt.Errorf("Error setting `sku` for KeyVault %q: %+v", *resp.Name, err) | ||
} | ||
|
||
if err := d.Set("sku_name", string(props.Sku.Name)); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll need to check that props.Sku is not nil here:
if sku := props.Sku; sku != nil {
d.Set("sku_name", sku.Name))
}
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! |
First phase of addressing issue #1500, to flatten the
SKU
block into a single attribute and unifying the handling ofSKU
across all resources within the Azure Terraform provider.Example: