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

data_source_key_vault, resource_arm_key_vault, resource_arm_automation_account, resource_arm_notification_hub_namespace, resource_arm_relay_namespace: Flatten SKU #3119

Merged
merged 30 commits into from
Jun 27, 2019

Conversation

WodansSon
Copy link
Collaborator

@WodansSon WodansSon commented Mar 25, 2019

First phase of addressing issue #1500, to flatten the SKU block into a single attribute and unifying the handling of SKU across all resources within the Azure Terraform provider.

Example:

resource "azurerm_automation_account" "test" {
  name     = "automation_account-1"
  sku_name = "Basic"
}

resource "azurerm_key_vault" "test" {
  name     = "key-vault-1"
  sku_name = "premium"
}

resource "azurerm_notification_hub_namespace" "test" {
  name     = "notification-hub-namespace-1"
  sku_name = "Free"
}

resource "azurerm_relay_namespace" "test" {
  name     = "relay-namespace-1"
  sku_name = "Standard"
}

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.

Hi @jeffreyCline,

Thank you for the PR, i've left a number of comments inline that need to be addressed before merging.

@@ -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 {
Copy link
Collaborator

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

Copy link
Collaborator Author

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


return []interface{}{result}
func flattenKeyVaultDataSourceSku(sku *keyvault.Sku) string {
return string(sku.Name)
Copy link
Collaborator

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.

Copy link
Collaborator Author

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 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

and this

Copy link
Collaborator Author

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)
Copy link
Collaborator

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

Copy link
Collaborator Author

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?

Copy link
Collaborator

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 == "" {
Copy link
Collaborator

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

Copy link
Collaborator Author

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"
Copy link
Collaborator

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?

Copy link
Collaborator Author

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"
Copy link
Collaborator

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"
Copy link
Collaborator

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?

Copy link
Collaborator Author

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"
Copy link
Collaborator

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?

Copy link
Collaborator Author

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"
Copy link
Collaborator

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes.

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.

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

@@ -26,17 +26,9 @@ func dataSourceArmKeyVault() *schema.Resource {

"location": azure.SchemaLocationForDataSource(),

"sku": {
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

Copy link
Collaborator

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)
Copy link
Collaborator

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.

Required: true,
Type: schema.TypeString,
Required: true,
DiffSuppressFunc: suppress.CaseDifference,
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

ValidateFunc: validation.StringInSlice([]string{
string(keyvault.Standard),
string(keyvault.Premium),
}, true),
Copy link
Collaborator

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.

Copy link
Collaborator Author

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,
Copy link
Collaborator

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,
Copy link
Collaborator

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,
Copy link
Collaborator

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?

azurerm/resource_arm_notification_hub_namespace_test.go Outdated Show resolved Hide resolved
azurerm/resource_arm_relay_namespace.go Outdated Show resolved Hide resolved
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerify: false,
Copy link
Collaborator

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.

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.

Updated inline comments

@@ -26,17 +26,9 @@ func dataSourceArmKeyVault() *schema.Resource {

"location": azure.SchemaLocationForDataSource(),

"sku": {
Copy link
Collaborator

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.

azurerm/resource_arm_notification_hub_namespace.go Outdated Show resolved Hide resolved
@WodansSon
Copy link
Collaborator Author

image

@katbyte katbyte changed the title Flatten SKU attribute azurerm_postgresql_server, resource_arm_express_route_circuit, resource_arm_cognitive_account, azurerm_app_service_plan: Flatten SKU Jun 27, 2019
@katbyte katbyte modified the milestones: v2.0.0, v1.31.0 Jun 27, 2019
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.

Thanks for the changes @jeffreyCline,

Just a couple minor comments left to address

azurerm/resource_arm_notification_hub_namespace.go Outdated Show resolved Hide resolved
azurerm/resource_arm_relay_namespace.go Outdated Show resolved Hide resolved
@@ -26,17 +26,9 @@ func dataSourceArmKeyVault() *schema.Resource {

"location": azure.SchemaLocationForDataSource(),

"sku": {
Copy link
Collaborator

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

@WodansSon WodansSon changed the title azurerm_postgresql_server, resource_arm_express_route_circuit, resource_arm_cognitive_account, azurerm_app_service_plan: Flatten SKU data_source_key_vault, resource_arm_key_vault, resource_arm_automation_account, resource_arm_notification_hub_namespace, resource_arm_relay_namespace: Flatten SKU Jun 27, 2019
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.

Thanks for the revisions @jeffreyCline, aside from the last 2 comments this LGTM

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 {
Copy link
Collaborator

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))
}

azurerm/resource_arm_notification_hub_namespace_test.go Outdated Show resolved Hide resolved
@katbyte katbyte merged commit 5686e47 into master Jun 27, 2019
@katbyte katbyte deleted the e_flatten_sku branch June 27, 2019 23:59
katbyte added a commit that referenced this pull request Jun 28, 2019
@ghost
Copy link

ghost commented Jul 28, 2019

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 and limited conversation to collaborators Jul 28, 2019
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.

2 participants