{"id":21261396,"url":"https://github.com/dflook/terraform-plan","last_synced_at":"2025-07-11T03:31:27.781Z","repository":{"id":61301420,"uuid":"277396488","full_name":"dflook/terraform-plan","owner":"dflook","description":"GitHub action to generate a terraform plan","archived":false,"fork":false,"pushed_at":"2025-06-16T14:38:52.000Z","size":197,"stargazers_count":28,"open_issues_count":0,"forks_count":10,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-06-16T15:40:41.289Z","etag":null,"topics":["actions","devops","github-action","github-actions","terraform"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dflook.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["dflook"]}},"created_at":"2020-07-05T22:53:45.000Z","updated_at":"2025-06-16T14:38:52.000Z","dependencies_parsed_at":"2023-02-18T01:31:10.488Z","dependency_job_id":"7d307797-6ac8-4bc7-88db-871e337798f1","html_url":"https://github.com/dflook/terraform-plan","commit_stats":{"total_commits":58,"total_committers":1,"mean_commits":58.0,"dds":0.0,"last_synced_commit":"f0212c2a3ea84e7f8a11cdc4187e8ebf3c426c0e"},"previous_names":[],"tags_count":316,"template":false,"template_full_name":null,"purl":"pkg:github/dflook/terraform-plan","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dflook%2Fterraform-plan","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dflook%2Fterraform-plan/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dflook%2Fterraform-plan/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dflook%2Fterraform-plan/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dflook","download_url":"https://codeload.github.com/dflook/terraform-plan/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dflook%2Fterraform-plan/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264721304,"owners_count":23653917,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["actions","devops","github-action","github-actions","terraform"],"created_at":"2024-11-21T04:29:25.270Z","updated_at":"2025-07-11T03:31:27.771Z","avatar_url":"https://github.com/dflook.png","language":null,"funding_links":["https://github.com/sponsors/dflook"],"categories":[],"sub_categories":[],"readme":"# terraform-plan action\n\nThis is one of a suite of Terraform related actions - find them at [dflook/terraform-github-actions](https://github.com/dflook/terraform-github-actions).\n\nThis action generates a Terraform plan.\nIf the triggering event relates to a PR it will add a comment on the PR containing the generated plan.\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"plan.png\" width=\"600\" alt=\"An example of a PR comment created by the action\"\u003e\n\u003c/p\u003e\n\nThe `GITHUB_TOKEN` environment variable must be set for the PR comment to be added.\nThe action can be run on other events, which prints the plan to the workflow log.\n\nThe [dflook/terraform-apply](https://github.com/dflook/terraform-github-actions/tree/main/terraform-apply) action can be used to apply the generated plan.\n\n## Inputs\n\n* `path`\n\n  The path to the Terraform root module to generate a plan for.\n\n  - Type: string\n  - Optional\n  - Default: The action workspace\n\n* `workspace`\n\n  Terraform workspace to run the plan for.\n\n  - Type: string\n  - Optional\n  - Default: `default`\n\n* `label`\n\n  A friendly name for the environment the Terraform configuration is for.\n  This will be used in the PR comment for easy identification.\n\n  If this is set, it must be the same as the `label` used in any corresponding [`dflook/terraform-apply`](https://github.com/dflook/terraform-github-actions/tree/main/terraform-apply) action.\n\n  - Type: string\n  - Optional\n\n* `variables`\n\n  Variables to set for the terraform plan. This should be valid Terraform syntax - like a [variable definition file](https://developer.hashicorp.com/terraform/language/values/variables#variable-definitions-tfvars-files).\n\n  Variables set here override any given in `var_file`s.\n\n  ```yaml\n  with:\n    variables: |\n      image_id = \"${{ secrets.AMI_ID }}\"\n      availability_zone_names = [\n        \"us-east-1a\",\n        \"us-west-1c\",\n      ]\n  ```\n\n  - Type: string\n  - Optional\n\n* `var_file`\n\n  List of tfvars files to use, one per line.\n  Paths should be relative to the GitHub Actions workspace\n\n  ```yaml\n  with:\n    var_file: |\n      common.tfvars\n      prod.tfvars\n  ```\n\n  - Type: string\n  - Optional\n\n* `backend_config`\n\n  List of Terraform backend config values, one per line.\n\n  ```yaml\n  with:\n    backend_config: token=${{ secrets.BACKEND_TOKEN }}\n  ```\n\n  - Type: string\n  - Optional\n\n* `backend_config_file`\n\n  List of Terraform backend config files to use, one per line.\n  Paths should be relative to the GitHub Actions workspace\n\n  ```yaml\n  with:\n    backend_config_file: prod.backend.tfvars\n  ```\n\n  - Type: string\n  - Optional\n\n* `replace`\n\n  List of resources to replace, one per line.\n\n  ```yaml\n  with:\n    replace: |\n      random_password.database\n  ```\n\n  - Type: string\n  - Optional\n\n* `target`\n\n  List of resources to target, one per line.\n  The plan will be limited to these resources and their dependencies.\n\n  ```yaml\n  with:\n    target: |\n      kubernetes_secret.tls_cert_public\n      kubernetes_secret.tls_cert_private\n  ```\n\n  - Type: string\n  - Optional\n\n* `destroy`\n\n  Set to `true` to generate a plan to destroy all resources.\n\n  This generates a plan in [destroy mode](https://developer.hashicorp.com/terraform/cli/commands/plan#planning-modes).\n\n  - Type: boolean\n  - Optional\n  - Default: `false`\n\n* `refresh`\n\n  Set to `false` to skip synchronisation of the Terraform state with actual resources.\n\n  This will make the plan faster but may be out of date with the actual resources, which can lead to incorrect plans.\n\n  - Type: boolean\n  - Optional\n  - Default: `true`\n\n* `add_github_comment`\n\n  Controls whether a comment is added to the PR with the generated plan.\n\n  The default is `true`, which adds a comment to the PR with the results of the plan.\n  Set to `changes-only` to add a comment only when the plan indicates there are changes to apply.\n  Set to `always-new` to always create a new comment for each plan, instead of updating the previous comment.\n  Set to `false` to disable the comment - the plan will still appear in the workflow log.\n\n  - Type: string\n  - Optional\n  - Default: `true`\n\n* `parallelism`\n\n  Limit the number of concurrent operations\n\n  - Type: number\n  - Optional\n  - Default: The Terraform default (10).\n\n## Outputs\n\n* `changes`\n\n  Set to 'true' if the plan would apply any changes, 'false' if it wouldn't.\n\n  - Type: boolean\n\n* `plan_path`\n\n  This is the path to the generated plan in an opaque binary format.\n  The path is relative to the Actions workspace.\n\n  The plan can be used as the `plan_file` input to the [dflook/terraform-apply](https://github.com/dflook/terraform-github-actions/tree/main/terraform-apply) action.\n\n  Terraform plans often contain sensitive information, so this output should be treated with care.\n\n  - Type: string\n\n* `json_plan_path`\n\n  This is the path to the generated plan in [JSON Output Format](https://www.terraform.io/docs/internals/json-format.html).\n  The path is relative to the Actions workspace.\n\n  Terraform plans often contain sensitive information, so this output should be treated with care.\n\n  - Type: string\n\n* `text_plan_path`\n\n  This is the path to the generated plan in a human-readable format.\n  The path is relative to the Actions workspace.\n\n  - Type: string\n\n* `to_add`\n* `to_change`\n* `to_destroy`\n* `to_move`\n* `to_import`\n\n  The number of resources that would be affected by each type of operation.\n\n  - Type: number\n\n* `run_id`\n\n  If the root module uses the `remote` or `cloud` backend in remote execution mode, this output will be set to the remote run id.\n\n  - Type: string\n\n## Environment Variables\n\n* `GITHUB_TOKEN`\n\n  The GitHub authorization token to use to create comments on a PR.\n\n  The token provided by GitHub Actions can be used - it can be passed by\n  using the `${{ secrets.GITHUB_TOKEN }}` expression, e.g.\n\n  ```yaml\n  env:\n    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n  ```\n\n  The token provided by GitHub Actions has default permissions at GitHub's whim. You can see what it is for your repo under the repo settings.\n\n  The minimum permissions are `pull-requests: write`.\n  It will also likely need `contents: read` so the job can checkout the repo.\n\n  You can also use any other App token that has `pull-requests: write` permission.\n\n  You can use a fine-grained Personal Access Token which has repository permissions:\n  - Read access to metadata\n  - Read and Write access to pull requests\n\n  You can also use a classic Personal Access Token which has the `repo` scope.\n\n  The GitHub user or app that owns the token will be the PR comment author.\n\n  - Type: string\n  - Optional\n\n* `TERRAFORM_ACTIONS_GITHUB_TOKEN`\n\n  When this is set it is used instead of `GITHUB_TOKEN`, with the same behaviour.\n  The GitHub Terraform provider also uses the `GITHUB_TOKEN` environment variable,\n  so this can be used to make the github actions and the Terraform provider use different tokens.\n\n  - Type: string\n  - Optional\n\n* `GITHUB_DOT_COM_TOKEN`\n\n  This is used to specify a token for GitHub.com when the action is running on a GitHub Enterprise instance.\n  This is only used for downloading OpenTofu binaries from GitHub.com.\n  If this is not set, an unauthenticated request will be made to GitHub.com to download the binary, which may be rate limited.\n\n  - Type: string\n  - Optional\n\n* `TERRAFORM_CLOUD_TOKENS`\n\n  API tokens for cloud hosts, of the form `\u003chost\u003e=\u003ctoken\u003e`. Multiple tokens may be specified, one per line.\n  These tokens may be used with the `remote` backend and for fetching required modules from the registry.\n\n  e.g:\n\n  ```yaml\n  env:\n    TERRAFORM_CLOUD_TOKENS: app.terraform.io=${{ secrets.TF_CLOUD_TOKEN }}\n  ```\n\n  With other registries:\n\n  ```yaml\n  env:\n    TERRAFORM_CLOUD_TOKENS: |\n      app.terraform.io=${{ secrets.TF_CLOUD_TOKEN }}\n      terraform.example.com=${{ secrets.TF_REGISTRY_TOKEN }}\n  ```\n\n  - Type: string\n  - Optional\n\n* `TERRAFORM_SSH_KEY`\n\n  A SSH private key that Terraform will use to fetch git/mercurial module sources.\n\n  This should be in PEM format.\n\n  For example:\n\n  ```yaml\n  env:\n    TERRAFORM_SSH_KEY: ${{ secrets.TERRAFORM_SSH_KEY }}\n  ```\n\n  - Type: string\n  - Optional\n\n* `TERRAFORM_HTTP_CREDENTIALS`\n\n  Credentials that will be used for fetching modules sources with `git::http://`, `git::https://`, `http://` \u0026 `https://` schemes.\n\n  Credentials have the format `\u003chost\u003e=\u003cusername\u003e:\u003cpassword\u003e`. Multiple credentials may be specified, one per line.\n\n  Each credential is evaluated in order, and the first matching credentials are used.\n\n  Credentials that are used by git (`git::http://`, `git::https://`) allow a path after the hostname.\n  Paths are ignored by `http://` \u0026 `https://` schemes.\n  For git module sources, a credential matches if each mentioned path segment is an exact match.\n\n  For example:\n\n  ```yaml\n  env:\n    TERRAFORM_HTTP_CREDENTIALS: |\n      example.com=dflook:${{ secrets.HTTPS_PASSWORD }}\n      github.com/dflook/terraform-github-actions.git=dflook-actions:${{ secrets.ACTIONS_PAT }}\n      github.com/dflook=dflook:${{ secrets.DFLOOK_PAT }}\n      github.com=graham:${{ secrets.GITHUB_PAT }}  \n  ```\n\n  - Type: string\n  - Optional\n\n* `TF_PLAN_COLLAPSE_LENGTH`\n\n  When PR comments are enabled, the terraform output is included in a collapsable pane.\n\n  If a terraform plan has fewer lines than this value, the pane is expanded\n  by default when the comment is displayed.\n\n  ```yaml\n\n  env:\n    TF_PLAN_COLLAPSE_LENGTH: 30\n  ```\n\n  - Type: integer\n  - Optional\n  - Default: `10`\n\n* `TERRAFORM_PRE_RUN`\n\n  A set of commands that will be ran prior to `terraform init`. This can be used to customise the environment before running Terraform.\n\n  The runtime environment for these actions is subject to change in minor version releases. If using this environment variable, specify the minor version of the action to use.\n\n  The runtime image is currently based on `debian:bookworm`, with the command run using `bash -xeo pipefail`.\n\n  For example:\n\n  ```yaml\n  env:\n    TERRAFORM_PRE_RUN: |\n      # Install latest Azure CLI\n      curl -skL https://aka.ms/InstallAzureCLIDeb | bash\n\n      # Install postgres client\n      apt-get install -y --no-install-recommends postgresql-client\n  ```\n\n  - Type: string\n  - Optional\n\n## Workflow events\n\nWhen adding the plan to a PR comment (`add_github_comment` is not `false`), the workflow can be triggered by the following events:\n\n* pull_request\n* pull_request_review_comment\n* pull_request_target\n* pull_request_review\n* issue_comment, if the comment is on a PR (see below)\n* push, if the pushed commit came from a PR (see below)\n* repository_dispatch, if the client payload includes the pull_request url (see below)\n\nWhen `add_github_comment` is set to `false`, the workflow can be triggered by any event.\n\n### issue_comment\n\nThis event triggers workflows when a comment is made in a Issue, as well as a Pull Request.\nSince running the action will only work in the context of a PR, the workflow should check that the comment is on a PR before running.\n\nAlso take care to checkout the PR ref.\n\n```yaml\njobs:\n  plan:\n    if: ${{ github.event.issue.pull_request }}\n    runs-on: ubuntu-latest\n    env:\n      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n    steps:\n      - name: Checkout\n        uses: actions/checkout@v4\n        with:\n          ref: refs/pull/${{ github.event.issue.number }}/merge\n\n      - name: terraform apply\n        uses: dflook/terraform-plan@v2\n        with:\n          path: my-terraform-config\n```\n\n### push\n\nThe pushed commit must have come from a Pull Request. Typically this is used to trigger a workflow that runs on the main branch after a PR has been merged.\n\n### repository_dispatch\n\nThis event can be used to trigger a workflow from another workflow. The client payload must include the pull_request api url of where the plan PR comment should be added.\n\nA minimal example payload looks like:\n\n```json\n{\n  \"pull_request\": {\n    \"url\": \"https://api.github.com/repos/dflook/terraform-github-actions/pulls/1\"\n  }\n}\n```\n\n## Example usage\n\n### Automatically generating a plan\n\nThis example workflow runs on every push to an open pull request,\nand create or updates a comment with the terraform plan\n\n```yaml\nname: PR Plan\n\non: [pull_request]\n\npermissions:\n  contents: read\n  pull-requests: write\n\njobs:\n  plan:\n    runs-on: ubuntu-latest\n    name: Create terraform plan\n    env:\n      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}            \n    steps:\n      - name: Checkout\n        uses: actions/checkout@v4\n\n      - name: terraform plan\n        uses: dflook/terraform-plan@v2\n        with:\n          path: my-terraform-config\n```\n\n### A full example of inputs\n\nThis example workflow demonstrates most of the available inputs:\n\n* The environment variables are set at the workflow level.\n* The PR comment will be labelled `production`, and the plan will use the `prod` workspace.\n* Variables are read from `env/prod.tfvars`, with `turbo_mode` overridden to `true`.\n* The backend config is taken from `env/prod.backend`, and the token is set from a secret.\n\n```yaml\nname: PR Plan\n\non: [pull_request]\n\nenv:\n  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n  TERRAFORM_CLOUD_TOKENS: terraform.example.com=${{ secrets.TF_REGISTRY_TOKEN }}\n  TERRAFORM_SSH_KEY: ${{ secrets.TERRAFORM_SSH_KEY }}\n\npermissions:\n  contents: read\n  pull-requests: write\n\njobs:\n  plan:\n    runs-on: ubuntu-latest\n    name: Create Terraform plan\n    steps:\n      - name: Checkout\n        uses: actions/checkout@v4\n\n      - name: terraform plan\n        uses: dflook/terraform-plan@v2\n        with:\n          path: my-terraform-config\n          label: production\n          workspace: prod\n          var_file: env/prod.tfvars\n          variables: |\n            turbo_mode=true\n          backend_config_file: env/prod.backend\n          backend_config: token=${{ secrets.BACKEND_TOKEN }}\n```\n\n### Generating a plan using a comment\n\nThis workflow generates a plan on demand, triggered by someone\ncommenting `terraform plan` on the PR. The action will create or update\na comment on the PR with the generated plan.\n\n```yaml\nname: Terraform Plan\n\non: [issue_comment]\n\npermissions:\n  contents: read\n  pull-requests: write\n\njobs:\n  plan:\n    if: ${{ github.event.issue.pull_request \u0026\u0026 contains(github.event.comment.body, 'terraform plan') }}\n    runs-on: ubuntu-latest\n    name: Create Terraform plan\n    env:\n      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n    steps:\n      - name: Checkout\n        uses: actions/checkout@v4\n        with:\n          ref: refs/pull/${{ github.event.issue.number }}/merge\n\n      - name: terraform plan\n        uses: dflook/terraform-plan@v2\n        with:\n          path: my-terraform-config\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdflook%2Fterraform-plan","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdflook%2Fterraform-plan","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdflook%2Fterraform-plan/lists"}