From 7052d69db52a8f3be4c49b1f3780f7246b880468 Mon Sep 17 00:00:00 2001 From: Alper Rifat Ulucinar Date: Wed, 24 Nov 2021 10:56:13 +0300 Subject: [PATCH] Allow prevent_destroy meta-arg to be overridden per resource - Fixes https://github.com/crossplane-contrib/provider-jet-azure/issues/97 Signed-off-by: Alper Rifat Ulucinar --- pkg/config/resource.go | 6 ++++++ pkg/controller/external.go | 2 +- pkg/terraform/files.go | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/config/resource.go b/pkg/config/resource.go index 5671ebda..38323561 100644 --- a/pkg/config/resource.go +++ b/pkg/config/resource.go @@ -212,6 +212,12 @@ type Resource struct { // databases. UseAsync bool + // AllowDestroy controls whether the `prevent_destroy: true` stanza + // is included in the Terraform configuration for the resource. + // For certain resources like Azure's PostgreSQLConfiguration, + // we would like to allow replacement. + AllowDestroy bool + // ExternalName allows you to specify a custom ExternalName. ExternalName ExternalName diff --git a/pkg/controller/external.go b/pkg/controller/external.go index c1c1c987..3b079e6e 100644 --- a/pkg/controller/external.go +++ b/pkg/controller/external.go @@ -181,7 +181,7 @@ func (e *external) Observe(ctx context.Context, mg xpresource.Managed) (managed. return managed.ExternalObservation{ ResourceExists: true, - ResourceUpToDate: plan.UpToDate, + ResourceUpToDate: plan.UpToDate && plan.Exists, ResourceLateInitialized: lateInitedAnn || lateInitedParams, ConnectionDetails: conn, }, nil diff --git a/pkg/terraform/files.go b/pkg/terraform/files.go index adc020b3..bc737547 100644 --- a/pkg/terraform/files.go +++ b/pkg/terraform/files.go @@ -148,7 +148,7 @@ func (fp *FileProducer) WriteMainTF() error { // If the resource is in a deletion process, we need to remove the deletion // protection. fp.parameters["lifecycle"] = map[string]bool{ - "prevent_destroy": !meta.WasDeleted(fp.Resource), + "prevent_destroy": !meta.WasDeleted(fp.Resource) && !fp.Config.AllowDestroy, } // Note(turkenh): To use third party providers, we need to configure // provider name in required_providers.