Terraform destroy
Using a Workflow, you can streamline the process of dismantling infrastructure that was previously provisioned and managed by a Terraform configuration. This Workflow will also remove the resource entity from your Cortex workspace.
How to use a Workflow in Cortex to destroy a resource with Terraform
Prerequisite
Before getting started, you should have already followed the guide to Provision an EC2 instance with Terraform.
Considerations
This Workflow makes HTTP calls to Terraform Cloud, but it is possible to call other Terraform orchestrators, such as Spacelift.
The Terraform orchestrator you use must have an API call to perform the destroy.
Step 1: Start creating the Workflow
Follow the steps in the documentation to create a Workflow and configure its basic settings.
In the Workflow's basic settings, set its scope to apply to the entity type AWS::EC2::Instance
and the group terraform
. The prerequisite Workflow Provision an EC2 instance with Terraform automatically adds the group to the entities it creates.
Step 2: Add blocks to the Workflow
The instructions on this page describe how to create this Workflow in the Cortex UI, but it is also possible to copy the Workflow YAML and add it to your workspace via the Cortex CLI. This allows you to quickly set up the example configuration then iterate on it for your own use case. Expand the tile below to learn more.
Expand the tiles below to learn about each block in this Workflow and how to configure them in the Cortex UI:
Step 3: Run the Workflow
When you run the Workflow, the following events happen:
The User input step prompts the user to confirm that they want to delete a resource.
If the user confirms during the first block, then the branch block runs.
The Workflow obtains the entity descriptor, then uses that information to obtain the related workspace ID.
The HTTP request triggers a destroy in Terraform.
The "Delete entity" step uses the entity descriptor obtained in the previous steps to determine which entity to delete.
Last updated
Was this helpful?