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
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.
Workflow YAML instructions
To upload the Workflow example YAML into your workspace:
Use the Cortex CLI to run this command, using the path to your Workflow YAML file:
cortex workflows create -f <path-to-your-workflow.yaml>
Expand the tiles below to learn about each block in this Workflow and how to configure them in the Cortex UI:
User input
This block prompts the user to confirm that they want to destroy the resource.
Click + in the center of the page. In the block library modal, choose User input.
In the block configuration side panel, enter a name and unique slug for this block.
In this example, we use the name Are you sure and the slug are-you-sure.
Click +Add user input. Add the following:
Name: Are you sure? This will also delete it from the catalog
Key: are-you-sure
Type: Toggle
Default value: This is set to False to prevent accidental deletion.
Click Add input.
Save the block.
Branch
During the previous User input step, if the user selects "Yes" when prompted, the Workflow will branch into a set of blocks to destroy the resource. If the user does not select yes, then the Workflow will not continue.
Click + in the center of the page. In the block library modal, choose Branch.
In the block configuration side panel, enter a name and unique slug for this block.
In this example, we use the name Branch and the slug branch.
The blocks in the path will get the entity descriptor and workspace ID, send an HTTP request to Terraform to destroy the resource, and delete the entity in your Cortex workspace.
Data transformations
Click + under the new path. In the block library modal, choose Data transformation.
In the block configuration side panel, enter a name and unique slug for this block.
In this example, we use the name Get descriptor and the slug get-descriptor.
Enter a jq expression:
.context.entity.descriptor
Save the block.
Click + under the path. In the block library modal, choose Data transformation.
In the block configuration side panel, enter a name and unique slug for this block. In this example, we use the name Get workspace ID and the slug get-workspace-id.