Skip to content

Commit

Permalink
allow empty tier value for sku like 'DC0'
Browse files Browse the repository at this point in the history
  • Loading branch information
liuwuliuyun committed Jan 17, 2024
1 parent 04e4801 commit 59b6fac
Showing 1 changed file with 6 additions and 31 deletions.
37 changes: 6 additions & 31 deletions internal/services/cognitive/cognitive_account_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,8 @@ func resourceCognitiveAccountCreate(d *pluginsdk.ResourceData, meta interface{})
}
}

sku, err := expandAccountSkuName(d.Get("sku_name").(string))
if err != nil {
return fmt.Errorf("expanding sku_name for %s: %v", id, err)
sku := cognitiveservicesaccounts.Sku{
Name: d.Get("sku_name").(string),
}

networkAcls, subnetIds := expandCognitiveAccountNetworkAcls(d)
Expand Down Expand Up @@ -373,7 +372,7 @@ func resourceCognitiveAccountCreate(d *pluginsdk.ResourceData, meta interface{})
props := cognitiveservicesaccounts.Account{
Kind: utils.String(kind),
Location: utils.String(azure.NormalizeLocation(d.Get("location").(string))),
Sku: sku,
Sku: &sku,
Properties: &cognitiveservicesaccounts.AccountProperties{
ApiProperties: apiProps,
NetworkAcls: networkAcls,
Expand Down Expand Up @@ -425,9 +424,8 @@ func resourceCognitiveAccountUpdate(d *pluginsdk.ResourceData, meta interface{})
return err
}

sku, err := expandAccountSkuName(d.Get("sku_name").(string))
if err != nil {
return fmt.Errorf("expanding sku_name for %s: %+v", *id, err)
sku := cognitiveservicesaccounts.Sku{
Name: d.Get("sku_name").(string),
}

networkAcls, subnetIds := expandCognitiveAccountNetworkAcls(d)
Expand Down Expand Up @@ -458,7 +456,7 @@ func resourceCognitiveAccountUpdate(d *pluginsdk.ResourceData, meta interface{})
}

props := cognitiveservicesaccounts.Account{
Sku: sku,
Sku: &sku,
Properties: &cognitiveservicesaccounts.AccountProperties{
ApiProperties: apiProps,
NetworkAcls: networkAcls,
Expand Down Expand Up @@ -647,29 +645,6 @@ func resourceCognitiveAccountDelete(d *pluginsdk.ResourceData, meta interface{})
return nil
}

func expandAccountSkuName(skuName string) (*cognitiveservicesaccounts.Sku, error) {
var tier cognitiveservicesaccounts.SkuTier
switch skuName[0:1] {
case "F":
tier = cognitiveservicesaccounts.SkuTierFree
case "S":
tier = cognitiveservicesaccounts.SkuTierStandard
case "P":
tier = cognitiveservicesaccounts.SkuTierPremium
case "E":
tier = cognitiveservicesaccounts.SkuTierEnterprise
default:
return &cognitiveservicesaccounts.Sku{
Name: skuName,
}, nil
}

return &cognitiveservicesaccounts.Sku{
Name: skuName,
Tier: &tier,
}, nil
}

func cognitiveAccountStateRefreshFunc(ctx context.Context, client *cognitiveservicesaccounts.CognitiveServicesAccountsClient, id cognitiveservicesaccounts.AccountId) pluginsdk.StateRefreshFunc {
return func() (interface{}, string, error) {
res, err := client.AccountsGet(ctx, id)
Expand Down

0 comments on commit 59b6fac

Please sign in to comment.