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
  • Storing the GitHub Personal Access Token
  • Integrate Resourcely CLI into your Plan Hooks
  1. Integrate
  2. CI/CD & Terraform Runners

Spacelift

CI/CD Automation

PreviousScalrNextTerramate

Last updated 3 months ago

You can integrate Resourcely with Spacelift 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 Spacelift, you must perform the following steps:

  • Verifying Prerequisites

  • Storing the Resourcely API Token

  • Storing the Github Personal Access Token

  • Integrate Resourcely CLI into your Plan Hooks

Verify Prerequisites

This document assumes that you have a pre-existing Spacelift account configured. If you do not, you can follow their Getting Started steps here:

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. Spacelift allows you to store these secrets in each stack as an Environment.

  1. In the Spacelift console navigate to the Stack you want to integrate with Resourcely.

  2. Click 'Edit'.

  3. With 'Environment Variable' selected, type RESOURCELY_API_TOKEN as the key.

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

  5. Click "Secret" to save this variable as a secret (this will prevent it from being exposed in stdout).

Storing the GitHub Personal Access Token

Resourcely requires a Classic Personal Access Token with the repo scope.

  1. In the Spacelift console navigate to the Stack you want to integrate with Resourcely.

  2. Click 'Edit'.

  3. With 'Environment Variable' selected, type GH_TOKEN as the key.

  4. Paste the Personal Access Token generated from GitHub as the value.

  5. Click "Secret" to save this variable as a secret (this will prevent it from being exposed in stdout).

Integrate Resourcely CLI into your Plan Hooks

Spacelift allows you to specify Hooks that you can run at different stages of your pipeline. We setup the Resourcely CLI to run after the Plan runs, which allows us to evaluate our guardrails against your planned changes. Use the following steps to setup your Post-Plan flow with Resourcely:

These instructions assume that your Spacelift stack name exactly matches the environment name configured in .resourcely.yaml.

If it does not, you will need to customize how RESOURCELY_EVALUATE_ENVIRONMENTis set in the script below.

  1. In your desired Stack, navigate to Hooks

  2. Click 'Planning'

  3. Navigate to 'After'

  4. Individually paste the following commands:

LATEST_RELEASE_TAG=$(curl -s -I https://github.com/cli/cli/releases/latest | awk -F '/' '/^location/ {print  substr($NF, 1, length($NF)-1)}')
curl -s -L -O https://github.com/cli/cli/releases/download/$LATEST_RELEASE_TAG/gh_${LATEST_RELEASE_TAG#v}_linux_amd64.tar.gz > /dev/null && tar -zxf gh_${LATEST_RELEASE_TAG#v}_linux_amd64.tar.gz && mv gh_${LATEST_RELEASE_TAG#v}_linux_amd64/bin/gh .
export GH_PR_URL=$(./gh api https://api.github.com/repos/$TF_VAR_spacelift_repository/commits/$TF_VAR_spacelift_commit_sha/pulls | jq -r '.[0].html_url')
terraform show -json spacelift.plan > spacelift.json
LATEST_RELEASE_TAG=$(curl -s -I https://github.com/Resourcely-Inc/resourcely-container-registry/releases/latest | awk -F '/' '/^location/ {print  substr($NF, 1, length($NF)-1)}')
curl -s -L -O https://github.com/Resourcely-Inc/resourcely-container-registry/releases/download/$LATEST_RELEASE_TAG/resourcely-cli-${LATEST_RELEASE_TAG}-linux-amd64.tar.gz > /dev/null && tar xvzf resourcely-cli-${LATEST_RELEASE_TAG}-linux-amd64.tar.gz
[ -z "$GH_PR_URL" ] && export RESOURCELY_EVALUATE_DRY_RUN=true || export RESOURCELY_EVALUATE_DRY_RUN=false
export RESOURCELY_EVALUATE_CHANGE_REQUEST_URL=$GH_PR_URL
export RESOURCELY_EVALUATE_CHANGE_REQUEST_SHA=$TF_VAR_spacelift_commit_sha
export RESOURCELY_EVALUATE_CONFIG_ROOT_PATH=$TF_VAR_spacelift_project_root
export RESOURCELY_EVALUATE_ENVIRONMENT=$TF_VAR_spacelift_stack_id
./resourcely-cli evaluate spacelift.json

Now Resourcely should be integrated into your Terraform flow, and we will alert your PRs with any violations to the Guardrails you've configured.

We need a GitHub Personal Access Token in order for Resourcely to map your Pull Request URL when your guardrails are evaluated. For details on how to generate a Personal Access Token, you can view the following docs:

See for more information.

🌌
https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens
https://docs.spacelift.io/getting-started
#advanced-resourcely-cli-usage