Skip to content

Commit

Permalink
feature: query keys for azure search
Browse files Browse the repository at this point in the history
  • Loading branch information
allantargino committed Nov 29, 2019
1 parent 4a8ab56 commit 43f7a82
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.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 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,
}
}
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` - 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.
Expand Down

0 comments on commit 43f7a82

Please sign in to comment.