Skip to content

Commit

Permalink
Merge pull request #11959 from terraform-providers/f/appconfig-sdk
Browse files Browse the repository at this point in the history
appconfiguration: refactoring on top of the generated SDK
  • Loading branch information
tombuildsstuff authored May 26, 2021
2 parents df7d7c7 + 7ef3501 commit 8c99f61
Show file tree
Hide file tree
Showing 38 changed files with 1,273 additions and 366 deletions.
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

0 comments on commit 8c99f61

Please sign in to comment.