» Terraform Init Action

Runs terraform init to initialize a Terraform working directory and to confirm that any backends, modules, and providers are configured correctly. This action will comment back on the pull request on failure.

» Success Criteria

This action succeeds if terraform init runs without error.

» Usage

To use the init action, add it to your workflow file.

action "terraform init" {
  # Replace <latest tag> with the latest tag from
  # https://github.com/hashicorp/terraform-github-actions/releases.
  uses = "hashicorp/terraform-github-actions/init@<latest tag>"

  # See Environment Variables below for details.
  env = {
    TF_ACTION_WORKING_DIR = "."
  }

  # We need the GitHub token to be able to comment back on the pull request.
  secrets = ["GITHUB_TOKEN"]
}

» Environment Variables

Name Default Description
TF_ACTION_WORKING_DIR "." Which directory init runs in. Relative to the root of the repo.
TF_ACTION_COMMENT "true" Set to "false" to disable commenting back on pull on error.
TF_ACTION_TFE_HOSTNAME "app.terraform.io" If using Terraform Enterprise, set this to its hostname.

» Secrets

Name Description
GITHUB_TOKEN Required for posting comments to the pull request unless TF_ACTION_COMMENT = "false".
TF_ACTION_TFE_TOKEN If using the Terraform Cloud remote backend set this secret to a user API token.

NOTE: You may also need to add secrets for your providers, like AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY or GOOGLE_CREDENTIALS, if you're using a Terraform feature that uses them during init (such as Remote State).

» Arguments

Arguments to init will be appended to the terraform init command:

action "terraform init" {
  ...
  args = ["-lock=false"]
}