Resourcely Documentation
LoginSign Up
  • Get Started
    • 🎱What is Resourcely?
    • 👋Why Resourcely
    • 🏃Quickstart
      • Terraform policies integrated into CI
      • Remediate policy violations in existing infrastructure
      • Templates for generating Terraform
      • Glossary
  • Concepts
    • Foundry
      • Create Blueprints with Foundry
      • Creating Guardrails with Foundry
      • lmport Terraform Modules
    • Guardrails
      • Writing your own Guardrails
      • Editing Guardrails
      • Releasing Guardrails
      • Enabling Inactive Guardrails
      • Guardrails in Action
        • 🐱GitHub Actions
        • 🦊GitLab Pipelines
    • Campaigns
      • Get started with Campaigns
      • Creating Campaigns
      • Remediate Resources
      • Campaign Agent
        • State File Support
          • Amazon Simple Storage Service (S3)
          • Google Cloud Storage (GCS)
          • HCP Terraform
          • Spacelift
        • Running Campaigns with GitHub Actions and a Repo-Hosted State File
        • Running Campaigns Locally
    • Blueprints
      • Authoring Your Own Blueprints
      • Using Built-in Resourcely Blueprints
      • Configuring Global Contexts
      • Deep Linking
    • Resources
      • Provisioning Infrastructure
      • Editing Infrastructure
      • Shopping Cart
      • Config Roots and Environments
    • Other Features and Settings
      • Global Values
      • Global Context
      • Metrics
      • Resourcely-cli
      • Resourcely.yaml
      • VCS Proxy
      • Settings
        • User management
        • Company Information
        • Notification Settings
        • Change Management
          • 🐱Connect to GitHub
          • 🦊Connect to Gitlab
        • Generate API Token
    • ✨Production Setup
      • Single Sign-On (SSO)
        • Auth0
        • AWS Single Sign-On
        • Azure AD
        • Google Workspace
        • JumpCloud
        • Okta
        • Omnissa Workspace ONE (formerly VMware)
        • OneLogin
        • Ping Identity
        • Other SAML / OIDC Providers
      • Source Code Management
        • Page
        • 🐱GitHub
        • 🦊GitLab
        • Atlassian Bitbucket
        • Azure Repos
  • Tutorials and guides
    • Remediation Use Cases
      • Apply tags to resources for automating backups
      • Implement centralized logging
    • Blueprints Use Cases
      • Automate Data Pipeline Creation
      • Encryption for GCP
      • AWS Account Factory
      • Streamline and govern AI
      • IAM Factory
      • Cost optimization for FinOps
      • Guardrails for Terraform Modules
    • Using the Resourcely Terraform Provider
      • Setup Resourcely Provider
      • Blueprints
      • Guardrails
      • Global Context
  • Integrate
    • CI/CD & Terraform Runners
      • Atlantis
      • 🐟AWS CodeBuild
      • Azure Pipelines
      • Buildkite
      • CircleCI
      • CloudBees CI
      • Codefresh
      • Digger
      • Env0
      • 🎏GitHub Actions
        • 🐱Local Plan
          • 🐹AWS with OpenID Connect
        • 🐶Terraform Cloud Integration
      • 🦊GitLab Pipelines
      • Harness
      • 🗻HashiCorp Cloud Platform (formerly Terraform Cloud)
      • Jenkins
      • Octopus Deploy
      • Scalr
      • 🌌Spacelift
      • Terramate
      • 🌎Terrateam
    • Cloud Providers
      • 🌨️Amazon Web Services (AWS)
      • 🤓Google Cloud Platform (GCP)
        • Guardrail Gaunlet at Google Cloud Next 2025
      • 💾Microsoft Azure
      • Alibaba Cloud
      • Huawei Cloud
      • IBM Cloud
      • Oracle Cloud Infrastructure (OCI)
      • Tencent Cloud
      • VMware vSphere
    • Developer Portals
      • Atlassian Compass
      • Backstage
      • Cortex
      • Harness IDP
      • Home grown internal developer portals
      • OpsLevel
      • Port
      • Roadie
    • ITSM
      • Atlassian Jira
      • FreshWorks
      • ServiceNow ITSM
      • ZenDesk
    • CSPM
      • Wiz
    • More Terraform Provider Integrations
      • 🚂ConductorOne Provider
      • Databricks Provider
      • Kubernetes Provider
      • 🐕Datadog Provider
      • ❄️Snowflake Provider
Powered by GitBook
On this page
  • Verify Prerequisites
  • Storing the Resourcely API Token
  • Granting CodeBuild access to the Resourcely API Key
  • Adding the Resourcely command
  1. Integrate
  2. CI/CD & Terraform Runners

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.

  1. In the AWS Console, navigate to AWS Secrets Manager.

  2. Click 'Store a new secret'.

  3. Choose 'Other' for 'Secret type'.

  4. Under 'Key/value pairs', choose any key. Later, this document will assume the key is resourcely-api-key.

  5. Paste the API Token generated from the Resourcely portal as the value.

  1. Click 'Next'.

  2. Name the secret. Later, this document will assume the name of resourcely-cli-secrets.

  3. Click 'Next' until you complete the wizard by clicking Store. Do not configure rotation.

  4. Copy the ARN of your secret for use in the next step.

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

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "CodeBuildReadsResourcelyToken",
            "Effect": "Allow",
            "Action": "secretsmanager:GetSecretValue",
            "Resource": "<the ARN of your secret>"
        }
    ]
}

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.

version: 0.2

env:
  variables:
    # Valid values: github | gitlab
    VCS: github
    
    # Resourcely needs to know the URL of the pull request associated with this
    # CodeBuild build. The source of this data will vary based on how CodeBuild
    # was integrated with your source control.
    #
    # For builds with no associated PR, a blank PR_URL will cause resourcely-cli
    # to do nothing (instead of failing due to an unknown PR).
    PR_URL: "TODO"
    
    # This directory should contain one or more Terraform plan json files when
    # the Resourcely command runs. The command at the bottom of this example
    # assumes this path is relative to the current working directory.
    PLANS_PATH: "TODO"
    
    RESOURCELY_API_HOST: https://api.resourcely.io
    
  secrets-manager:
  
    # If you stored the Resourcely API Key in AWS Secrets Manager, this will
    # make it available in CodeBuild. The string below is made up of the
    # secret name and the 'key' under which you stored the secret value.
    RESOURCELY_API_TOKEN: resourcely-cli-secrets:resourcely-api-key

# The phases below are just examples. You can run the resourcely-cli command
# in any phase, as long as the Terraform plan json is present by the time it
# runs.

phases:
  install:
    on-failure: ABORT
    commands:
      - docker pull ghcr.io/resourcely-inc/resourcely-cli:latest
  build:
    on-failure: ABORT
    commands:
      - docker run --rm \
        -e RESOURCELY_API_HOST=$RESOURCELY_API_HOST \
        -e RESOURCELY_API_TOKEN=$RESOURCELY_API_TOKEN \
        --mount type=bind,src=$(pwd)/$PLANS_PATH,dst=/plans \
        ghcr.io/resourcely-inc/resourcely-cli \
        evaluate \
        --vcs $VCS \
        --change_request_url ${PR_URL:-skip} \
        --change_request_sha $(git rev-parse HEAD) \
        $(ls -1 $PLANS_PATH/* | sed "s|^$PLANS_PATH|/plans|" | tr '\n' ',' | sed 's/,$//')

AWS CodeBuild should now run the Resourcely CLI on every build whenever PR_URL is set.

PreviousAtlantisNextAzure Pipelines

Last updated 1 year ago

See the documentation for more information.

🐟
AWS Secrets Manager