Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Allow prevent_destroy meta-arg to be overridden per resource #159

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/config/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +215 to +219
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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
// AllowRecreation controls whether the changes that require resource
// re-creation, i.e. immutable fields, should be allowed, which is against
// Crossplane Resource Model.
//
// This should be enabled only in cases where there is no point in lifecycle
// of the resource where the API returns NotFound. For example, the
// configurations that Azure PostgreSQLConfiguration resource changes
// have defaults, hence they always exist and when you create a new
// PostgreSQLConfiguration, it's always an importing process of the default
// so the operation would have to be a re-creation since all parameters are
// immutable. Otherwise, controller imports instead of creation since the
// resource exists and ends up in dead-lock state since re-creation is no
// allowed.
//
// For other cases, enabling this is strictly against Crossplane Resource Model
// where the deletion of the external resource is issued if and only if the custom
// resource in Kubernetes API is deleted. Use this parameter with high caution.
AllowRecreation bool


// ExternalName allows you to specify a custom ExternalName.
ExternalName ExternalName

Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/external.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really necessary?

ResourceLateInitialized: lateInitedAnn || lateInitedParams,
ConnectionDetails: conn,
}, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/terraform/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down