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 Add publicNetworkAccess and update api-version to 2020-03-13 #7867

Merged
merged 1 commit into from
Jul 23, 2020
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
2 changes: 1 addition & 1 deletion azurerm/internal/services/search/client/client.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package client

import (
"github.com/Azure/azure-sdk-for-go/services/search/mgmt/2015-08-19/search"
"github.com/Azure/azure-sdk-for-go/services/search/mgmt/2020-03-13/search"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
)

Expand Down
28 changes: 22 additions & 6 deletions azurerm/internal/services/search/resource_arm_search_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"time"

"github.com/Azure/azure-sdk-for-go/services/search/mgmt/2015-08-19/search"
"github.com/Azure/azure-sdk-for-go/services/search/mgmt/2020-03-13/search"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
Expand Down Expand Up @@ -103,6 +103,12 @@ func resourceArmSearchService() *schema.Resource {
},
},

"public_network_access_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},

"tags": tags.Schema(),
},
}
Expand All @@ -117,6 +123,12 @@ func resourceArmSearchServiceCreateUpdate(d *schema.ResourceData, meta interface
location := azure.NormalizeLocation(d.Get("location").(string))
resourceGroup := d.Get("resource_group_name").(string)
skuName := d.Get("sku").(string)

publicNetworkAccess := search.Enabled
if enabled := d.Get("public_network_access_enabled").(bool); !enabled {
publicNetworkAccess = search.Disabled
}

t := d.Get("tags").(map[string]interface{})

if features.ShouldResourcesBeImported() && d.IsNewResource() {
Expand All @@ -137,8 +149,10 @@ func resourceArmSearchServiceCreateUpdate(d *schema.ResourceData, meta interface
Sku: &search.Sku{
Name: search.SkuName(skuName),
},
ServiceProperties: &search.ServiceProperties{},
Tags: tags.Expand(t),
ServiceProperties: &search.ServiceProperties{
PublicNetworkAccess: publicNetworkAccess,
},
Tags: tags.Expand(t),
}

if v, ok := d.GetOk("replica_count"); ok {
Expand Down Expand Up @@ -204,6 +218,8 @@ func resourceArmSearchServiceRead(d *schema.ResourceData, meta interface{}) erro
if count := props.ReplicaCount; count != nil {
d.Set("replica_count", int(*count))
}

d.Set("public_network_access_enabled", props.PublicNetworkAccess != "Disabled")
}

adminKeysClient := meta.(*clients.Client).Search.AdminKeysClient
Expand All @@ -216,7 +232,7 @@ func resourceArmSearchServiceRead(d *schema.ResourceData, meta interface{}) erro
queryKeysClient := meta.(*clients.Client).Search.QueryKeysClient
queryKeysResp, err := queryKeysClient.ListBySearchService(ctx, id.ResourceGroup, id.Name, nil)
if err == nil {
d.Set("query_keys", flattenSearchQueryKeys(queryKeysResp.Value))
d.Set("query_keys", flattenSearchQueryKeys(queryKeysResp.Values()))
}

return tags.FlattenAndSet(d, resp.Tags)
Expand Down Expand Up @@ -245,10 +261,10 @@ func resourceArmSearchServiceDelete(d *schema.ResourceData, meta interface{}) er
return nil
}

func flattenSearchQueryKeys(input *[]search.QueryKey) []interface{} {
func flattenSearchQueryKeys(input []search.QueryKey) []interface{} {
results := make([]interface{}, 0)

for _, v := range *input {
for _, v := range input {
result := make(map[string]interface{})

if v.Name != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func TestAccAzureRMSearchService_complete(t *testing.T) {
resource.TestCheckResourceAttrSet(data.ResourceName, "primary_key"),
resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_key"),
resource.TestCheckResourceAttr(data.ResourceName, "query_keys.#", "1"),
resource.TestCheckResourceAttr(data.ResourceName, "public_network_access_enabled", "false"),
),
},
data.ImportStep(),
Expand All @@ -89,6 +90,7 @@ func TestAccAzureRMSearchService_update(t *testing.T) {
testCheckAzureRMSearchServiceExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "staging"),
resource.TestCheckResourceAttr(data.ResourceName, "public_network_access_enabled", "true"),
),
},
{
Expand All @@ -97,6 +99,7 @@ func TestAccAzureRMSearchService_update(t *testing.T) {
testCheckAzureRMSearchServiceExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"),
resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Production"),
resource.TestCheckResourceAttr(data.ResourceName, "public_network_access_enabled", "false"),
),
},
},
Expand Down Expand Up @@ -220,6 +223,8 @@ resource "azurerm_search_service" "test" {
replica_count = 2
partition_count = 3

public_network_access_enabled = false

tags = {
environment = "Production"
residential = "Area"
Expand Down
Loading