Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

A GitHub Action that creates an apply or destroy run in a Terraform Cloud workspace

License

Notifications You must be signed in to change notification settings

hashicorp-forge/terraform-cloud-run-action

terraform-cloud-run-action

⚠️ IMPORTANT

This repo has been archived. New features and bug fixes will be added to hashicorp-forge/terraform-cloud-action, which contains several Terraform Cloud actions that are better organized and easier to maintain.

Overview

A GitHub Action that creates an apply or destroy run in a Terraform Cloud workspace. Use this in conjunction with hashicorp-forge/terraform-cloud-outputs-action to assemble GitHub Action pipelines using infrastructure managed by Terraform Cloud.

Inputs

  • token (Required): Terraform Cloud API access token
  • organization (Required): The organization
  • workspace (Required): The name of the workspace
  • hostname (Optional): The hostname (if not using Terraform Cloud) of the Terraform Enterprise instance. Defaults to app.terraform.io
  • wait (Optional): If set, waits for the run to terminate and resources to be processed before the action finishes. Defaults to true.
  • auto-apply (Optional): If set, applies changes when a Terraform plan is successful. Defaults to true.
  • is-destroy (Optional): If set, a destroy plan will be run. Defaults to false.
  • message (Optional): A custom message to associate with the run. Default to "Run created by GitHub action"
  • replace-addrs (Optional): Multi-line list of resource addresses to be replaced. Use one address per line.
  • target-addrs (Optional): Multi-line list of resource addresses that Terraform should focus its planning efforts on. Use one address per line.

Read more about the Runs API

Outputs

  • run-id: The run ID for the created run.

Example Usage

You can use this action in conjunction with hashicorp-forge/terraform-cloud-outputs-action to create infrastructure and fetch new outputs to help utilize it:

name: Nightly Test
on:
  workflow_dispatch:
  schedule:
    - cron: 0 0 * * *

jobs:
  infra:
    runs-on: ubuntu-latest
    steps:
      - name: Create infra
        id: fetch
        uses: hashicorp-forge/terraform-cloud-run-action@v1
        with:
          token: ${{ secrets.TFC_TOKEN }}
          organization: example-org
          workspace: my-workspace
          wait: true

  tests:
    runs-on: ubuntu-latest
    needs: [infra]
    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Fetch infra secrets
        id: fetch
        uses: hashicorp-forge/terraform-cloud-outputs-action@v1
        with:
          token: ${{ secrets.TFC_TOKEN }}
          organization: example-org
          workspace: my-workspace

      - name: Tests
        run: go test ./...
        env:
          SOME_FOO: ${{ fromJSON(steps.fetch.outputs.workspace-outputs-json).foo }}
          SOME_BAR: ${{ fromJSON(steps.fetch.outputs.workspace-outputs-json).bar }}

  cleanup:
    runs-on: ubuntu-latest
    needs: [tests]
    if: "${{ always() }}"
    steps:
      - name: Destroy infra
        uses: hashicorp-forge/terraform-cloud-run-action@v1
        with:
          token: ${{ secrets.TFC_TOKEN }}
          organization: example-org
          workspace: my-workspace
          is-destroy: true
          wait: true

About

A GitHub Action that creates an apply or destroy run in a Terraform Cloud workspace

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published