Skip to content

Commit 3cf09ce

Browse files
author
Neil Ye
authored
Use getOK to get qna_runtime_endpoint for azurerm_cognitive_account (#7916)
fixes #6343
1 parent cf597b2 commit 3cf09ce

File tree

2 files changed

+50
-6
lines changed

2 files changed

+50
-6
lines changed

azurerm/internal/services/cognitive/cognitive_account_resource.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,7 @@ func resourceArmCognitiveAccountCreate(d *schema.ResourceData, meta interface{})
157157
Location: utils.String(azure.NormalizeLocation(d.Get("location").(string))),
158158
Sku: sku,
159159
Properties: &cognitiveservices.AccountProperties{
160-
APIProperties: &cognitiveservices.AccountAPIProperties{
161-
QnaRuntimeEndpoint: utils.String(d.Get("qna_runtime_endpoint").(string)),
162-
},
160+
APIProperties: &cognitiveservices.AccountAPIProperties{},
163161
},
164162
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
165163
}
@@ -168,6 +166,10 @@ func resourceArmCognitiveAccountCreate(d *schema.ResourceData, meta interface{})
168166
return fmt.Errorf("the QnAMaker runtime endpoint `qna_runtime_endpoint` is required when kind is set to `QnAMaker`")
169167
}
170168

169+
if v, ok := d.GetOk("qna_runtime_endpoint"); ok {
170+
props.Properties.APIProperties.QnaRuntimeEndpoint = utils.String(v.(string))
171+
}
172+
171173
if _, err := client.Create(ctx, resourceGroup, name, props); err != nil {
172174
return fmt.Errorf("Error creating Cognitive Services Account %q (Resource Group %q): %+v", name, resourceGroup, err)
173175
}
@@ -200,9 +202,7 @@ func resourceArmCognitiveAccountUpdate(d *schema.ResourceData, meta interface{})
200202
props := cognitiveservices.Account{
201203
Sku: sku,
202204
Properties: &cognitiveservices.AccountProperties{
203-
APIProperties: &cognitiveservices.AccountAPIProperties{
204-
QnaRuntimeEndpoint: utils.String(d.Get("qna_runtime_endpoint").(string)),
205-
},
205+
APIProperties: &cognitiveservices.AccountAPIProperties{},
206206
},
207207
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
208208
}
@@ -211,6 +211,10 @@ func resourceArmCognitiveAccountUpdate(d *schema.ResourceData, meta interface{})
211211
return fmt.Errorf("the QnAMaker runtime endpoint `qna_runtime_endpoint` is required when kind is set to `QnAMaker`")
212212
}
213213

214+
if v, ok := d.GetOk("qna_runtime_endpoint"); ok {
215+
props.Properties.APIProperties.QnaRuntimeEndpoint = utils.String(v.(string))
216+
}
217+
214218
if _, err = client.Update(ctx, id.ResourceGroup, id.Name, props); err != nil {
215219
return fmt.Errorf("Error updating Cognitive Services Account %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
216220
}

azurerm/internal/services/cognitive/tests/cognitive_account_resource_test.go

+40
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,25 @@ func TestAccAzureRMCognitiveAccount_qnaRuntimeEndpoint(t *testing.T) {
174174
})
175175
}
176176

177+
func TestAccAzureRMCognitiveAccount_cognitiveServices(t *testing.T) {
178+
data := acceptance.BuildTestData(t, "azurerm_cognitive_account", "test")
179+
180+
resource.ParallelTest(t, resource.TestCase{
181+
PreCheck: func() { acceptance.PreCheck(t) },
182+
Providers: acceptance.SupportedProviders,
183+
CheckDestroy: testCheckAzureRMAppCognitiveAccountDestroy,
184+
Steps: []resource.TestStep{
185+
{
186+
Config: testAccAzureRMCognitiveAccount_cognitiveServices(data),
187+
Check: resource.ComposeTestCheckFunc(
188+
testCheckAzureRMCognitiveAccountExists(data.ResourceName),
189+
),
190+
},
191+
data.ImportStep(),
192+
},
193+
})
194+
}
195+
177196
func testCheckAzureRMAppCognitiveAccountDestroy(s *terraform.State) error {
178197
client := acceptance.AzureProvider.Meta().(*clients.Client).Cognitive.AccountsClient
179198
ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext
@@ -339,3 +358,24 @@ resource "azurerm_cognitive_account" "test" {
339358
}
340359
`, data.RandomInteger, data.Locations.Ternary, data.RandomInteger, url)
341360
}
361+
362+
func testAccAzureRMCognitiveAccount_cognitiveServices(data acceptance.TestData) string {
363+
return fmt.Sprintf(`
364+
provider "azurerm" {
365+
features {}
366+
}
367+
368+
resource "azurerm_resource_group" "test" {
369+
name = "acctestRG-cognitive-%d"
370+
location = "%s"
371+
}
372+
373+
resource "azurerm_cognitive_account" "test" {
374+
name = "acctestcogacc-%d"
375+
location = azurerm_resource_group.test.location
376+
resource_group_name = azurerm_resource_group.test.name
377+
kind = "CognitiveServices"
378+
sku_name = "S0"
379+
}
380+
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
381+
}

0 commit comments

Comments
 (0)