Skip to content

Commit

Permalink
azurerm_cognitive_account - `custom_question_answering_search_servi…
Browse files Browse the repository at this point in the history
…ce_key` (#17683)
  • Loading branch information
ms-henglu authored Jul 28, 2022
1 parent 11cc0d9 commit 748e446
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 deletions.
13 changes: 13 additions & 0 deletions internal/services/cognitive/cognitive_account_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,12 @@ func resourceCognitiveAccount() *pluginsdk.Resource {
ValidateFunc: search.ValidateSearchServiceID,
},

"custom_question_answering_search_service_key": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"storage": {
Type: pluginsdk.TypeList,
Optional: true,
Expand Down Expand Up @@ -698,6 +704,13 @@ func expandCognitiveAccountAPIProperties(d *pluginsdk.ResourceData) (*cognitives
return nil, fmt.Errorf("the Search Service ID `custom_question_answering_search_service_id` can only be set when kind is set to `TextAnalytics`")
}
}
if v, ok := d.GetOk("custom_question_answering_search_service_key"); ok {
if kind == "TextAnalytics" {
props.QnaAzureSearchEndpointKey = utils.String(v.(string))
} else {
return nil, fmt.Errorf("the Search Service Key `custom_question_answering_search_service_key` can only be set when kind is set to `TextAnalytics`")
}
}
if v, ok := d.GetOk("metrics_advisor_aad_client_id"); ok {
if kind == "MetricsAdvisor" {
props.AadClientId = utils.String(v.(string))
Expand Down
38 changes: 20 additions & 18 deletions internal/services/cognitive/cognitive_account_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,21 +193,21 @@ func TestAccCognitiveAccount_customQuestionAnsweringSearchServiceId(t *testing.T
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
data.ImportStep("custom_question_answering_search_service_key"),
{
Config: r.customQuestionAnsweringSearchServiceIdUpdated(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
data.ImportStep("custom_question_answering_search_service_key"),
{
Config: r.customQuestionAnsweringSearchServiceIdRemoved(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
data.ImportStep("custom_question_answering_search_service_key"),
})
}

Expand Down Expand Up @@ -639,14 +639,15 @@ resource "azurerm_search_service" "test" {
}
resource "azurerm_cognitive_account" "test" {
name = "acctestcogacc-%[1]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
kind = "TextAnalytics"
sku_name = "F0"
custom_question_answering_search_service_id = azurerm_search_service.test.id
name = "acctestcogacc-%[1]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
kind = "TextAnalytics"
sku_name = "F0"
custom_question_answering_search_service_id = azurerm_search_service.test.id
custom_question_answering_search_service_key = azurerm_search_service.test.primary_key
}
`, data.RandomInteger, data.Locations.Primary)
`, data.RandomInteger, "West US")
}

func (CognitiveAccountResource) customQuestionAnsweringSearchServiceIdUpdated(data acceptance.TestData) string {
Expand Down Expand Up @@ -675,14 +676,15 @@ resource "azurerm_search_service" "test2" {
}
resource "azurerm_cognitive_account" "test" {
name = "acctestcogacc-%[1]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
kind = "TextAnalytics"
sku_name = "F0"
custom_question_answering_search_service_id = azurerm_search_service.test2.id
name = "acctestcogacc-%[1]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
kind = "TextAnalytics"
sku_name = "F0"
custom_question_answering_search_service_id = azurerm_search_service.test2.id
custom_question_answering_search_service_key = azurerm_search_service.test2.primary_key
}
`, data.RandomInteger, data.Locations.Primary)
`, data.RandomInteger, "West US")
}

func (CognitiveAccountResource) customQuestionAnsweringSearchServiceIdRemoved(data acceptance.TestData) string {
Expand Down Expand Up @@ -717,7 +719,7 @@ resource "azurerm_cognitive_account" "test" {
kind = "TextAnalytics"
sku_name = "F0"
}
`, data.RandomInteger, data.Locations.Primary)
`, data.RandomInteger, "West US")
}

func (CognitiveAccountResource) cognitiveServices(data acceptance.TestData) string {
Expand Down
4 changes: 3 additions & 1 deletion website/docs/r/cognitive_account.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ The following arguments are supported:

* `custom_question_answering_search_service_id` - If `kind` is `TextAnalytics` this specifies the ID of the Search service.

-> **NOTE:** `custom_question_answering_search_service_id` is used for [Custom Question Answering, the renamed version of QnA Maker](https://docs.microsoft.com/azure/cognitive-services/qnamaker/custom-question-answering), while `qna_runtime_endpoint` is used for [the old version of QnA Maker](https://docs.microsoft.com/azure/cognitive-services/qnamaker/overview/overview)
* `custom_question_answering_search_service_key` - If `kind` is `TextAnalytics` this specifies the key of the Search service.

-> **NOTE:** `custom_question_answering_search_service_id` and `custom_question_answering_search_service_key` are used for [Custom Question Answering, the renamed version of QnA Maker](https://docs.microsoft.com/azure/cognitive-services/qnamaker/custom-question-answering), while `qna_runtime_endpoint` is used for [the old version of QnA Maker](https://docs.microsoft.com/azure/cognitive-services/qnamaker/overview/overview)

* `storage` - (Optional) A `storage` block as defined below.

Expand Down

0 comments on commit 748e446

Please sign in to comment.