Skip to content

Feature Request: Support when = "destroy" for aap_job #137

@akli-ime

Description

@akli-ime

Description:
Currently, the AAP provider supports launching jobs using the aap_job resource, for example:

resource "aap_job" "sample_bar" {
  job_template_id = 7
  inventory_id    = aap_inventory.my_inventory.id
  extra_vars      = jsonencode(yamldecode(local.values_extra_vars))

}

However, there is no way to configure a job to run only on destroy.
This is important for teardown workflows where you need to call an AAP job template to remove infrastructure or clean up environments.

Proposed Solution:
Add a when argument to the aap_job resource.

Example (proposed syntax):

resource "aap_job" "sample_destroy" {
  job_template_id = 12
  inventory_id    = aap_inventory.my_inventory.id
  extra_vars      = jsonencode(yamldecode(local.destroy_extra_vars))

  when = "destroy"
}

Behavior:

when = "apply" (default): job launches on apply (current behavior).
when = "destroy": job launches only when the resource is being destroyed.

Benefits:

  • Enables clean teardown workflows directly in Terraform.
  • Keeps syntax consistent without introducing a separate aap_destroy_job resource.

There is strong precedent:
The [hashicorp/terraform-provider-http#558] proposal introduced a similar when argument to control whether HTTP requests run during apply or destroy. Aligning with this approach makes provider behavior more predictable and familiar for Terraform users.

Thank you in advance for considering this feature!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions