From 8d33cf087c4aaf478b925b64b381dc69a62aa9aa Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Wed, 23 Mar 2022 14:49:17 +0100 Subject: [PATCH] appconfig: handling the app configuration being deleted This allows items within the App Configuration to be detected as requiring recreation which fixes #14665 --- .../app_configuration_feature_resource.go | 13 +++++++++++++ .../app_configuration_feature_resource_test.go | 4 ++++ .../app_configuration_key_data_source.go | 3 +++ .../app_configuration_key_resource.go | 13 +++++++++++++ .../app_configuration_key_resource_test.go | 4 ++++ internal/services/appconfiguration/client/client.go | 7 ++++++- 6 files changed, 43 insertions(+), 1 deletion(-) diff --git a/internal/services/appconfiguration/app_configuration_feature_resource.go b/internal/services/appconfiguration/app_configuration_feature_resource.go index 0e43926592ab..3944a697cacf 100644 --- a/internal/services/appconfiguration/app_configuration_feature_resource.go +++ b/internal/services/appconfiguration/app_configuration_feature_resource.go @@ -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 } @@ -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 } @@ -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 } @@ -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 } diff --git a/internal/services/appconfiguration/app_configuration_feature_resource_test.go b/internal/services/appconfiguration/app_configuration_feature_resource_test.go index d4c5699af439..4017f673a192 100644 --- a/internal/services/appconfiguration/app_configuration_feature_resource_test.go +++ b/internal/services/appconfiguration/app_configuration_feature_resource_test.go @@ -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 } diff --git a/internal/services/appconfiguration/app_configuration_key_data_source.go b/internal/services/appconfiguration/app_configuration_key_data_source.go index 1eb3fa6639f9..4c35cd4cf366 100644 --- a/internal/services/appconfiguration/app_configuration_key_data_source.go +++ b/internal/services/appconfiguration/app_configuration_key_data_source.go @@ -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 } diff --git a/internal/services/appconfiguration/app_configuration_key_resource.go b/internal/services/appconfiguration/app_configuration_key_resource.go index a272a9e9804c..00a1139888d4 100644 --- a/internal/services/appconfiguration/app_configuration_key_resource.go +++ b/internal/services/appconfiguration/app_configuration_key_resource.go @@ -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 } @@ -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 } @@ -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 } @@ -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 } diff --git a/internal/services/appconfiguration/app_configuration_key_resource_test.go b/internal/services/appconfiguration/app_configuration_key_resource_test.go index 413bc07f6275..be444f640144 100644 --- a/internal/services/appconfiguration/app_configuration_key_resource_test.go +++ b/internal/services/appconfiguration/app_configuration_key_resource_test.go @@ -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 } diff --git a/internal/services/appconfiguration/client/client.go b/internal/services/appconfiguration/client/client.go index b75b820a0331..1213920e91aa 100644 --- a/internal/services/appconfiguration/client/client.go +++ b/internal/services/appconfiguration/client/client.go @@ -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" @@ -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 }