Terraform Cloud Run Task Integration
Terraform Cloud is a managed service by HashiCorp that makes it easy to run Terraform in production. With the beta release of run tasks for Terraform Cloud, we are able to easily integrate into the workflow of a Terraform deployment by executing webhooks after the plan stage but before the apply stage. The run tasks can be set to either advisory or mandatory to show informational errors or fail the pipeline, respectively.
Run Tasks in Kion
We have two run tasks available:
- Savings Opportunities. Shows the monthly forecast on a project as well as the available cost savings opportunities.
- Compliance. Shows the number of compliance findings on a project, and will throw an error if there are any critical findings.
EC2 Instance Deployment
To start using run tasks, set up an EC2 instance in the account where you have Kion installed.
The account you use here must have an elastic IP and a key pair allocated to it.
To deploy an EC2 instance in your account:
- Login to the AWS console where Kion is installed.
- Navigate to the AWS CloudFormation service.
- Click Create stack.
- Upload the AWS CloudFormation template from the GitHub repository. It's called ec2-deploy.yaml and is located in the AWS CloudFormation folder.
- Fill in the parameters on the stack details page.
- Walk through the rest of the wizard, and then click Create stack.
Once it is deployed, ensure the EC2 instance is publicly accessible to Terraform Cloud and can send a webhook to your Kion application.
Terraform Cloud Setup
To add run tasks to your Terraform workspace:
- Login to the Terraform Cloud console: https://app.terraform.io/
- In your organization, click Settings > Run Tasks.
- Click the Create run task button.
In the form, edit the following fields:
- Name. Enter a friendly name.
- Hook endpoint URL. Paste in the elastic IP allocated
to your account and append to the URL either:
- /savings Append this for the savings opportunities webhook.
- /compliance Append this for the compliance webhook.
- HMAC key. Leave this field blank.
- Click Save run task.
- Navigate to the workspace where you want to add the run tasks.
- Click Settings > Run Tasks.
- Click the plus button next to the run task.
- Under the Environment Variables section, click Variables > Add variable.
- Add a variable named KION_PROJECT.
- Add the ID of the Kion project that the workspace will modify.
- Click Save variable.
That's it! You can push changes to your workspace and the run tasks will start.