In addition to automating the creation of AWS resources, CloudFormation provides a simple method for deleting the resources it created as part of a stack. Using a runbook, you can automate tearing down environments when they’re no longer needed.
Octopus supports the deletion of an existing AWS CloudFormation stack through the Delete an AWS CloudFormation stack step. This step deletes a CloudFormation stack using AWS credentials managed by Octopus.
The proceeding instructions can be followed to configure the Delete an AWS CloudFormation stack step.
Create the runbook
- To create a runbook, navigate to Project ➜ Operations ➜ Runbooks ➜ Add Runbook.
- Give the runbook a name and click SAVE.
- Click DEFINE YOUR RUNBOOK PROCESS, then click ADD STEP.
- Choose the Delete an AWS CloudFormation stack step:
- Fill in the parameters for the step:
|Region||The region your resources are located||us-west-1|
|CloudFormation stack name||Name of existing stack||MySuperStack|
Select the variable that references the Amazon Web Services Account under the AWS Account section or choose to execute using a service role assigned to the EC2 instance. If you don’t have an AWS Account Variable yet, check our documentation on how to create one.
The supplied account can optionally be used to assume a different AWS service role. This can be used to run the AWS commands with a role that limits the services that can be affected.
If you select Yes to Execute using the AWS service role for an EC2 instance, you do not need an AWS account or account variable. Instead the AWS service role for the EC2 instance executing the deployment will be used. See the AWS documentation for more information on service roles.
Under the CloudFormation section, the AWS region and stack name need to be defined.
If the stack does not exist, this step will succeed and not attempt to delete it again.
You can also optionally wait for the stack to be deleted completely before finishing the step by selecting the Wait for completion check-box.
Unselecting the Wait for completion check-box will allow the step to complete once that CloudFormation deletion has been initiated. However unselecting the option means that the step will not fail if the CloudFormation stack deletion fails.
In a single step, you can delete all the resources created within a CloudFormation stack.
We have a Target - PostgreSQL Space on our Samples instance of Octopus. You can sign in as
Guest to take a look at this example and more runbooks in the
Space Infrastructure project.
Help us continuously improve
Please let us know if you have any feedback about this page.
Page updated on Sunday, January 1, 2023