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

Azure Search: Add primary and secondary keys as exported attributes #2074

Merged
merged 3 commits into from
Oct 15, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 6 additions & 2 deletions azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ import (
"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2017-10-01/storage"
"github.com/Azure/azure-sdk-for-go/services/trafficmanager/mgmt/2017-05-01/trafficmanager"
"github.com/Azure/azure-sdk-for-go/services/web/mgmt/2018-02-01/web"

mainStorage "github.com/Azure/azure-sdk-for-go/storage"
"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/adal"
Expand Down Expand Up @@ -255,7 +254,8 @@ type ArmClient struct {
schedulerJobsClient scheduler.JobsClient

// Search
searchServicesClient search.ServicesClient
searchServicesClient search.ServicesClient
searchAdminKeysClient search.AdminKeysClient

// Security Centre
securityCenterPricingClient security.PricingsClient
Expand Down Expand Up @@ -1030,6 +1030,10 @@ func (c *ArmClient) registerSearchClients(endpoint, subscriptionId string, auth
searchClient := search.NewServicesClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&searchClient.Client, auth)
c.searchServicesClient = searchClient

searchAdminKeysClient := search.NewAdminKeysClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&searchAdminKeysClient.Client, auth)
c.searchAdminKeysClient = searchAdminKeysClient
}

func (c *ArmClient) registerSecurityCenterClients(endpoint, subscriptionId, ascLocation string, auth autorest.Authorizer) {
Expand Down
22 changes: 22 additions & 0 deletions azurerm/resource_arm_search_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ func resourceArmSearchService() *schema.Resource {
},

"tags": tagsForceNewSchema(),
cmpxchg16b marked this conversation as resolved.
Show resolved Hide resolved

"primary_key": {
Type: schema.TypeString,
Computed: true,
},

"secondary_key": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -149,6 +159,18 @@ func resourceArmSearchServiceRead(d *schema.ResourceData, meta interface{}) erro
}
}

adminKeysClient := meta.(*ArmClient).searchAdminKeysClient
adminKeysResp, err := adminKeysClient.Get(ctx, resourceGroup, name, nil)
if err == nil {
if primaryKey := adminKeysResp.PrimaryKey; primaryKey != nil {
d.Set("primary_key", primaryKey)
cmpxchg16b marked this conversation as resolved.
Show resolved Hide resolved
}

if secondaryKey := adminKeysResp.SecondaryKey; secondaryKey != nil {
d.Set("secondary_key", secondaryKey)
}
}

flattenAndSetTags(d, resp.Tags)

return nil
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/search_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ The following attributes are exported:

* `id` - The Search Service ID.

* `primary_key` - The Search Service primary key.

* `secondary_key` - The Search Service secondary key.

## Import

Search Services can be imported using the `resource id`, e.g.
Expand Down