Skip to content

Commit 135ff7c

Browse files
committed
[#11] Updates documentation providing clarity on init with private repositories. No changes to functionality.
1 parent 36e38ca commit 135ff7c

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

README.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,41 @@
11
# it-ae-actions-pullrequest-tfplan
22
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.
33

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+
47
## Inputs
58

69
| Name | Description | Default | Required |
710
|------|-------------|---------|:--------:|
811
| 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 |
1013
| save-artifact | Save the terraform plan as an artifact (May contain sensitive data) | `false` | No |
1114
| working-directory | Working directory for the `run` actions | `""` | No |
1215
| terraform-version | Version of terraform to install | latest | No |
1316
| terraform-workspace | Terraform workspace to select. Must already exist | default | No |
1417
| terraform-init-flags | CLI flags to use with terraform init | `""` | No |
1518
| 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 |
1720

1821
## Outputs
1922

2023
| Name | Description |
2124
|------|-------------|
2225
| 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+
```

action.yaml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,7 @@ runs:
6969
id: init
7070
shell: bash
7171
working-directory: ${{ inputs.working-directory }}
72-
env:
73-
GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }}
74-
run: |
75-
git config --global url."https://oauth2:${GITHUB_TOKEN}@github.com".insteadOf https://github.com
76-
terraform init ${{ inputs.terraform-init-flags }}
72+
run: terraform init ${{ inputs.terraform-init-flags }}
7773

7874
- name: Post Init
7975
if: ${{ github.event_name == 'pull_request' }}

0 commit comments

Comments
 (0)