Skip to content

Commit

Permalink
Merge pull request #20533 from hashicorp/b/app-configuration-data-pla…
Browse files Browse the repository at this point in the history
…ne-regression

appconfiguration: surfacing an error when one exists, rather than misleadingly marking the app configuration as gone
  • Loading branch information
tombuildsstuff authored Feb 17, 2023
2 parents 4e5961d + f791bde commit 7901ebb
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 45 deletions.
2 changes: 1 addition & 1 deletion internal/common/correlation_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func correlationRequestID() string {
if err != nil {
log.Printf("[WARN] Failed to generate uuid for msCorrelationRequestID: %+v", err)
}
log.Printf("[DEBUG] Genereated Provider Correlation Request Id: %s", msCorrelationRequestID)
log.Printf("[DEBUG] Generated Provider Correlation Request Id: %s", msCorrelationRequestID)
})

return msCorrelationRequestID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"time"

"github.com/Azure/go-autorest/autorest"
"github.com/hashicorp/go-azure-sdk/resource-manager/appconfiguration/2022-05-01/configurationstores"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/appconfiguration/parse"
Expand Down Expand Up @@ -48,7 +48,7 @@ func (k FeatureResource) Arguments() map[string]*pluginsdk.Schema {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: azure.ValidateResourceID,
ValidateFunc: configurationstores.ValidateConfigurationStoreID,
},
"description": {
Type: pluginsdk.TypeString,
Expand Down Expand Up @@ -166,12 +166,12 @@ func (k FeatureResource) Create() sdk.ResourceFunc {
}

client, err := metadata.Client.AppConfiguration.DataPlaneClient(ctx, model.ConfigurationStoreId)
if client == nil {
return fmt.Errorf("app configuration %q was not found", model.ConfigurationStoreId)
}
if err != nil {
return err
}
if client == nil {
return fmt.Errorf("app configuration %q was not found", model.ConfigurationStoreId)
}

appCfgFeatureResourceID := parse.AppConfigurationFeatureId{
ConfigurationStoreId: model.ConfigurationStoreId,
Expand Down Expand Up @@ -225,13 +225,13 @@ func (k FeatureResource) Read() sdk.ResourceFunc {
}

client, err := metadata.Client.AppConfiguration.DataPlaneClient(ctx, resourceID.ConfigurationStoreId)
if err != nil {
return err
}
if client == nil {
// if the AppConfiguration is gone then all the data inside it is too
return metadata.MarkAsGone(resourceID)
}
if err != nil {
return err
}

kv, err := client.GetKeyValue(ctx, featureKey, resourceID.Label, "", "", "", []string{})
if err != nil {
Expand Down Expand Up @@ -297,12 +297,12 @@ func (k FeatureResource) Update() sdk.ResourceFunc {
featureKey := fmt.Sprintf("%s/%s", FeatureKeyPrefix, resourceID.Name)

client, err := metadata.Client.AppConfiguration.DataPlaneClient(ctx, resourceID.ConfigurationStoreId)
if client == nil {
return fmt.Errorf("app configuration %q was not found", resourceID.ConfigurationStoreId)
}
if err != nil {
return err
}
if client == nil {
return fmt.Errorf("app configuration %q was not found", resourceID.ConfigurationStoreId)
}

var model FeatureResourceModel
if err := metadata.Decode(&model); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ func (t AppConfigurationFeatureResource) Exists(ctx context.Context, clients *cl
}

client, err := clients.AppConfiguration.DataPlaneClient(ctx, resourceID.ConfigurationStoreId)
if err != nil {
return nil, err
}
if client == nil {
// if the AppConfiguration is gone all the data is too
return utils.Bool(false), nil
}
if err != nil {
return nil, err
}

res, err := client.GetKeyValues(ctx, resourceID.Name, resourceID.Label, "", "", []string{})
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"time"

"github.com/Azure/go-autorest/autorest"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/go-azure-sdk/resource-manager/appconfiguration/2022-05-01/configurationstores"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/appconfiguration/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/tags"
Expand All @@ -26,7 +26,7 @@ func (k KeyDataSource) Arguments() map[string]*pluginsdk.Schema {
"configuration_store_id": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: azure.ValidateResourceID,
ValidateFunc: configurationstores.ValidateConfigurationStoreID,
},
"key": {
Type: pluginsdk.TypeString,
Expand Down Expand Up @@ -100,12 +100,12 @@ func (k KeyDataSource) Read() sdk.ResourceFunc {
}

client, err := metadata.Client.AppConfiguration.DataPlaneClient(ctx, model.ConfigurationStoreId)
if client == nil {
return fmt.Errorf("building data plane client: app configuration %q was not found", model.ConfigurationStoreId)
}
if err != nil {
return err
}
if client == nil {
return fmt.Errorf("building data plane client: app configuration %q was not found", model.ConfigurationStoreId)
}

kv, err := client.GetKeyValue(ctx, decodedKey, model.Label, "", "", "", []string{})
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"time"

"github.com/Azure/go-autorest/autorest"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/go-azure-sdk/resource-manager/appconfiguration/2022-05-01/configurationstores"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/appconfiguration/migration"
Expand Down Expand Up @@ -56,7 +56,7 @@ func (k KeyResource) Arguments() map[string]*pluginsdk.Schema {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: azure.ValidateResourceID,
ValidateFunc: configurationstores.ValidateConfigurationStoreID,
},
"key": {
Type: pluginsdk.TypeString,
Expand Down Expand Up @@ -125,12 +125,12 @@ func (k KeyResource) Create() sdk.ResourceFunc {
}

client, err := metadata.Client.AppConfiguration.DataPlaneClient(ctx, model.ConfigurationStoreId)
if client == nil {
return fmt.Errorf("app configuration %q was not found", model.ConfigurationStoreId)
}
if err != nil {
return err
}
if client == nil {
return fmt.Errorf("app configuration %q was not found", model.ConfigurationStoreId)
}

appCfgKeyResourceID := parse.AppConfigurationKeyId{
ConfigurationStoreId: model.ConfigurationStoreId,
Expand Down Expand Up @@ -208,13 +208,13 @@ func (k KeyResource) Read() sdk.ResourceFunc {
}

client, err := metadata.Client.AppConfiguration.DataPlaneClient(ctx, resourceID.ConfigurationStoreId)
if err != nil {
return err
}
if client == nil {
// if the parent AppConfiguration is gone, all the data will be too
return metadata.MarkAsGone(resourceID)
}
if err != nil {
return err
}

kv, err := client.GetKeyValue(ctx, resourceID.Key, resourceID.Label, "", "", "", []string{})
if err != nil {
Expand Down Expand Up @@ -272,12 +272,12 @@ func (k KeyResource) Update() sdk.ResourceFunc {
}

client, err := metadata.Client.AppConfiguration.DataPlaneClient(ctx, resourceID.ConfigurationStoreId)
if client == nil {
return fmt.Errorf("app configuration %q was not found", resourceID.ConfigurationStoreId)
}
if err != nil {
return err
}
if client == nil {
return fmt.Errorf("app configuration %q was not found", resourceID.ConfigurationStoreId)
}

var model KeyResourceModel
if err := metadata.Decode(&model); err != nil {
Expand Down Expand Up @@ -334,11 +334,12 @@ func (k KeyResource) Delete() sdk.ResourceFunc {
}

client, err := metadata.Client.AppConfiguration.DataPlaneClient(ctx, resourceID.ConfigurationStoreId)
if client == nil {
return fmt.Errorf("app configuration %q was not found", resourceID.ConfigurationStoreId)
}
if err != nil {
return err

}
if client == nil {
return fmt.Errorf("app configuration %q was not found", resourceID.ConfigurationStoreId)
}

decodedKey, err := url.QueryUnescape(resourceID.Key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,13 @@ func (t AppConfigurationKeyResource) Exists(ctx context.Context, clients *client
}

client, err := clients.AppConfiguration.DataPlaneClient(ctx, resourceID.ConfigurationStoreId)
if err != nil {
return nil, err
}
if client == nil {
// if the AppConfiguration is gone all the data will be too
return utils.Bool(false), nil
}
if err != nil {
return nil, err
}

res, err := client.GetKeyValues(ctx, resourceID.Key, resourceID.Label, "", "", []string{})
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"time"

"github.com/Azure/go-autorest/autorest"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/go-azure-sdk/resource-manager/appconfiguration/2022-05-01/configurationstores"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/appconfiguration/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/tags"
Expand Down Expand Up @@ -44,7 +44,7 @@ func (k KeysDataSource) Arguments() map[string]*pluginsdk.Schema {
"configuration_store_id": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: azure.ValidateResourceID,
ValidateFunc: configurationstores.ValidateConfigurationStoreID,
},
"key": {
Type: pluginsdk.TypeString,
Expand Down Expand Up @@ -137,12 +137,12 @@ func (k KeysDataSource) Read() sdk.ResourceFunc {
// whereas the client expects a complete URI to be present and therefore fails to fetch all results if
// store contains more than 100 entries
client, err := metadata.Client.AppConfiguration.LinkWorkaroundDataPlaneClient(ctx, model.ConfigurationStoreId)
if client == nil {
return fmt.Errorf("building data plane client: app configuration %q was not found", model.ConfigurationStoreId)
}
if err != nil {
return err
}
if client == nil {
return fmt.Errorf("building data plane client: app configuration %q was not found", model.ConfigurationStoreId)
}

iter, err := client.GetKeyValuesComplete(ctx, decodedKey, model.Label, "", "", []string{})
if err != nil {
Expand Down
8 changes: 5 additions & 3 deletions internal/services/appconfiguration/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ func (c Client) DataPlaneClient(ctx context.Context, configurationStoreId string
return nil, fmt.Errorf("endpoint was nil")
}

api := environments.NewApiEndpoint("AppConfiguration", *appConfig.Model.Properties.Endpoint, nil)
endpoint := *appConfig.Model.Properties.Endpoint

api := environments.NewApiEndpoint("AppConfiguration", endpoint, nil)
appConfigAuth, err := c.authorizerFunc(api)
if err != nil {
return nil, fmt.Errorf("obtaining auth token for %q: %+v", *appConfig.Model.Properties.Endpoint, err)
return nil, fmt.Errorf("obtaining auth token for %q: %+v", endpoint, err)
}

client := appconfiguration.NewWithoutDefaults("", *appConfig.Model.Properties.Endpoint)
client := appconfiguration.NewWithoutDefaults("", endpoint)
c.configureClientFunc(&client.Client, authWrapper.AutorestAuthorizer(appConfigAuth))

return &client, nil
Expand Down

0 comments on commit 7901ebb

Please sign in to comment.