vmware / terraform-provider-vra

Terraform Provider for VMware Aria Automation
https://registry.terraform.io/providers/vmware/vra/
Mozilla Public License 2.0
103 stars 90 forks source link

Add support to filter/taint expired deployments to trigger recreation #473

Open azrdev opened 1 year ago

azrdev commented 1 year ago

Code of Conduct

This project has a Code of Conduct that all participants are expected to understand and follow:

Description

Our vRA imposes a lifetime on all deployments, i.e. they expire after 30 days. Afterwards the deployed VMs are powered off and not useable anymore until being deleted some time after. For terraform, however, they still exist "in good state" -- attributes like last_request and lease_expire_at tell it has been expired and allow failing such a VM early using a postcondition, but I'm looking for a way to re-create such expired deployments. Context is a scheduled CI pipeline which runs terraform followed by config management to ensure certain infrastructure (VM + application) is always present. Currently it fails in config management due to the expired VM being powered off, requiring manual destruction of the VM to recreate the setup.

This is a follow-up to #436 since even with it solved in #462 (thank you!) a workaround seems not to be possible (see https://github.com/hashicorp/terraform/issues/31702).

Possible solutions

Adding a parameter to the resource (or provider?) recreate_expired: bool is probably the best way to go

Describe alternatives you've considered

  1. workaround using postcondition with self.last_request.action_id != "Deployment.Expire" -- works, but only fails plan/apply and requires manual action to trigger recreation
  2. replace_triggered_by: cannot be applied to self, see linked terraform issue above
  3. replace_triggered_bydata "vra_resource" { (same ID as the resource) } (full example see linked tf issue above): data source fails when resource not yet exists

References

Community Note

azrdev commented 8 months ago

I'm trying to implement a fix for this one:

azrdev commented 8 months ago

So given what I've tried above, I see two solutions:

  1. implement the third bulletpoint d.SetId("") (maybe behind a boolean user-input flag): an expired vra_deployment already in tfstate is planned to be created but there's no reference that the old deployment is removed. plan output:

    attribute (TODO: implement flag) recreate_if_expired = false recreate_if_expired = true
    is expired nothing create (expired deployment is ignored)
    is not expired nothing nothing
  2. merge my PR #514 which will yield these plans:

    attribute recreate_if_expired_at = null recreate_if_expired_at = plantimestamp()
    is expired nothing destroy+create
    is not expired nothing diff on the attribute in every plan