From 43f7a8282328771adbe9b4c855c4d4de8950d035 Mon Sep 17 00:00:00 2001 From: Allan Targino Date: Fri, 29 Nov 2019 16:46:54 -0300 Subject: [PATCH] feature: query keys for azure search --- azurerm/internal/services/search/client.go | 5 +++ azurerm/resource_arm_search_service.go | 41 +++++++++++++++++++++ azurerm/resource_arm_search_service_test.go | 1 + website/docs/r/search_service.html.markdown | 12 ++++++ 4 files changed, 59 insertions(+) diff --git a/azurerm/internal/services/search/client.go b/azurerm/internal/services/search/client.go index 51456406d798b..db43a3a63ad41 100644 --- a/azurerm/internal/services/search/client.go +++ b/azurerm/internal/services/search/client.go @@ -7,6 +7,7 @@ import ( type Client struct { AdminKeysClient *search.AdminKeysClient + QueryKeysClient *search.QueryKeysClient ServicesClient *search.ServicesClient } @@ -14,11 +15,15 @@ func BuildClient(o *common.ClientOptions) *Client { AdminKeysClient := search.NewAdminKeysClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&AdminKeysClient.Client, o.ResourceManagerAuthorizer) + QueryKeysClient := search.NewQueryKeysClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) + o.ConfigureClient(&QueryKeysClient.Client, o.ResourceManagerAuthorizer) + ServicesClient := search.NewServicesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&ServicesClient.Client, o.ResourceManagerAuthorizer) return &Client{ AdminKeysClient: &AdminKeysClient, + QueryKeysClient: &QueryKeysClient, ServicesClient: &ServicesClient, } } diff --git a/azurerm/resource_arm_search_service.go b/azurerm/resource_arm_search_service.go index fff01fff26f5d..8ed695f86a9ee 100644 --- a/azurerm/resource_arm_search_service.go +++ b/azurerm/resource_arm_search_service.go @@ -81,6 +81,24 @@ func resourceArmSearchService() *schema.Resource { Computed: true, }, + "query_keys": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + }, + + "key": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "tags": tags.Schema(), }, } @@ -193,6 +211,12 @@ func resourceArmSearchServiceRead(d *schema.ResourceData, meta interface{}) erro d.Set("secondary_key", adminKeysResp.SecondaryKey) } + queryKeysClient := meta.(*ArmClient).Search.QueryKeysClient + queryKeysResp, err := queryKeysClient.ListBySearchService(ctx, resourceGroup, name, nil) + if err == nil { + d.Set("query_keys", flattenSearchQueryKeys(queryKeysResp.Value)) + } + return tags.FlattenAndSet(d, resp.Tags) } @@ -220,3 +244,20 @@ func resourceArmSearchServiceDelete(d *schema.ResourceData, meta interface{}) er return nil } + +func flattenSearchQueryKeys(input *[]search.QueryKey) []interface{} { + results := make([]interface{}, 0) + + for _, v := range *input { + result := make(map[string]interface{}) + + if v.Name != nil { + result["name"] = *v.Name + } + result["key"] = *v.Key + + results = append(results, result) + } + + return results +} diff --git a/azurerm/resource_arm_search_service_test.go b/azurerm/resource_arm_search_service_test.go index 6a038a2192694..bcbcf16142d30 100644 --- a/azurerm/resource_arm_search_service_test.go +++ b/azurerm/resource_arm_search_service_test.go @@ -82,6 +82,7 @@ func TestAccAzureRMSearchService_complete(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "replica_count", "2"), resource.TestCheckResourceAttrSet(resourceName, "primary_key"), resource.TestCheckResourceAttrSet(resourceName, "secondary_key"), + resource.TestCheckResourceAttr(resourceName, "query_keys.#", "1"), ), }, { diff --git a/website/docs/r/search_service.html.markdown b/website/docs/r/search_service.html.markdown index d94eb7478432f..c6bfe160ee62d 100644 --- a/website/docs/r/search_service.html.markdown +++ b/website/docs/r/search_service.html.markdown @@ -59,6 +59,18 @@ The following attributes are exported: * `secondary_key` - The Search Service Administration secondary key. +* `query_keys` - One or more `query_keys` blocks as defined below. + +--- + +A `query_keys` block supports the following: + +* `name` - The name of the query key. + +* `key` - The value of the query key. + +--- + ## Import Search Services can be imported using the `resource id`, e.g.