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

Use getOK to get qna_runtime_endpoint for azurerm_cognitive_account #7916

Merged
merged 4 commits into from
Jul 30, 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
16 changes: 10 additions & 6 deletions azurerm/internal/services/cognitive/cognitive_account_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@ func resourceArmCognitiveAccountCreate(d *schema.ResourceData, meta interface{})
Location: utils.String(azure.NormalizeLocation(d.Get("location").(string))),
Sku: sku,
Properties: &cognitiveservices.AccountProperties{
APIProperties: &cognitiveservices.AccountAPIProperties{
QnaRuntimeEndpoint: utils.String(d.Get("qna_runtime_endpoint").(string)),
},
APIProperties: &cognitiveservices.AccountAPIProperties{},
},
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
}
Expand All @@ -168,6 +166,10 @@ func resourceArmCognitiveAccountCreate(d *schema.ResourceData, meta interface{})
return fmt.Errorf("the QnAMaker runtime endpoint `qna_runtime_endpoint` is required when kind is set to `QnAMaker`")
}

if v, ok := d.GetOk("qna_runtime_endpoint"); ok {
props.Properties.APIProperties.QnaRuntimeEndpoint = utils.String(v.(string))
}

if _, err := client.Create(ctx, resourceGroup, name, props); err != nil {
return fmt.Errorf("Error creating Cognitive Services Account %q (Resource Group %q): %+v", name, resourceGroup, err)
}
Expand Down Expand Up @@ -200,9 +202,7 @@ func resourceArmCognitiveAccountUpdate(d *schema.ResourceData, meta interface{})
props := cognitiveservices.Account{
Sku: sku,
Properties: &cognitiveservices.AccountProperties{
APIProperties: &cognitiveservices.AccountAPIProperties{
QnaRuntimeEndpoint: utils.String(d.Get("qna_runtime_endpoint").(string)),
},
APIProperties: &cognitiveservices.AccountAPIProperties{},
},
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
}
Expand All @@ -211,6 +211,10 @@ func resourceArmCognitiveAccountUpdate(d *schema.ResourceData, meta interface{})
return fmt.Errorf("the QnAMaker runtime endpoint `qna_runtime_endpoint` is required when kind is set to `QnAMaker`")
}

if v, ok := d.GetOk("qna_runtime_endpoint"); ok {
props.Properties.APIProperties.QnaRuntimeEndpoint = utils.String(v.(string))
}

if _, err = client.Update(ctx, id.ResourceGroup, id.Name, props); err != nil {
return fmt.Errorf("Error updating Cognitive Services Account %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,25 @@ func TestAccAzureRMCognitiveAccount_qnaRuntimeEndpoint(t *testing.T) {
})
}

func TestAccAzureRMCognitiveAccount_cognitiveServices(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_cognitiveServices(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMCognitiveAccountExists(data.ResourceName),
),
},
data.ImportStep(),
},
})
}

func testCheckAzureRMAppCognitiveAccountDestroy(s *terraform.State) error {
client := acceptance.AzureProvider.Meta().(*clients.Client).Cognitive.AccountsClient
ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext
Expand Down Expand Up @@ -339,3 +358,24 @@ resource "azurerm_cognitive_account" "test" {
}
`, data.RandomInteger, data.Locations.Ternary, data.RandomInteger, url)
}

func testAccAzureRMCognitiveAccount_cognitiveServices(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-cognitive-%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 = "CognitiveServices"
sku_name = "S0"
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}