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

Conversation

ulucinar
Copy link
Collaborator

@ulucinar ulucinar commented Nov 24, 2021

Description of your changes

Fixes #158

For certain Terraform resources like Azure's PostgreSQL server configuration, we should not be including the lifecycle.prevent_destroy meta-arg for updates. This PR proposes a backwards-compatible change that allows us to override this behavior. The default behavior stays the same, unless explicitly configured for a resource, we always include (apart from deletions) the prevent_destroy: true meta-argument in the generated configuration.

I have:

  • Read and followed Crossplane's contribution process.
  • Run make reviewable to ensure this PR is ready for review.
  • Added backport release-x.y labels to auto-backport this PR if necessary.

How has this code been tested

Tested using the example manifest of PostgreSQLConfiguration resource of provider-jet-azure on top of crossplane-contrib/provider-jet-azure#98.

Copy link
Member

@muvaf muvaf left a comment

Choose a reason for hiding this comment

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

Copy link
Member

@muvaf muvaf left a comment

Choose a reason for hiding this comment

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

@ulucinar I understand the necessity of this change now. I added a long comment section in the review to make it more clear but while I was writing it, I had some second thoughts because while the use case we have doesn't, the concept itself allows something that is very much against Crossplane conventions (deleting without user consent given we don't have interactive confirmation like TF does before taking action), which could cause developers to use it with not as much caution.

What would you think about excluding these resources (PostgreSQLConfiguration, MySQLConfiguration and possibly MSSQLConfiguration) from Jet Azure and let people use the implementation in provider-azure? I'd like us to see more resources with that exception so that it's worth handling at the top level and take the risk.

@@ -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?

Comment on lines +215 to +219
// 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
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

@muvaf
Copy link
Member

muvaf commented Nov 25, 2021

@ulucinar Another alternative could be to copy the implementation from the native provider. All the structure and flows of Jet providers are just like native implementation, so it should work OK if you'd prefer to have those resources in Jet Azure.

@turkenh
Copy link
Member

turkenh commented Dec 2, 2021

Should we close this one (for now) given the original issue resolved without needing this?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support per-Resource lifecycle.prevent_destroy meta-arg Configuration
3 participants