Skip to content

Commit

Permalink
Merge pull request #5029 from allantargino/search-service-query-keys
Browse files Browse the repository at this point in the history
feature: query keys for azure search
  • Loading branch information
tombuildsstuff committed Dec 17, 2019
2 parents 59c3b86 + 49f6766 commit ba3c352
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
5 changes: 5 additions & 0 deletions azurerm/internal/services/search/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,23 @@ import (

type Client struct {
AdminKeysClient *search.AdminKeysClient
QueryKeysClient *search.QueryKeysClient
ServicesClient *search.ServicesClient
}

func NewClient(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,
}
}
41 changes: 41 additions & 0 deletions azurerm/resource_arm_search_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
}
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
}
1 change: 1 addition & 0 deletions azurerm/resource_arm_search_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
{
Expand Down
12 changes: 12 additions & 0 deletions website/docs/r/search_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ The following attributes are exported:

* `secondary_key` - The Search Service Administration secondary key.

* `query_keys` - A `query_keys` block as defined below.

---

A `query_keys` block exports 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.
Expand Down

0 comments on commit ba3c352

Please sign in to comment.