Skip to content

GitHub Actions Configuration

The github section configures the generated GitHub Actions workflow. This section is used when the resolved provider is github (auto-detected from the GITHUB_ACTIONS environment variable, or set via the TERRACI_PROVIDER environment variable). When the provider is gitlab, this section is omitted and the gitlab section is used instead. See GitLab CI Configuration for the GitLab equivalent.

Options

Execution settings

binary, init_enabled, parallelism, and Terraform job env live under the top-level execution: section, not under extensions.github. Plan jobs are derived from apply intent and resource requests such as plan.json consumers.

runs_on

Type: stringDefault: "ubuntu-latest"

The GitHub Actions runner label for jobs.

yaml
extensions:
  github:
    runs_on: "ubuntu-latest"
    # runs_on: "self-hosted"

container

Type: object (optional) Default: none

Optionally run jobs inside a container. Supports both string and object format.

yaml
extensions:
  github:
    container:
      name: "hashicorp/terraform:1.6"
      entrypoint: [""]

env

Type: map[string]stringDefault: {}

Workflow-level environment variables.

yaml
extensions:
  github:
    env:
      TF_IN_AUTOMATION: "true"
      TF_INPUT: "false"
      AWS_DEFAULT_REGION: "us-east-1"

Use terraci generate --plan-only for read-only workflows. There is no provider-level plan toggle.

permissions

Type: map[string]stringDefault: {}

Workflow-level permissions. Required for PR comments and OIDC authentication.

yaml
extensions:
  github:
    permissions:
      contents: read
      pull-requests: write
      id-token: write        # Required for OIDC

job_defaults

Type: objectDefault: null

Default settings applied to all generated jobs (both plan and apply). These are applied before overwrites.

Available fields:

  • runs_on - Override runner label for all jobs
  • container - Container image for all jobs
  • env - Additional environment variables
  • if - Job condition
  • environment - GitHub Actions environment
  • steps_before - Extra steps to run before terraform commands
  • steps_after - Extra steps to run after terraform commands

Example: Common setup steps for all jobs

yaml
extensions:
  github:
    job_defaults:
      steps_before:
        - uses: actions/checkout@v4
        - uses: hashicorp/setup-terraform@v3
        - name: Configure AWS credentials
          uses: aws-actions/configure-aws-credentials@v4
          with:
            role-to-assume: arn:aws:iam::123456789012:role/terraform
            aws-region: us-east-1
      steps_after:
        - name: Upload logs
          run: echo "Job completed"

Each step in steps_before / steps_after supports:

  • name - Step display name
  • uses - GitHub Action reference (e.g., actions/checkout@v4)
  • with - Action inputs as key-value pairs
  • run - Shell command to run
  • env - Step-level environment variables

overwrites

Type: arrayDefault: []

Job-level overrides for plan or apply jobs. Applied after job_defaults.

Each overwrite has:

  • type - Which jobs to override: plan, apply, or an exact contributed job name
  • runs_on - Override runner label
  • container - Override container image
  • env - Override/add environment variables
  • if - Job condition
  • environment - GitHub Actions environment
  • steps_before - Override steps before terraform commands
  • steps_after - Override steps after terraform commands

Example: Different runners for plan and apply

yaml
extensions:
  github:
    overwrites:
      - type: plan
        runs_on: ubuntu-latest

      - type: apply
        runs_on: self-hosted
        environment: production
        env:
          DEPLOY_ENV: "production"

Example: Extra steps for apply jobs

yaml
extensions:
  github:
    overwrites:
      - type: apply
        steps_before:
          - uses: actions/checkout@v4
          - uses: hashicorp/setup-terraform@v3
          - name: Approve deployment
            run: echo "Deploying..."

Full Example

yaml
execution:
  binary: terraform
  init_enabled: true

extensions:
  github:
    runs_on: "ubuntu-latest"

    # Workflow-level environment variables
    env:
      TF_IN_AUTOMATION: "true"
      TF_INPUT: "false"

    # Permissions (required for PR comments and OIDC)
    permissions:
      contents: read
      pull-requests: write
      id-token: write

    # Job defaults (applied to all jobs)
    job_defaults:
      steps_before:
        - uses: actions/checkout@v4
        - uses: hashicorp/setup-terraform@v3
        - name: Configure AWS credentials
          uses: aws-actions/configure-aws-credentials@v4
          with:
            role-to-assume: arn:aws:iam::123456789012:role/terraform
            aws-region: us-east-1

    # Job overwrites (override job_defaults for specific job types)
    overwrites:
      - type: apply
        runs_on: self-hosted

Per-Job Environment Variables

Like GitLab, each job receives environment variables dynamically generated from your structure.pattern segments. For the default pattern {service}/{environment}/{region}/{module}:

VariableDescriptionExample
TF_MODULE_PATHRelative path to moduleplatform/prod/us-east-1/vpc
TF_SERVICEService nameplatform
TF_ENVIRONMENTEnvironment nameprod
TF_REGIONRegion nameus-east-1
TF_MODULEModule namevpc

Variable names are derived by uppercasing the segment name and prefixing with TF_.

Comparison with GitLab Configuration

FeatureGitLab (gitlab:)GitHub (github:)
Runner selectionjob_defaults.tagsruns_on
Container imageimagecontainer (optional)
Pre-job commandsjob_defaults.before_scriptjob_defaults.steps_before
Post-job commandsjob_defaults.after_scriptjob_defaults.steps_after
Pipeline variablesvariablesenv
Access controlrulespermissions
MR/PR integrationmr sectionpr section
Secretssecrets (Vault)Use GitHub Action steps
OIDC tokensid_tokenspermissions.id-token: write
Cachingcache.enabledUse actions/cache in steps
Stages prefixstages_prefixN/A (uses job dependencies)

See Also

Released under the MIT License.