-
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
Changes from 8 commits
ed02bc9
4376934
857900f
f0f0f7d
8e73fe9
d630381
a68fd36
96cf7e3
106e746
2764db9
d15ee4c
907f35e
2bd0c80
699cd49
a2f3528
c9a9fae
f907f33
9781279
c642cdc
465a3ee
c7cb43b
a406b85
4bd21fa
7ac5cef
0c8c18b
962aec1
d5e7a70
c6ebd0f
86bebe7
832d630
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
return fmt.Errorf("Error setting `sku` for KeyVault %q: %+v", *resp.Name, err) | ||
} | ||
|
||
|
@@ -196,12 +196,8 @@ func dataSourceArmKeyVaultRead(d *schema.ResourceData, meta interface{}) error { | |
return nil | ||
} | ||
|
||
func flattenKeyVaultDataSourceSku(sku *keyvault.Sku) []interface{} { | ||
result := map[string]interface{}{ | ||
"name": string(sku.Name), | ||
} | ||
|
||
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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} | ||
|
||
func flattenKeyVaultDataSourceNetworkAcls(input *keyvault.NetworkRuleSet) []interface{} { | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -39,16 +39,18 @@ func resourceArmAutomationAccount() *schema.Resource { | |||||
|
||||||
"resource_group_name": resourceGroupNameSchema(), | ||||||
|
||||||
// Remove in 2.0 | ||||||
"sku": { | ||||||
Type: schema.TypeList, | ||||||
Required: true, | ||||||
MaxItems: 1, | ||||||
Type: schema.TypeList, | ||||||
Optional: true, | ||||||
Deprecated: "This property has been deprecated in favour of the 'sku_name' property and will be removed in version 2.0 of the provider", | ||||||
ConflictsWith: []string{"sku_name"}, | ||||||
MaxItems: 1, | ||||||
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 commentThe 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? |
||||||
DiffSuppressFunc: suppress.CaseDifference, | ||||||
ValidateFunc: validation.StringInSlice([]string{ | ||||||
string(automation.Basic), | ||||||
|
@@ -59,6 +61,17 @@ func resourceArmAutomationAccount() *schema.Resource { | |||||
}, | ||||||
}, | ||||||
|
||||||
"sku_name": { | ||||||
Type: schema.TypeString, | ||||||
Optional: true, | ||||||
DiffSuppressFunc: suppress.CaseDifference, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For new properties we shouldn't be ignoring case without good reason such as a broken API, can we remove this?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure... |
||||||
ConflictsWith: []string{"sku"}, | ||||||
ValidateFunc: validation.StringInSlice([]string{ | ||||||
string(automation.Basic), | ||||||
string(automation.Free), | ||||||
}, true), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}, | ||||||
|
||||||
"tags": tagsSchema(), | ||||||
|
||||||
"dsc_server_endpoint": { | ||||||
|
@@ -81,6 +94,12 @@ func resourceArmAutomationAccountCreateUpdate(d *schema.ResourceData, meta inter | |||||
client := meta.(*ArmClient).automationAccountClient | ||||||
ctx := meta.(*ArmClient).StopContext | ||||||
|
||||||
sku := expandAutomationAccountSku(d) | ||||||
|
||||||
if sku == nil { | ||||||
return fmt.Errorf("either 'sku_name' or 'sku' must be defined in the configuration file") | ||||||
} | ||||||
|
||||||
log.Printf("[INFO] preparing arguments for Automation Account create/update.") | ||||||
|
||||||
name := d.Get("name").(string) | ||||||
|
@@ -101,7 +120,6 @@ func resourceArmAutomationAccountCreateUpdate(d *schema.ResourceData, meta inter | |||||
|
||||||
location := azureRMNormalizeLocation(d.Get("location").(string)) | ||||||
tags := d.Get("tags").(map[string]interface{}) | ||||||
sku := expandAutomationAccountSku(d) | ||||||
|
||||||
parameters := automation.AccountCreateOrUpdateParameters{ | ||||||
AccountCreateOrUpdateProperties: &automation.AccountCreateOrUpdateProperties{ | ||||||
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Would that cause issues when we totally remove There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||||||
|
||||||
resp, err := client.Get(ctx, resGroup, name) | ||||||
if err != nil { | ||||||
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Would that cause issues when we totally remove |
||||||
// Remove in 2.0 | ||||||
if sku := resp.Sku; sku != nil { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This entire thing can then be:
i don't think there is a need for the flatten function anymore There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did remove one of the flatten functions, however I don't think we should be setting both of the values. |
||||||
if err := d.Set("sku", flattenAutomationAccountSku(resp.Sku)); err != nil { | ||||||
return fmt.Errorf("Error setting `sku`: %+v", err) | ||||||
} | ||||||
} | ||||||
d.Set("sku_name", "") | ||||||
} else { | ||||||
if sku := resp.Sku; sku != nil { | ||||||
if err := d.Set("sku_name", flattenAutomationAccountSkuName(resp.Sku)); err != nil { | ||||||
return fmt.Errorf("Error setting `sku_name`: %+v", err) | ||||||
} | ||||||
} | ||||||
d.Set("sku", "") | ||||||
} | ||||||
|
||||||
d.Set("dsc_server_endpoint", keysResp.Endpoint) | ||||||
|
@@ -210,6 +242,15 @@ func resourceArmAutomationAccountDelete(d *schema.ResourceData, meta interface{} | |||||
return nil | ||||||
} | ||||||
|
||||||
func flattenAutomationAccountSkuName(sku *automation.Sku) string { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets remove this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, I did. |
||||||
if sku == nil { | ||||||
return "" | ||||||
} | ||||||
|
||||||
return string(sku.Name) | ||||||
} | ||||||
|
||||||
// Remove in 2.0 | ||||||
func flattenAutomationAccountSku(sku *automation.Sku) []interface{} { | ||||||
if sku == nil { | ||||||
return []interface{}{} | ||||||
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. This is for backward compatibility when both |
||||||
inputs := d.Get("sku").([]interface{}) | ||||||
input := inputs[0].(map[string]interface{}) | ||||||
name := automation.SkuNameEnum(input["name"].(string)) | ||||||
v := d.Get("sku_name").(string) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we move this logic into the main function as we'll remove this in 2.0 and it'll end up being sku = automation.SkuNameEnum(d.Get("sku_name").(string)) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move the logic and removed the function |
||||||
|
||||||
// Remove in 2.0 | ||||||
if v == "" { | ||||||
inputs := d.Get("sku").([]interface{}) | ||||||
|
||||||
if len(inputs) == 0 { | ||||||
return nil | ||||||
} | ||||||
|
||||||
input := inputs[0].(map[string]interface{}) | ||||||
v = input["name"].(string) | ||||||
} | ||||||
|
||||||
name := automation.SkuNameEnum(v) | ||||||
|
||||||
sku := automation.Sku{ | ||||||
Name: 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.
Is this a mistake? there is no property
sku_name
in the schema for this resourceThere 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