Skip to content

Commit

Permalink
appconfig: handling the app configuration being deleted
Browse files Browse the repository at this point in the history
This allows items within the App Configuration to be detected as requiring recreation
which fixes #14665
  • Loading branch information
tombuildsstuff committed Mar 23, 2022
1 parent e83fc1e commit 8d33cf0
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ 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
}
Expand Down Expand Up @@ -222,6 +225,10 @@ func (k FeatureResource) Read() sdk.ResourceFunc {
}

client, err := metadata.Client.AppConfiguration.DataPlaneClient(ctx, resourceID.ConfigurationStoreId)
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
}
Expand Down Expand Up @@ -290,6 +297,9 @@ 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
}
Expand Down Expand Up @@ -327,6 +337,9 @@ func (k FeatureResource) 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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ func (t AppConfigurationFeatureResource) Exists(ctx context.Context, clients *cl
}

client, err := clients.AppConfiguration.DataPlaneClient(ctx, resourceID.ConfigurationStoreId)
if client == nil {
// if the AppConfiguration is gone all the data is too
return utils.Bool(false), nil
}
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ 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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ 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
}
Expand Down Expand Up @@ -202,6 +205,10 @@ func (k KeyResource) Read() sdk.ResourceFunc {
}

client, err := metadata.Client.AppConfiguration.DataPlaneClient(ctx, resourceID.ConfigurationStoreId)
if client == nil {
// if the parent AppConfiguration is gone, all the data will be too
return metadata.MarkAsGone(resourceID)
}
if err != nil {
return err
}
Expand Down Expand Up @@ -267,6 +274,9 @@ 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
}
Expand Down Expand Up @@ -326,6 +336,9 @@ 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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ func (t AppConfigurationKeyResource) Exists(ctx context.Context, clients *client
}

client, err := clients.AppConfiguration.DataPlaneClient(ctx, resourceID.ConfigurationStoreId)
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
}
Expand Down
7 changes: 6 additions & 1 deletion internal/services/appconfiguration/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"

"github.com/hashicorp/go-azure-helpers/lang/response"

"github.com/Azure/go-autorest/autorest"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/appconfiguration/sdk/1.0/appconfiguration"
Expand All @@ -25,7 +27,10 @@ func (c Client) DataPlaneClient(ctx context.Context, configurationStoreId string
// TODO: caching all of this
appConfig, err := c.ConfigurationStoresClient.Get(ctx, *appConfigId)
if err != nil {
// TODO: if not found etc
if response.WasNotFound(appConfig.HttpResponse) {
return nil, nil
}

return nil, err
}

Expand Down

0 comments on commit 8d33cf0

Please sign in to comment.