🐟AWS CodeBuild
CI/CD Automation
You can integrate Resourcely with AWS CodeBuild to automatically evaluate your Terraform plans and policies on every pull request, and provide feedback directly within your pull/merge request. To set up Resourcely with AWS CodeBuild, you must perform the following steps:
Verifying Prerequisites
Storing the Resourcely API key
Granting CodeBuild access to the Resourcely API Key
Adding the Resourcely command
Verify Prerequisites
This document assumes that you have a pre-existing AWS CodeBuild project configured. Before adding Resourcely to your build logic, please verify your build environment:
Your worker instances have Internet egress (e.g. through a NAT Gateway).
Your worker instances run in privileged mode.
Privileged mode is required for a CodeBuild worker to use Docker. Please contact us if you can't run your worker using privileged mode.
Storing the Resourcely API Token
The Resourcely CLI needs access to a Resourcely API key at build time so it can report findings in your Terraform plans. There are many ways to securely store secrets and make them available in AWS CodeBuild. This document uses AWS Secrets Manager as an example.
In the AWS Console, navigate to AWS Secrets Manager.
Click 'Store a new secret'.
Choose 'Other' for 'Secret type'.
Under 'Key/value pairs', choose any key. Later, this document will assume the key is
resourcely-api-key
.Paste the API Token generated from the Resourcely portal as the value.
Click 'Next'.
Name the secret. Later, this document will assume the name of
resourcely-cli-secrets
.Click 'Next' until you complete the wizard by clicking
Store
. Do not configure rotation.Copy the ARN of your secret for use in the next step.
See the AWS Secrets Manager documentation for more information.
Granting CodeBuild access to the Resourcely API Key
CodeBuild needs AWS IAM permissions to be able to read the Resourcely API Token. If you stored the token in AWS Secrets Manager, attach a policy like the one below to your CodeBuild Project's role. The role of ARN can be found in the project's Environment settings.
If you do not use AWS Secrets Manager, the policy details will differ
We recommend using a new policy rather than updating an existing policy. Adding a statement to an existing CodeBuild policy, that is managed by CodeBuild will disable the automated management.
Adding the Resourcely command
Now we can add a resourcely-cli
command to your buildspec.yml
. It evaluates your Terraform plan(s) by downloading policies from Resourcely, assessing them, and submitting the results to Resourcely. These findings will be displayed on the pull request associated with this build.
Here is an example buildspec.yml
with commentary.
AWS CodeBuild should now run the Resourcely CLI on every build whenever PR_URL is set.
Last updated