Skip to content

Commit

Permalink
azurerm_cognitive_account - Support property `dynamic_throttling_en…
Browse files Browse the repository at this point in the history
…abled` (#19371)
  • Loading branch information
sinbai authored Nov 21, 2022
1 parent af52a21 commit 7857908
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 0 deletions.
14 changes: 14 additions & 0 deletions internal/services/cognitive/cognitive_account_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ func resourceCognitiveAccount() *pluginsdk.Resource {
},
},

"dynamic_throttling_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
},

"fqdns": {
Type: pluginsdk.TypeList,
Optional: true,
Expand Down Expand Up @@ -375,6 +380,7 @@ func resourceCognitiveAccountCreate(d *pluginsdk.ResourceData, meta interface{})
UserOwnedStorage: expandCognitiveAccountStorage(d.Get("storage").([]interface{})),
RestrictOutboundNetworkAccess: utils.Bool(d.Get("outbound_network_access_restricted").(bool)),
DisableLocalAuth: utils.Bool(!d.Get("local_auth_enabled").(bool)),
DynamicThrottlingEnabled: utils.Bool(d.Get("dynamic_throttling_enabled").(bool)),
Encryption: expandCognitiveAccountCustomerManagedKey(d.Get("customer_managed_key").([]interface{})),
},
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
Expand Down Expand Up @@ -459,6 +465,7 @@ func resourceCognitiveAccountUpdate(d *pluginsdk.ResourceData, meta interface{})
UserOwnedStorage: expandCognitiveAccountStorage(d.Get("storage").([]interface{})),
RestrictOutboundNetworkAccess: utils.Bool(d.Get("outbound_network_access_restricted").(bool)),
DisableLocalAuth: utils.Bool(!d.Get("local_auth_enabled").(bool)),
DynamicThrottlingEnabled: utils.Bool(d.Get("dynamic_throttling_enabled").(bool)),
Encryption: expandCognitiveAccountCustomerManagedKey(d.Get("customer_managed_key").([]interface{})),
},
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
Expand Down Expand Up @@ -551,6 +558,13 @@ func resourceCognitiveAccountRead(d *pluginsdk.ResourceData, meta interface{}) e
if err := d.Set("network_acls", flattenCognitiveAccountNetworkAcls(props.NetworkAcls)); err != nil {
return fmt.Errorf("setting `network_acls` for Cognitive Account %q: %+v", id, err)
}

dynamicThrottlingEnabled := false
if props.DynamicThrottlingEnabled != nil {
dynamicThrottlingEnabled = *props.DynamicThrottlingEnabled
}
d.Set("dynamic_throttling_enabled", dynamicThrottlingEnabled)

d.Set("fqdns", utils.FlattenStringSlice(props.AllowedFqdnList))

publicNetworkAccess := true
Expand Down
88 changes: 88 additions & 0 deletions internal/services/cognitive/cognitive_account_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,35 @@ func TestAccCognitiveAccount_basic(t *testing.T) {
})
}

func TestAccCognitiveAccount_dynamicThrottlingEnabled(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_cognitive_account", "test")
r := CognitiveAccountResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.dynamicThrottlingEnabled(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.updateDynamicThrottlingEnabled(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.dynamicThrottlingEnabled(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccCognitiveAccount_speechServices(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_cognitive_account", "test")
r := CognitiveAccountResource{}
Expand Down Expand Up @@ -760,6 +789,65 @@ resource "azurerm_cognitive_account" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func (CognitiveAccountResource) openAI(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 = "OpenAI"
sku_name = "S0"
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func (CognitiveAccountResource) dynamicThrottlingEnabled(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 = "LUIS"
sku_name = "S0"
dynamic_throttling_enabled = true
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func (CognitiveAccountResource) updateDynamicThrottlingEnabled(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 = "LUIS"
sku_name = "S0"
dynamic_throttling_enabled = false
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func (CognitiveAccountResource) metricsAdvisor(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/cognitive_account.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ The following arguments are supported:

* `custom_subdomain_name` - (Required) The subdomain name used for token-based authentication. Changing this forces a new resource to be created.

* `dynamic_throttling_enabled` - (Optional) Whether to enable the dynamic throttling for this Cognitive Service Account. Defaults to `false`.

* `customer_managed_key` (Optional) A `customer_managed_key` block as documented below.

* `fqdns` - (Optional) List of FQDNs allowed for the Cognitive Account.
Expand Down

0 comments on commit 7857908

Please sign in to comment.