From e58c111226cb272f3fc90f0f5a3b16e93a5974c0 Mon Sep 17 00:00:00 2001 From: Evgenii Gostiukhin Date: Sun, 14 Oct 2018 00:41:54 +0200 Subject: [PATCH 1/3] add primary and secondary keys for azure search resource --- azurerm/config.go | 8 ++++++-- azurerm/resource_arm_search_service.go | 22 +++++++++++++++++++++ website/docs/r/search_service.html.markdown | 4 ++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/azurerm/config.go b/azurerm/config.go index f4414a901a14..5c7ddf5718c5 100644 --- a/azurerm/config.go +++ b/azurerm/config.go @@ -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" @@ -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 @@ -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) { diff --git a/azurerm/resource_arm_search_service.go b/azurerm/resource_arm_search_service.go index a0cfeca09c91..079b8322c1eb 100644 --- a/azurerm/resource_arm_search_service.go +++ b/azurerm/resource_arm_search_service.go @@ -59,6 +59,16 @@ func resourceArmSearchService() *schema.Resource { }, "tags": tagsForceNewSchema(), + + "primary_key": { + Type: schema.TypeString, + Computed: true, + }, + + "secondary_key": { + Type: schema.TypeString, + Computed: true, + }, }, } } @@ -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) + } + + if secondaryKey := adminKeysResp.SecondaryKey; secondaryKey != nil { + d.Set("secondary_key", secondaryKey) + } + } + flattenAndSetTags(d, resp.Tags) return nil diff --git a/website/docs/r/search_service.html.markdown b/website/docs/r/search_service.html.markdown index 220e57b94cef..ee99401091e2 100644 --- a/website/docs/r/search_service.html.markdown +++ b/website/docs/r/search_service.html.markdown @@ -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. From 46ae187b4920f9ab162f82274da72d7c789c92e6 Mon Sep 17 00:00:00 2001 From: Evgenii Gostiukhin Date: Mon, 15 Oct 2018 22:00:12 +0200 Subject: [PATCH 2/3] drops nil checks, moves tags to last position in schema, adds tests for attributes --- azurerm/resource_arm_search_service.go | 13 ++++--------- azurerm/resource_arm_search_service_test.go | 2 ++ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/azurerm/resource_arm_search_service.go b/azurerm/resource_arm_search_service.go index 079b8322c1eb..f126da36aa14 100644 --- a/azurerm/resource_arm_search_service.go +++ b/azurerm/resource_arm_search_service.go @@ -58,8 +58,6 @@ func resourceArmSearchService() *schema.Resource { ForceNew: true, }, - "tags": tagsForceNewSchema(), - "primary_key": { Type: schema.TypeString, Computed: true, @@ -69,6 +67,8 @@ func resourceArmSearchService() *schema.Resource { Type: schema.TypeString, Computed: true, }, + + "tags": tagsForceNewSchema(), }, } } @@ -162,13 +162,8 @@ 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) - } - - if secondaryKey := adminKeysResp.SecondaryKey; secondaryKey != nil { - d.Set("secondary_key", secondaryKey) - } + d.Set("primary_key", adminKeysResp.PrimaryKey) + d.Set("secondary_key", adminKeysResp.SecondaryKey) } flattenAndSetTags(d, resp.Tags) diff --git a/azurerm/resource_arm_search_service_test.go b/azurerm/resource_arm_search_service_test.go index ae72f3811be6..90ce36881370 100644 --- a/azurerm/resource_arm_search_service_test.go +++ b/azurerm/resource_arm_search_service_test.go @@ -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"), ), }, }, From 362ef22cacc29adc939393dfa04258c5da133920 Mon Sep 17 00:00:00 2001 From: kt Date: Mon, 15 Oct 2018 13:14:34 -0700 Subject: [PATCH 3/3] Updated docs to reflect they are admin keys --- website/docs/r/search_service.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website/docs/r/search_service.html.markdown b/website/docs/r/search_service.html.markdown index ee99401091e2..ae5ec2830f16 100644 --- a/website/docs/r/search_service.html.markdown +++ b/website/docs/r/search_service.html.markdown @@ -54,9 +54,9 @@ The following attributes are exported: * `id` - The Search Service ID. -* `primary_key` - The Search Service primary key. +* `primary_key` - The Search Service Administration primary key. -* `secondary_key` - The Search Service secondary key. +* `secondary_key` - The Search Service Administration secondary key. ## Import