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 all commits
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
17 changes: 17 additions & 0 deletions azurerm/resource_arm_search_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ func resourceArmSearchService() *schema.Resource {
ForceNew: true,
},

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

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

"tags": tagsForceNewSchema(),
},
}
Expand Down Expand Up @@ -149,6 +159,13 @@ func resourceArmSearchServiceRead(d *schema.ResourceData, meta interface{}) erro
}
}

adminKeysClient := meta.(*ArmClient).searchAdminKeysClient
adminKeysResp, err := adminKeysClient.Get(ctx, resourceGroup, name, nil)
if err == nil {
d.Set("primary_key", adminKeysResp.PrimaryKey)
d.Set("secondary_key", adminKeysResp.SecondaryKey)
}

flattenAndSetTags(d, resp.Tags)

return nil
Expand Down
2 changes: 2 additions & 0 deletions azurerm/resource_arm_search_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ func TestAccAzureRMSearchService_complete(t *testing.T) {
testCheckAzureRMSearchServiceExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(resourceName, "replica_count", "2"),
resource.TestCheckResourceAttrSet(resourceName, "primary_key"),
resource.TestCheckResourceAttrSet(resourceName, "secondary_key"),
),
},
},
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 Administration primary key.

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

## Import

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