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

appconfiguration: refactoring on top of the generated SDK #11959

Merged
merged 5 commits into from
May 26, 2021
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
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ linters-settings:
ignore-words:
- hdinsight
- exportfs
nakedret:
max-func-lines: 40
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import (
"fmt"
"time"

"github.com/hashicorp/go-azure-helpers/response"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/location"

"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/appconfiguration/sdk/configurationstores"

"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/appconfiguration/parse"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/appconfiguration/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/pluginsdk"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func dataSourceAppConfiguration() *pluginsdk.Resource {
Expand Down Expand Up @@ -145,49 +148,47 @@ func dataSourceAppConfiguration() *pluginsdk.Resource {
}

func dataSourceAppConfigurationRead(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).AppConfiguration.AppConfigurationsClient
client := meta.(*clients.Client).AppConfiguration.ConfigurationStoresClient
subscriptionId := meta.(*clients.Client).Account.SubscriptionId
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

name := d.Get("name").(string)
resourceGroup := d.Get("resource_group_name").(string)

resp, err := client.Get(ctx, resourceGroup, name)
id := configurationstores.NewConfigurationStoreID(subscriptionId, resourceGroup, name)
resp, err := client.Get(ctx, id)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("App Configuration %q was not found in Resource Group %q", name, resourceGroup)
if response.WasNotFound(resp.HttpResponse) {
return fmt.Errorf("%s was not found", id)
}

return fmt.Errorf("Error retrieving App Configuration %q (Resource Group %q): %+v", name, resourceGroup, err)
return fmt.Errorf("retrieving %s: %+v", id, err)
}

resultPage, err := client.ListKeys(ctx, resourceGroup, name, "")
resultPage, err := client.ListKeysComplete(ctx, id)
if err != nil {
return fmt.Errorf("Failed to receive access keys for App Configuration %q (Resource Group %q): %+v", name, resourceGroup, err)
return fmt.Errorf("retrieving access keys for %s: %+v", id, err)
}

d.SetId(parse.NewConfigurationStoreID(subscriptionId, resourceGroup, name).ID())
d.SetId(id.ID())

if location := resp.Location; location != nil {
d.Set("location", azure.NormalizeLocation(*location))
}
if model := resp.Model; model != nil {
d.Set("location", location.Normalize(model.Location))
d.Set("sku", model.Sku.Name)

skuName := ""
if resp.Sku != nil && resp.Sku.Name != nil {
skuName = *resp.Sku.Name
}
d.Set("sku", skuName)
if props := model.Properties; props != nil {
d.Set("endpoint", props.Endpoint)
}

if props := resp.ConfigurationStoreProperties; props != nil {
d.Set("endpoint", props.Endpoint)
}
accessKeys := flattenAppConfigurationAccessKeys(resultPage.Items)
d.Set("primary_read_key", accessKeys.primaryReadKey)
d.Set("primary_write_key", accessKeys.primaryWriteKey)
d.Set("secondary_read_key", accessKeys.secondaryReadKey)
d.Set("secondary_write_key", accessKeys.secondaryWriteKey)

accessKeys := flattenAppConfigurationAccessKeys(resultPage.Values())
d.Set("primary_read_key", accessKeys.primaryReadKey)
d.Set("primary_write_key", accessKeys.primaryWriteKey)
d.Set("secondary_read_key", accessKeys.secondaryReadKey)
d.Set("secondary_write_key", accessKeys.secondaryWriteKey)
return tags.FlattenAndSet(d, flattenTags(model.Tags))
}

return tags.FlattenAndSet(d, resp.Tags)
return nil
}
Loading