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

azurerm_cognitive_account - Support new property bypass in network_acls block #28331

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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 @@ -9,6 +9,7 @@ import (
"log"
"time"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonids"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
Expand Down Expand Up @@ -209,6 +210,13 @@ func resourceCognitiveAccount() *pluginsdk.Resource {
string(cognitiveservicesaccounts.NetworkRuleActionDeny),
}, false),
},

"bypass": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice(cognitiveservicesaccounts.PossibleValuesForByPassSelection(), false),
},

"ip_rules": {
Type: pluginsdk.TypeSet,
Optional: true,
Expand Down Expand Up @@ -671,6 +679,7 @@ func expandCognitiveAccountNetworkAcls(d *pluginsdk.ResourceData) (*cognitiveser

v := input[0].(map[string]interface{})

bypass := cognitiveservicesaccounts.ByPassSelection(v["bypass"].(string))
defaultAction := cognitiveservicesaccounts.NetworkRuleAction(v["default_action"].(string))

ipRulesRaw := v["ip_rules"].(*pluginsdk.Set)
Expand All @@ -697,6 +706,7 @@ func expandCognitiveAccountNetworkAcls(d *pluginsdk.ResourceData) (*cognitiveser
}

ruleSet := cognitiveservicesaccounts.NetworkRuleSet{
Bypass: &bypass,
DefaultAction: &defaultAction,
IPRules: &ipRules,
VirtualNetworkRules: &networkRules,
Expand Down Expand Up @@ -779,6 +789,8 @@ func flattenCognitiveAccountNetworkAcls(input *cognitiveservicesaccounts.Network
return []interface{}{}
}

bypass := string(pointer.From(input.Bypass))

ipRules := make([]interface{}, 0)
if input.IPRules != nil {
for _, v := range *input.IPRules {
Expand All @@ -803,6 +815,7 @@ func flattenCognitiveAccountNetworkAcls(input *cognitiveservicesaccounts.Network
}

return []interface{}{map[string]interface{}{
"bypass": bypass,
"default_action": input.DefaultAction,
"ip_rules": pluginsdk.NewSet(pluginsdk.HashString, ipRules),
"virtual_network_rules": virtualNetworkRules,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -889,12 +889,13 @@ resource "azurerm_cognitive_account" "test" {
name = "acctestcogacc-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
kind = "Face"
kind = "OpenAI"
sku_name = "S0"
custom_subdomain_name = "acctestcogacc-%d"

network_acls {
default_action = "Deny"
bypass = "None"
virtual_network_rules {
subnet_id = azurerm_subnet.test_a.id
}
Expand All @@ -913,12 +914,13 @@ resource "azurerm_cognitive_account" "test" {
name = "acctestcogacc-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
kind = "Face"
kind = "OpenAI"
sku_name = "S0"
custom_subdomain_name = "acctestcogacc-%d"

network_acls {
default_action = "Allow"
bypass = "AzureServices"
ip_rules = ["123.0.0.101"]
virtual_network_rules {
subnet_id = azurerm_subnet.test_a.id
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 @@ -100,6 +100,8 @@ A `network_acls` block supports the following:

* `default_action` - (Required) The Default Action to use when no rules match from `ip_rules` / `virtual_network_rules`. Possible values are `Allow` and `Deny`.

* `bypass` - (Optional) Specifies the bypass rule for Azure services. Possible values are `AzureServices` and `None`. Defaults to `AzureServices`.

* `ip_rules` - (Optional) One or more IP Addresses, or CIDR Blocks which should be able to access the Cognitive Account.

* `virtual_network_rules` - (Optional) A `virtual_network_rules` block as defined below.
Expand Down
Loading