Skip to content

Commit 830bb77

Browse files
committed
Link to terraform.io docs.
1 parent f2bd58b commit 830bb77

File tree

5 files changed

+9
-468
lines changed

5 files changed

+9
-468
lines changed

README.md

Lines changed: 4 additions & 270 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
# Terraform GitHub Actions
2-
These official Terraform GitHub Actions allow you to run `terraform fmt`, `validate` and `plan` on your pull requests to help you review and validate Terraform changes.
3-
4-
* [Actions](#actions)
5-
* [Fmt Action](#fmt-action)
6-
* [Validate Action](#validate-action)
7-
* [Plan Action](#plan-action)
8-
* [Usage](#usage)
9-
* [Recommended Workflow](#recommended-workflow)
10-
* [Step 1 - Create the initial workflow](#step-1---create-the-initial-workflow)
11-
* [Step 2 - Customize it for your use-case](#step-2---customize-it-for-your-use-case)
12-
* [Compose Your Own Workflow](#compose-your-own-workflow)
13-
* [Directories](#directories)
14-
* [Workspaces](#workspaces)
2+
These official Terraform GitHub Actions allow you to run `terraform fmt`, `validate`
3+
and `plan` on your pull requests to help you review and validate Terraform changes.
154

165
## Actions
176

@@ -27,260 +16,5 @@ Runs `terraform validate` and comments back on error.
2716
Runs `terraform plan` and comments back with the output.
2817
<img src="./assets/plan.png" alt="Terraform Plan Action" width="80%" />
2918

30-
## Usage
31-
To add these actions to your pull requests, you can copy our [recommended workflow](#recommended-workflow) into your `.github/main.workflow` file or you can [write your own workflow](#compose-your-own-workflow).
32-
33-
### Recommended Workflow
34-
This workflow will run `terraform fmt`, `init`, `validate` and `plan`. To use it:
35-
36-
#### Step 1 - Create the initial workflow
37-
1. Open up your repository in GitHub and click on the **Actions** tab
38-
1. Click **Create a new workflow**
39-
1. Click **<> Edit new file**
40-
1. Paste the contents below into the file
41-
<details><summary>Show</summary>
42-
43-
```workflow
44-
workflow "Terraform" {
45-
resolves = "terraform-plan"
46-
on = "pull_request"
47-
}
48-
49-
action "filter-to-pr-open-synced" {
50-
uses = "docker://superbbears/filter:0.2.0"
51-
args = ["action", "opened|synchronize"]
52-
}
53-
54-
action "terraform-fmt" {
55-
uses = "hashicorp/terraform-github-actions/[email protected]"
56-
needs = "filter-to-pr-open-synced"
57-
secrets = ["GITHUB_TOKEN"]
58-
env = {
59-
TF_ACTION_WORKING_DIR = "."
60-
}
61-
}
62-
63-
action "terraform-init" {
64-
uses = "hashicorp/terraform-github-actions/[email protected]"
65-
needs = "terraform-fmt"
66-
secrets = ["GITHUB_TOKEN"]
67-
env = {
68-
TF_ACTION_WORKING_DIR = "."
69-
}
70-
}
71-
72-
action "terraform-validate" {
73-
uses = "hashicorp/terraform-github-actions/[email protected]"
74-
needs = "terraform-init"
75-
secrets = ["GITHUB_TOKEN"]
76-
env = {
77-
TF_ACTION_WORKING_DIR = "."
78-
}
79-
}
80-
81-
action "terraform-plan" {
82-
uses = "hashicorp/terraform-github-actions/[email protected]"
83-
needs = "terraform-validate"
84-
secrets = ["GITHUB_TOKEN"]
85-
env = {
86-
TF_ACTION_WORKING_DIR = "."
87-
# If you're using Terraform workspaces, set this to the workspace name.
88-
TF_ACTION_WORKSPACE = "default"
89-
}
90-
}
91-
```
92-
</details>
93-
94-
#### Step 2 - Customize it for your use-case
95-
1. If your Terraform is in a different directory that the root of your repo, replace all instances of
96-
```
97-
TF_ACTION_WORKING_DIR = "."
98-
```
99-
With your directory, relative to the root of the repo, ex.
100-
```
101-
TF_ACTION_WORKING_DIR = "./terraform"
102-
```
103-
If you have multiple directories of Terraform code see [Directories](#directories)
104-
1. If your Terraform runs in a different [workspace](https://www.terraform.io/docs/state/workspaces.html) than `default`, also change the `TF_ACTION_WORKSPACE` environment variable in the `terraform-plan` action.
105-
106-
If you have multiple workspaces, see [Workspaces](#workspaces).
107-
1. If you're using a Terraform provider that requires credentials to run `terraform plan` (like AWS or Google Cloud Platform) then you need to add those credentials as Secrets to the `terraform-plan` action. Secrets can only be added from the **Visual Editor** so click back to that tab.
108-
1. Scroll down to the `terraform-plan` action and click **Edit**. This will open up the action editor on the right side where you'll be able to add your secrets, ex. `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`. See your [Provider Documentation](https://www.terraform.io/docs/providers/) for how to use environment variables with your provider.
109-
110-
⚠️ WARNING ⚠️ These secrets could be exposed if the plan action is run on a malicious Terraform file. As a result, we recommend you do not use this action on public repos or repos where untrusted users can submit pull requests.
111-
112-
113-
## Compose Your Own Workflow
114-
If you'd like to compose your own workflow, you can use each action separately. Each action is documented:
115-
* [fmt](fmt/)
116-
* [init](init/)
117-
* [validate](validate/)
118-
* [plan](plan/)
119-
120-
## Directories
121-
Currently, these actions only support running in a single directory. If you'd like to run them in multiple directories, you'll have to create separate workflows for each directory:
122-
123-
<details><summary>Show</summary>
124-
125-
```workflow
126-
workflow "terraform-dir1" {
127-
resolves = "terraform-plan-dir1"
128-
on = "pull_request"
129-
}
130-
131-
action "filter-to-pr-open-synced" {
132-
uses = "docker://superbbears/filter:0.2.0"
133-
args = ["action", "opened|synchronize"]
134-
}
135-
136-
action "terraform-fmt-dir1" {
137-
uses = "hashicorp/terraform-github-actions/[email protected]"
138-
needs = "filter-to-pr-open-synced"
139-
secrets = ["GITHUB_TOKEN"]
140-
141-
env = {
142-
TF_ACTION_WORKING_DIR = "dir1"
143-
}
144-
}
145-
146-
action "terraform-init-dir1" {
147-
uses = "hashicorp/terraform-github-actions/[email protected]"
148-
secrets = ["GITHUB_TOKEN"]
149-
needs = "terraform-fmt-dir1"
150-
151-
env = {
152-
TF_ACTION_WORKING_DIR = "dir1"
153-
}
154-
}
155-
156-
action "terraform-validate-dir1" {
157-
uses = "hashicorp/terraform-github-actions/[email protected]"
158-
secrets = ["GITHUB_TOKEN"]
159-
needs = "terraform-init-dir1"
160-
161-
env = {
162-
TF_ACTION_WORKING_DIR = "dir1"
163-
}
164-
}
165-
166-
action "terraform-plan-dir1" {
167-
uses = "hashicorp/terraform-github-actions/[email protected]"
168-
needs = "terraform-validate-dir1"
169-
secrets = ["GITHUB_TOKEN"]
170-
171-
env = {
172-
TF_ACTION_WORKING_DIR = "dir1"
173-
}
174-
}
175-
176-
workflow "terraform-dir2" {
177-
resolves = "terraform-plan-dir2"
178-
on = "pull_request"
179-
}
180-
181-
action "terraform-fmt-dir2" {
182-
uses = "hashicorp/terraform-github-actions/[email protected]"
183-
needs = "filter-to-pr-open-synced"
184-
secrets = ["GITHUB_TOKEN"]
185-
186-
env = {
187-
TF_ACTION_WORKING_DIR = "dir2"
188-
}
189-
}
190-
191-
action "terraform-init-dir2" {
192-
uses = "hashicorp/terraform-github-actions/[email protected]"
193-
secrets = ["GITHUB_TOKEN"]
194-
needs = "terraform-fmt-dir2"
195-
196-
env = {
197-
TF_ACTION_WORKING_DIR = "dir2"
198-
}
199-
}
200-
201-
action "terraform-validate-dir2" {
202-
uses = "hashicorp/terraform-github-actions/[email protected]"
203-
secrets = ["GITHUB_TOKEN"]
204-
needs = "terraform-init-dir2"
205-
206-
env = {
207-
TF_ACTION_WORKING_DIR = "dir2"
208-
}
209-
}
210-
211-
action "terraform-plan-dir2" {
212-
uses = "hashicorp/terraform-github-actions/[email protected]"
213-
needs = "terraform-validate-dir2"
214-
secrets = ["GITHUB_TOKEN"]
215-
216-
env = {
217-
TF_ACTION_WORKING_DIR = "dir2"
218-
}
219-
}
220-
```
221-
</details>
222-
223-
## Workspaces
224-
Currently, these actions only support running in a single [Terraform workspace](https://www.terraform.io/docs/state/workspaces.html).
225-
226-
NOTE: The only action workspaces affect is `plan`.
227-
228-
If you'd like to run in multiple workspaces, you need to create separate workflows for each workspace. Since the only action that uses workspaces is `plan`, you can share the rest of the `fmt`, `init` and `validate` actions between the two workflows:
229-
230-
<details><summary>Show</summary>
231-
232-
```workflow
233-
workflow "terraform-workspace1" {
234-
resolves = "terraform-plan-workspace1"
235-
on = "pull_request"
236-
}
237-
238-
workflow "terraform-workspace2" {
239-
resolves = "terraform-plan-workspace2"
240-
on = "pull_request"
241-
}
242-
243-
action "filter-to-pr-open-synced" {
244-
uses = "docker://superbbears/filter:0.2.0"
245-
args = ["action", "opened|synchronize"]
246-
}
247-
248-
action "terraform-fmt" {
249-
uses = "hashicorp/terraform-github-actions/[email protected]"
250-
needs = "filter-to-pr-open-synced"
251-
secrets = ["GITHUB_TOKEN"]
252-
}
253-
254-
action "terraform-init" {
255-
uses = "hashicorp/terraform-github-actions/[email protected]"
256-
secrets = ["GITHUB_TOKEN"]
257-
needs = "terraform-fmt"
258-
}
259-
260-
action "terraform-validate" {
261-
uses = "hashicorp/terraform-github-actions/[email protected]"
262-
secrets = ["GITHUB_TOKEN"]
263-
needs = "terraform-init"
264-
}
265-
266-
action "terraform-plan-workspace1" {
267-
uses = "hashicorp/terraform-github-actions/[email protected]"
268-
needs = "terraform-validate"
269-
secrets = ["GITHUB_TOKEN"]
270-
271-
env = {
272-
TF_ACTION_WORKSPACE = "workspace1"
273-
}
274-
}
275-
276-
action "terraform-plan-workspace2" {
277-
uses = "hashicorp/terraform-github-actions/[email protected]"
278-
needs = "terraform-validate"
279-
secrets = ["GITHUB_TOKEN"]
280-
281-
env = {
282-
TF_ACTION_WORKSPACE = "workspace2"
283-
}
284-
}
285-
```
286-
</details>
19+
## Getting Started
20+
To get started, check out our documentation: [https://www.terraform.io/docs/github-actions/getting-started/](https://www.terraform.io/docs/github-actions/getting-started/).

fmt/README.md

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,5 @@
11
# Terraform Fmt Action
22
Runs `terraform fmt` to validate all Terraform files in a directory are in the canonical format.
3-
If any files differ, this action will comment back on the pull request with the diffs of each file.
3+
If any files differ, this action will comment back on the pull request with the diffs of each file.
44

5-
## Success Criteria
6-
This action succeeds if `terraform fmt` runs without error.
7-
8-
## Usage
9-
To use the `fmt` action, add it to your workflow file.
10-
11-
```workflow
12-
action "terraform fmt" {
13-
# Replace <latest tag> with the latest tag from https://github.com/hashicorp/terraform-github-actions/releases.
14-
uses = "hashicorp/terraform-github-actions/fmt@<latest tag>"
15-
16-
# See Environment Variables below for details.
17-
env = {
18-
TF_ACTION_WORKING_DIR = "."
19-
}
20-
21-
# We need the GitHub token to be able to comment back on the pull request.
22-
secrets = ["GITHUB_TOKEN"]
23-
}
24-
```
25-
26-
## Environment Variables
27-
| Name | Default | Description |
28-
|-------------------------|-----------|----------------------------------------------------------------------------------|
29-
| `TF_ACTION_WORKING_DIR` | `"."` | Which directory `fmt` runs in. Relative to the root of the repo. |
30-
| `TF_ACTION_COMMENT` | `"true"` | Set to `"false"` to disable commenting back on pull request with the diffs of unformatted files. |
31-
32-
33-
## Secrets
34-
The `GITHUB_TOKEN` secret is required for posting a comment back to the pull request if `fmt` fails.
35-
36-
If you have set `TF_ACTION_COMMENT = "false"`, then `GITHUB_TOKEN` is not required.
37-
38-
## Arguments
39-
Any arguments will be appended to the `terraform fmt` command however we do not anticipate that this will be needed.
5+
See [https://www.terraform.io/docs/github-actions/actions/fmt.html](https://www.terraform.io/docs/github-actions/actions/fmt.html).

init/README.md

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,4 @@
11
# Terraform Init Action
22
Runs `terraform init` to initialize a Terraform working directory. This action will comment back on the pull request on failure.
33

4-
## Success Criteria
5-
This action succeeds if `terraform init` runs without error.
6-
7-
## Usage
8-
To use the `init` action, add it to your workflow file.
9-
10-
```workflow
11-
action "terraform init" {
12-
# Replace <latest tag> with the latest tag from https://github.com/hashicorp/terraform-github-actions/releases.
13-
uses = "hashicorp/terraform-github-actions/init@<latest tag>"
14-
15-
# See Environment Variables below for details.
16-
env = {
17-
TF_ACTION_WORKING_DIR = "."
18-
}
19-
20-
# We need the GitHub token to be able to comment back on the pull request.
21-
secrets = ["GITHUB_TOKEN"]
22-
}
23-
```
24-
25-
## Environment Variables
26-
| Name | Default | Description |
27-
|-------------------------|-----------|----------------------------------------------------------------------------------|
28-
| `TF_ACTION_WORKING_DIR` | `"."` | Which directory `init` runs in. Relative to the root of the repo. |
29-
| `TF_ACTION_COMMENT` | `"true"` | Set to `"false"` to disable commenting back on pull on error. |
30-
31-
32-
## Secrets
33-
The `GITHUB_TOKEN` secret is required for posting a comment back to the pull request if `init` fails.
34-
35-
If you have set `TF_ACTION_COMMENT = "false"`, then `GITHUB_TOKEN` is not required.
36-
37-
## Arguments
38-
Arguments to `init` will be appended to the `terraform init` command:
39-
40-
```workflow
41-
action "terraform init" {
42-
...
43-
args = ["-lock=false"]
44-
}
45-
```
4+
See [https://www.terraform.io/docs/github-actions/actions/init.html](https://www.terraform.io/docs/github-actions/actions/init.html).

0 commit comments

Comments
 (0)