Skip to content
This repository was archived by the owner on May 6, 2020. It is now read-only.

Commit 5011554

Browse files
authored
Adding ability to pass arguments via args (#107)
This should enable using GitHub Actions `args` attribute to pass arguments to each action.
1 parent 5bb74f3 commit 5011554

File tree

30 files changed

+303
-509
lines changed

30 files changed

+303
-509
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6262
```
6363
64-
This was a simplified example showing the basic features of these Terraform GitHub Actions. Please refer to the examples within the `examples` directory for more complex usage examples.
64+
This was a simplified example showing the basic features of these Terraform GitHub Actions. Please refer to the examples within the `examples` directory for more examples of common workflows.
6565

6666
## Inputs
6767

@@ -98,4 +98,4 @@ The usual [Terraform environment variables](https://www.terraform.io/docs/comman
9898
* [`TF_CLI_ARGS_name`](https://www.terraform.io/docs/commands/environment-variables.html#tf_cli_args-and-tf_cli_args_name)
9999
* `TF_WORKSPACE`
100100

101-
Other environment variables may be configured to pass data into Terraform backends and providers. If the data is sensitive, consider using [secrets](#secrets) instead.
101+
Other environment variables may be configured to pass data into Terraform. If the data is sensitive, consider using [secrets](#secrets) instead.

examples/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Examples
2+
3+
Here are some examples showing common workflows using Terraform GitHub Actions.

examples/arguments.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Arguments
2+
3+
Arguments can be passed to each subcommand in two ways.
4+
5+
## Using Arguments
6+
7+
GitHub Actions supports an `args` attribute that will pass arguments to the Terraform subcommand. Using this `args` attribute will place the arguments at the end of the entire `terraform` command, even after all of the arguments defined in the source code. In this example, the argument `-var="env=dev"` will be appended to the `terraform init` command.
8+
9+
```yaml
10+
name: 'Terraform GitHub Actions'
11+
on:
12+
- pull_request
13+
jobs:
14+
terraform:
15+
name: 'Terraform'
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: 'Checkout'
19+
uses: actions/checkout@master
20+
- name: 'Terraform Init'
21+
uses: hashicorp/terraform-github-actions@master
22+
with:
23+
tf_actions_version: 0.12.13
24+
tf_actions_subcommand: 'init'
25+
tf_actions_working_dir: '.'
26+
tf_actions_comment: true
27+
args: '-var="env=dev"'
28+
env:
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30+
```
31+
32+
33+
## Using Environment Variables
34+
35+
Terraform supports environment variables named `TF_CLI_ARGS` and `TF_CLI_ARG_name` where `name` is the subcommand that is being executed. Using these environment variables will place the arguments after the subcommand but before any arguments defined in the source code. In this example, the argument `-var="env=dev"` will be appended to the `terraform init` command.
36+
37+
```yaml
38+
name: 'Terraform GitHub Actions'
39+
on:
40+
- pull_request
41+
jobs:
42+
terraform:
43+
name: 'Terraform'
44+
runs-on: ubuntu-latest
45+
steps:
46+
- name: 'Checkout'
47+
uses: actions/checkout@master
48+
- name: 'Terraform Init'
49+
uses: hashicorp/terraform-github-actions@master
50+
with:
51+
tf_actions_version: 0.12.13
52+
tf_actions_subcommand: 'init'
53+
tf_actions_working_dir: '.'
54+
tf_actions_comment: true
55+
env:
56+
TF_CLI_ARGS_init: '-var="env=dev"'
57+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58+
```

examples/backends.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Terraform Backends
2+
3+
Terraform GitHub Actions supports initializing a `backend` block using the `-backend-config` option.
4+
5+
The example below shows how to pass the `token` and `organization` arguments to the `remote` backend block. The `token` argument is passed using GitHub Actions secrets while the organization is hardcoded.
6+
7+
```yaml
8+
name: 'Terraform GitHub Actions'
9+
on:
10+
- pull_request
11+
jobs:
12+
terraform:
13+
name: 'Terraform'
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: 'Checkout'
17+
uses: actions/checkout@master
18+
- name: 'Terraform Init'
19+
uses: hashicorp/terraform-github-actions@master
20+
with:
21+
tf_actions_version: 0.12.13
22+
tf_actions_subcommand: 'init'
23+
tf_actions_working_dir: '.'
24+
tf_actions_comment: true
25+
args: '-backend-config="token=${{ secrets.TF_API_TOKEN }}" -backend-config="organization=CHANGE_ME"'
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
```

examples/pull_request_no_working_dir/.github/workflows/example.yml

Lines changed: 0 additions & 43 deletions
This file was deleted.

examples/pull_request_no_working_dir/main.tf

Lines changed: 0 additions & 5 deletions
This file was deleted.

examples/pull_request_remote_backend_name/.github/workflows/example.yml

Lines changed: 0 additions & 46 deletions
This file was deleted.

examples/pull_request_remote_backend_name/main.tf

Lines changed: 0 additions & 13 deletions
This file was deleted.

examples/pull_request_remote_backend_prefix/.github/workflows/example.yml

Lines changed: 0 additions & 54 deletions
This file was deleted.

examples/pull_request_remote_backend_prefix/main.tf

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)