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

azurerm_search_service - add support for local_authentication_enabled, authentication_failure_mode, authentication_options and hosting_mode #21323

Merged
merged 17 commits into from
Apr 26, 2023
Merged
39 changes: 24 additions & 15 deletions internal/services/search/search_service_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package search

import (
"fmt"
"net/http"
"strings"
"time"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/identity"
Expand All @@ -13,6 +16,7 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
"github.com/hashicorp/terraform-provider-azurerm/utils"
)

func dataSourceSearchService() *pluginsdk.Resource {
Expand All @@ -29,7 +33,7 @@ func dataSourceSearchService() *pluginsdk.Resource {
Required: true,
},

"resource_group_name": commonschema.ResourceGroupName(),
"resource_group_name": commonschema.ResourceGroupNameForDataSource(),

"replica_count": {
Type: pluginsdk.TypeInt,
Expand Down Expand Up @@ -102,9 +106,9 @@ func dataSourceSearchServiceRead(d *pluginsdk.ResourceData, meta interface{}) er

if model := resp.Model; model != nil {
if props := model.Properties; props != nil {
partitionCount := 0
replicaCount := 0
publicNetworkAccess := false
partitionCount := 1
replicaCount := 1
publicNetworkAccess := true

if count := props.PartitionCount; count != nil {
partitionCount = int(*count)
Expand All @@ -115,7 +119,7 @@ func dataSourceSearchServiceRead(d *pluginsdk.ResourceData, meta interface{}) er
}

if props.PublicNetworkAccess != nil {
publicNetworkAccess = *props.PublicNetworkAccess != "Disabled"
publicNetworkAccess = strings.EqualFold(string(pointer.From(props.PublicNetworkAccess)), string(services.PublicNetworkAccessEnabled))
}

d.Set("partition_count", partitionCount)
Expand All @@ -128,30 +132,35 @@ func dataSourceSearchServiceRead(d *pluginsdk.ResourceData, meta interface{}) er
}
}

primaryKey := ""
secondaryKey := ""
adminKeysClient := meta.(*clients.Client).Search.AdminKeysClient
adminKeysId, err := adminkeys.ParseSearchServiceID(d.Id())
if err != nil {
return err
}

adminKeysResp, err := adminKeysClient.Get(ctx, *adminKeysId, adminkeys.GetOperationOptions{})
if err == nil {
if model := adminKeysResp.Model; model != nil {
d.Set("primary_key", model.PrimaryKey)
d.Set("secondary_key", model.SecondaryKey)
}
if err != nil && !response.WasStatusCode(adminKeysResp.HttpResponse, http.StatusForbidden) {
return fmt.Errorf("retrieving Admin Keys for %s: %+v", id, err)
}
if model := adminKeysResp.Model; model != nil {
primaryKey = utils.NormalizeNilableString(model.PrimaryKey)
secondaryKey = utils.NormalizeNilableString(model.SecondaryKey)
}
d.Set("primary_key", primaryKey)
d.Set("secondary_key", secondaryKey)

queryKeysClient := meta.(*clients.Client).Search.QueryKeysClient
queryKeysId, err := querykeys.ParseSearchServiceID(d.Id())
if err != nil {
return err
}
queryKeysResp, err := queryKeysClient.ListBySearchService(ctx, *queryKeysId, querykeys.ListBySearchServiceOperationOptions{})
if err == nil {
if model := queryKeysResp.Model; model != nil {
d.Set("query_keys", flattenSearchQueryKeys(*model))
}
if err != nil && !response.WasStatusCode(queryKeysResp.HttpResponse, http.StatusForbidden) {
return fmt.Errorf("retrieving Query Keys for %s: %+v", id, err)
}
if err := d.Set("query_keys", flattenSearchQueryKeys(queryKeysResp.Model)); err != nil {
return fmt.Errorf("setting `query_keys`: %+v", err)
}

return nil
Expand Down
Loading