|
1 | 1 | # it-ae-actions-pullrequest-tfplan
|
2 | 2 | A GitHub composite action for generating and posting a terraform plan to a pull request. It will post the output of `terraform init` and `terraform plan` to the pull request found in the `github` workflow variable. It will also upload the terraform plan file to the repository as an artifact intended to be used with `terraform apply` later.
|
3 | 3 |
|
| 4 | +> [!IMPORTANT] |
| 5 | +> Note on private repositories: If the included `terraform init` needs to download a module from a private github repository, see below. |
| 6 | +
|
4 | 7 | ## Inputs
|
5 | 8 |
|
6 | 9 | | Name | Description | Default | Required |
|
7 | 10 | |------|-------------|---------|:--------:|
|
8 | 11 | | debug | Debug workflow with tmate if an error occurs | `false` | No |
|
9 |
| -| GITHUB_TOKEN | GitHub token for access to the pull request | | Yes | |
| 12 | +| GITHUB_TOKEN | GitHub token for access to the pull request (see note about private repositories) | | Yes | |
10 | 13 | | save-artifact | Save the terraform plan as an artifact (May contain sensitive data) | `false` | No |
|
11 | 14 | | working-directory | Working directory for the `run` actions | `""` | No |
|
12 | 15 | | terraform-version | Version of terraform to install | latest | No |
|
13 | 16 | | terraform-workspace | Terraform workspace to select. Must already exist | default | No |
|
14 | 17 | | terraform-init-flags | CLI flags to use with terraform init | `""` | No |
|
15 | 18 | | terraform-plan-flags | CLI flags to use with terraform plan | `""` | No |
|
16 |
| -| workflow-artifact-name | Provides a unique name to append to the plan artifact attached to this workflow run. Default tfplan | "tfplan" | No | |
| 19 | +| workflow-artifact-name | Provides a unique name to append to the plan artifact attached to this workflow run | "tfplan" | No | |
17 | 20 |
|
18 | 21 | ## Outputs
|
19 | 22 |
|
20 | 23 | | Name | Description |
|
21 | 24 | |------|-------------|
|
22 | 25 | | plan | The combined stdout and stderr output of `terraform plan` |
|
| 26 | + |
| 27 | +## Private Repositories |
| 28 | + |
| 29 | +If `terraform init` needs to download a module from a private github repository, merely passing `GITHUB_ACTION` to this Action is not sufficient. Instead, the calling action needs to change the source URL to embed the oauth2 token in a git-config step like: |
| 30 | +``` |
| 31 | + - name: Allow terraform to clone from private repo |
| 32 | + run: | |
| 33 | + git config --global url."https://oauth2:${{ secrets.GITHUB_TOKEN }}@github.com".insteadOf https://github.com |
| 34 | +``` |
| 35 | + |
| 36 | +for the corresponding Terraform module invocation like: |
| 37 | + |
| 38 | +``` |
| 39 | +module "my_module" { |
| 40 | + source = "github.com/my-org/my-repo.git//deep/path/to/module?ref=v0.1" |
| 41 | +``` |
0 commit comments