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

2.0-cognitive #5797

Merged
merged 1 commit into from
Feb 18, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -91,45 +91,13 @@ func resourceArmCognitiveAccount() *schema.Resource {
},

"sku_name": {
Type: schema.TypeString,
Optional: true, // required in 2.0
Computed: true, // remove in 2.0
ConflictsWith: []string{"sku"},
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
"F0", "F1", "S0", "S1", "S2", "S3", "S4", "S5", "S6", "P0", "P1", "P2",
}, false),
},

"sku": {
Type: schema.TypeList,
Optional: true,
Computed: true,
ConflictsWith: []string{"sku_name"},
Deprecated: "This property has been deprecated in favour of the 'sku_name' property and will be removed in version 2.0 of the provider",
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
"F0", "F1", "S0", "S1", "S2", "S3", "S4", "S5", "S6", "P0", "P1", "P2",
}, false),
},

"tier": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
string(cognitiveservices.Free),
string(cognitiveservices.Standard),
string(cognitiveservices.Premium),
}, false),
},
},
},
},

"tags": tags.Schema(),

"endpoint": {
Expand Down Expand Up @@ -173,17 +141,9 @@ func resourceArmCognitiveAccountCreate(d *schema.ResourceData, meta interface{})
}
}

var sku *cognitiveservices.Sku
if b, ok := d.GetOk("sku_name"); ok {
var err error
sku, err = expandAccountSkuName(b.(string))
if err != nil {
return fmt.Errorf("error expanding sku_name for Cognitive Account %s (Resource Group %q): %v", name, resourceGroup, err)
}
} else if _, ok := d.GetOk("sku"); ok {
sku = expandCognitiveAccountSku(d)
} else {
return fmt.Errorf("One of `sku` or `sku_name` must be set for Cognitive Account %q (Resource Group %q)", name, resourceGroup)
sku, err := expandAccountSkuName(d.Get("sku_name").(string))
if err != nil {
return fmt.Errorf("error expanding sku_name for Cognitive Account %s (Resource Group %q): %v", name, resourceGroup, err)
}

properties := cognitiveservices.Account{
Expand Down Expand Up @@ -218,17 +178,9 @@ func resourceArmCognitiveAccountUpdate(d *schema.ResourceData, meta interface{})
return err
}

var sku *cognitiveservices.Sku
if b, ok := d.GetOk("sku_name"); ok {
var err error
sku, err = expandAccountSkuName(b.(string))
if err != nil {
return fmt.Errorf("error expanding sku_name for Cognitive Account %s (Resource Group %q): %v", id.Name, id.ResourceGroup, err)
}
} else if _, ok := d.GetOk("sku"); ok {
sku = expandCognitiveAccountSku(d)
} else {
return fmt.Errorf("One of `sku` or `sku_name` must be set for Cognitive Account %q (Resource Group %q)", id.Name, id.ResourceGroup)
sku, err := expandAccountSkuName(d.Get("sku_name").(string))
if err != nil {
return fmt.Errorf("error expanding sku_name for Cognitive Account %s (Resource Group %q): %v", id.Name, id.ResourceGroup, err)
}

properties := cognitiveservices.Account{
Expand Down Expand Up @@ -276,10 +228,6 @@ func resourceArmCognitiveAccountRead(d *schema.ResourceData, meta interface{}) e
d.Set("sku_name", sku.Name)
}

if err = d.Set("sku", flattenCognitiveAccountSku(resp.Sku)); err != nil {
return fmt.Errorf("Error setting `sku`: %+v", err)
}

if props := resp.Properties; props != nil {
d.Set("endpoint", props.Endpoint)
}
Expand Down Expand Up @@ -339,29 +287,3 @@ func expandAccountSkuName(skuName string) (*cognitiveservices.Sku, error) {
Tier: tier,
}, nil
}

func expandCognitiveAccountSku(d *schema.ResourceData) *cognitiveservices.Sku {
skus := d.Get("sku").([]interface{})
sku := skus[0].(map[string]interface{})

return &cognitiveservices.Sku{
Name: utils.String(sku["name"].(string)),
Tier: cognitiveservices.SkuTier(sku["tier"].(string)),
}
}

func flattenCognitiveAccountSku(input *cognitiveservices.Sku) []interface{} {
if input == nil {
return []interface{}{}
}

m := map[string]interface{}{
"tier": string(input.Tier),
}

if v := input.Name; v != nil {
m["name"] = *v
}

return []interface{}{m}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,6 @@ func TestAccAzureRMCognitiveAccount_basic(t *testing.T) {
})
}

func TestAccAzureRMCognitiveAccount_basicOldSku(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_cognitive_account", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMAppCognitiveAccountDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMCognitiveAccount_basicOldSku(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMCognitiveAccountExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "kind", "Face"),
resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"),
resource.TestCheckResourceAttrSet(data.ResourceName, "primary_access_key"),
resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_access_key"),
),
},
data.ImportStep(),
},
})
}

func TestAccAzureRMCognitiveAccount_speechServices(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_cognitive_account", "test")

Expand Down Expand Up @@ -241,27 +218,6 @@ resource "azurerm_cognitive_account" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func testAccAzureRMCognitiveAccount_basicOldSku(data acceptance.TestData) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}

resource "azurerm_cognitive_account" "test" {
name = "acctestcogacc-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
kind = "Face"

sku {
name = "S0"
tier = "Standard"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func testAccAzureRMCognitiveAccount_speechServices(data acceptance.TestData) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down