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_search_service allows configuration of network_rule_bypass_option #28139

Merged
merged 5 commits into from
Dec 6, 2024
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
24 changes: 24 additions & 0 deletions internal/services/search/search_service_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@ func resourceSearchService() *pluginsdk.Resource {
},
},

"network_rule_bypass_option": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
string(services.SearchBypassAzureServices),
string(services.SearchBypassNone),
}, false),
Default: string(services.SearchBypassNone),
},

"identity": commonschema.SystemAssignedUserAssignedIdentityOptional(),

"tags": commonschema.Tags(),
Expand Down Expand Up @@ -223,6 +233,7 @@ func resourceSearchServiceCreate(d *pluginsdk.ResourceData, meta interface{}) er
cmkEnforcementEnabled := d.Get("customer_managed_key_enforcement_enabled").(bool)
localAuthenticationEnabled := d.Get("local_authentication_enabled").(bool)
authenticationFailureMode := d.Get("authentication_failure_mode").(string)
networkRuleBypassOptions := services.SearchBypass(d.Get("network_rule_bypass_option").(string))

semanticSearchSku := services.SearchSemanticSearchDisabled
if v := d.Get("semantic_search_sku").(string); v != "" {
Expand Down Expand Up @@ -302,6 +313,7 @@ func resourceSearchServiceCreate(d *pluginsdk.ResourceData, meta interface{}) er
PublicNetworkAccess: pointer.To(publicNetworkAccess),
NetworkRuleSet: pointer.To(services.NetworkRuleSet{
IPRules: expandSearchServiceIPRules(ipRulesRaw),
Bypass: pointer.To(networkRuleBypassOptions),
}),
EncryptionWithCmk: pointer.To(services.EncryptionWithCmk{
Enforcement: pointer.To(cmkEnforcement),
Expand Down Expand Up @@ -484,6 +496,14 @@ func resourceSearchServiceUpdate(d *pluginsdk.ResourceData, meta interface{}) er
}
}

if d.HasChange("network_rule_bypass_option") {
networkBypassOptions := services.SearchBypass(d.Get("network_rule_bypass_option").(string))
if model.Properties.NetworkRuleSet == nil {
model.Properties.NetworkRuleSet = &services.NetworkRuleSet{}
}
model.Properties.NetworkRuleSet.Bypass = pointer.To(networkBypassOptions)
}

if d.HasChange("semantic_search_sku") {
semanticSearchSku := services.SearchSemanticSearchDisabled
if v := d.Get("semantic_search_sku").(string); v != "" {
Expand Down Expand Up @@ -604,6 +624,10 @@ func resourceSearchServiceRead(d *pluginsdk.ResourceData, meta interface{}) erro
d.Set("customer_managed_key_enforcement_enabled", cmkEnforcement)
d.Set("allowed_ips", flattenSearchServiceIPRules(props.NetworkRuleSet))
d.Set("semantic_search_sku", semanticSearchSku)

if props.NetworkRuleSet != nil {
d.Set("network_rule_bypass_option", string(pointer.From(props.NetworkRuleSet.Bypass)))
}
}

flattenedIdentity, err := identity.FlattenSystemAndUserAssignedMap(model.Identity)
Expand Down
48 changes: 48 additions & 0 deletions internal/services/search/search_service_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,35 @@ func TestAccSearchService_ipRules(t *testing.T) {
})
}

func TestAccSearchService_bypassServices(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_search_service", "test")
r := SearchServiceResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data, "standard"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.bypassServices(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.basic(data, "standard"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccSearchService_identity(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_search_service", "test")
r := SearchServiceResource{}
Expand Down Expand Up @@ -699,6 +728,25 @@ resource "azurerm_search_service" "test" {
`, template, data.RandomInteger)
}

func (r SearchServiceResource) bypassServices(data acceptance.TestData) string {
template := r.template(data)
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

%s

resource "azurerm_search_service" "test" {
name = "acctestsearchservice%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
sku = "standard"
network_rule_bypass_option = "AzureServices"
}
`, template, data.RandomInteger)
}

func (r SearchServiceResource) identity(data acceptance.TestData) string {
template := r.template(data)
return fmt.Sprintf(`
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/search_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ The following arguments are supported:

* `local_authentication_enabled` - (Optional) Specifies whether the Search Service allows authenticating using API Keys? Defaults to `true`.

* `network_rule_bypass_option` - (Optional) Whether to allow trusted Azure services to access a network restricted Container Registry? Possible values are `None` and `AzureServices`. Defaults to `None`.

* `partition_count` - (Optional) Specifies the number of partitions which should be created. This field cannot be set when using a `free` sku ([see the Microsoft documentation](https://learn.microsoft.com/azure/search/search-sku-tier)). Possible values include `1`, `2`, `3`, `4`, `6`, or `12`. Defaults to `1`.

-> **NOTE:** when `hosting_mode` is set to `highDensity` the maximum number of partitions allowed is `3`.
Expand Down
Loading