Skip to content

Commit

Permalink
azurerm_search_service Add publicNetworkAccess and update api-ver…
Browse files Browse the repository at this point in the history
…sion to `2020-03-13` #7867
  • Loading branch information
lrxtom2 authored Jul 23, 2020
1 parent 3e19061 commit 88699f4
Show file tree
Hide file tree
Showing 16 changed files with 2,395 additions and 583 deletions.
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

0 comments on commit 88699f4

Please sign in to comment.