Skip to content

Commit 3f979e0

Browse files
committed
Run actions with Terragrunt
1 parent 306798b commit 3f979e0

13 files changed

+141
-114
lines changed

README.md

+43-31
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,103 @@
1-
# Terraform GitHub Actions
1+
# Terragrunt GitHub Actions
22

3-
Terraform GitHub Actions allow you to execute Terraform commands within GitHub Actions.
3+
Terragrunt GitHub Actions allow you to execute Terragrunt commands within GitHub Actions.
44

55
The output of the actions can be viewed from the Actions tab in the main repository view. If the actions are executed on a pull request event, a comment may be posted on the pull request.
66

7-
Terraform GitHub Actions are a single GitHub Action that executes different Terraform subcommands depending on the content of the GitHub Actions YAML file.
7+
Terragrunt GitHub Actions are a single GitHub Action that executes different Terragrunt subcommands depending on the content of the GitHub Actions YAML file.
88

99
## Success Criteria
1010

1111
An exit code of `0` is considered a successful execution.
1212

1313
## Usage
1414

15-
The most common workflow is to run `terraform fmt`, `terraform init`, `terraform validate`, `terraform plan`, and `terraform taint` on all of the Terraform files in the root of the repository when a pull request is opened or updated. A comment will be posted to the pull request depending on the output of the Terraform subcommand being executed. This workflow can be configured by adding the following content to the GitHub Actions workflow YAML file.
15+
The most common workflow is to run `terragrunt fmt`, `terragrunt init`, `terragrunt validate`, `terragrunt plan`, and `terragrunt taint` on all of the Terragrunt files in the root of the repository when a pull request is opened or updated. A comment will be posted to the pull request depending on the output of the Terragrunt subcommand being executed. This workflow can be configured by adding the following content to the GitHub Actions workflow YAML file. Note that this action will use `terragrunt` binary to run all commands. In case of passing a `terraform` subcommand `terragrunt` will forward it to `terraform`.
1616

1717
```yaml
18-
name: 'Terraform GitHub Actions'
18+
name: 'Terragrunt GitHub Actions'
1919
on:
2020
- pull_request
2121
env:
2222
tf_version: 'latest'
23+
tg_version: 'latest'
2324
tf_working_dir: '.'
2425
jobs:
25-
terraform:
26-
name: 'Terraform'
26+
terragrunt:
27+
name: 'Terragrunt'
2728
runs-on: ubuntu-latest
2829
steps:
2930
- name: 'Checkout'
3031
uses: actions/checkout@master
31-
- name: 'Terraform Format'
32-
uses: hashicorp/terraform-github-actions@master
32+
- name: 'Terragrunt Format'
33+
uses: hashicorp/terragrunt-github-actions@master
3334
with:
34-
tf_actions_version: ${{ env.tf_version }}
35-
tf_actions_subcommand: 'fmt'
36-
tf_actions_working_dir: ${{ env.tf_working_dir }}
37-
tf_actions_comment: true
35+
tf_actions_actions_version: ${{ env.tf_version }}
36+
tg_actions_actions_version: ${{ env.tg_version }}
37+
tf_actions_actions_subcommand: 'fmt'
38+
tf_actions_actions_working_dir: ${{ env.tf_working_dir }}
39+
tf_actions_actions_comment: true
3840
env:
3941
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40-
- name: 'Terraform Init'
41-
uses: hashicorp/terraform-github-actions@master
42+
- name: 'Terragrunt Init'
43+
uses: hashicorp/terragrunt-github-actions@master
4244
with:
4345
tf_actions_version: ${{ env.tf_version }}
46+
tg_actions_version: ${{ env.tg_version }}
4447
tf_actions_subcommand: 'init'
4548
tf_actions_working_dir: ${{ env.tf_working_dir }}
4649
tf_actions_comment: true
4750
env:
4851
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49-
- name: 'Terraform Validate'
50-
uses: hashicorp/terraform-github-actions@master
52+
- name: 'Terragrunt Validate'
53+
uses: hashicorp/terragrunt-github-actions@master
5154
with:
5255
tf_actions_version: ${{ env.tf_version }}
56+
tg_actions_version: ${{ env.tg_version }}
5357
tf_actions_subcommand: 'validate'
5458
tf_actions_working_dir: ${{ env.tf_working_dir }}
5559
tf_actions_comment: true
5660
env:
5761
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58-
- name: 'Terraform Plan'
59-
uses: hashicorp/terraform-github-actions@master
62+
- name: 'Terragrunt Plan'
63+
uses: hashicorp/terragrunt-github-actions@master
6064
with:
6165
tf_actions_version: ${{ env.tf_version }}
66+
tg_actions_version: ${{ env.tg_version }}
6267
tf_actions_subcommand: 'plan'
6368
tf_actions_working_dir: ${{ env.tf_working_dir }}
6469
tf_actions_comment: true
6570
env:
6671
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6772
```
6873
69-
This was a simplified example showing the basic features of these Terraform GitHub Actions. Please refer to the examples within the `examples` directory for other common workflows.
74+
This was a simplified example showing the basic features of these Terragrunt GitHub Actions. Please refer to the examples within the `examples` directory for other common workflows.
7075

7176
## Inputs
7277

7378
Inputs configure Terraform GitHub Actions to perform different actions.
7479

75-
* `tf_actions_subcommand` - (Required) The Terraform subcommand to execute. Valid values are `fmt`, `init`, `validate`, `plan`, and `apply`.
76-
* `tf_actions_version` - (Required) The Terraform version to install and execute. If set to `latest`, the latest stable version will be used.
77-
* `tf_actions_cli_credentials_hostname` - (Optional) Hostname for the CLI credentials file. Defaults to `app.terraform.io`.
78-
* `tf_actions_cli_credentials_token` - (Optional) Token for the CLI credentials file.
79-
* `tf_actions_comment` - (Optional) Whether or not to comment on GitHub pull requests. Defaults to `true`.
80-
* `tf_actions_working_dir` - (Optional) The working directory to change into before executing Terraform subcommands. Defaults to `.` which means use the root of the GitHub repository.
81-
* `tf_actions_fmt_write` - (Optional) Whether or not to write `fmt` changes to source files. Defaults to `false`.
80+
| Input Name | Description | Required |
81+
|:------------------------------------|:-----------------------------------------------------------|:--------:|
82+
| tf_actions_subcommand | The Terraform/Terragrunt subcommand to execute. | `Yes` |
83+
| tf_actions_version | The Terraform version to install and execute. If set to `latest`, the latest stable version will be used. | `Yes` |
84+
| tg_actions_version | The Terragrunt version to install and execute. If set to `latest`, the latest stable version will be used. | `Yes` |
85+
| tf_actions_cli_credentials_hostname | Hostname for the CLI credentials file. Defaults to `app.terraform.io`. | `No` |
86+
| tf_actions_cli_credentials_token | Token for the CLI credentials file. | `No` |
87+
| tf_actions_comment | Whether or not to comment on GitHub pull requests. Defaults to `true`. | `No` |
88+
| tf_actions_working_dir | The working directory to change into before executing Terragrunt subcommands. Defaults to the root of the GitHub repository. | `No` |
89+
| tf_actions_fmt_write | Whether or not to write `fmt` changes to source files. Defaults to `false`. | `No` |
8290

8391
## Outputs
8492

8593
Outputs are used to pass information to subsequent GitHub Actions steps.
8694

87-
* `tf_actions_output` - The Terraform outputs in (stringified) JSON format.
88-
* `tf_actions_plan_has_changes` - `'true'` if the Terraform plan contained changes, otherwise `'false'`.
89-
* `tf_actions_plan_output` - The Terraform plan output.
90-
* `tf_actions_fmt_written` - Whether or not the Terraform formatting from `fmt` was written to source files.
95+
| Output Name | Description |
96+
|:----------------------------|:---------------------------------------------------------------------------------|
97+
| tf_actions_output | The Terragrunt outputs in (stringified) JSON format. |
98+
| tf_actions_plan_has_changes | `'true'` if the Terragrunt plan contained changes, otherwise `'false'`. |
99+
| tf_actions_plan_output | The Terragrunt plan output. |
100+
| tf_actions_fmt_written | Whether or not the Terragrunt formatting from `fmt` was written to source files. |
91101

92102
## Secrets
93103

@@ -112,3 +122,5 @@ The usual [Terraform environment variables](https://www.terraform.io/docs/comman
112122
* `TF_WORKSPACE`
113123

114124
Other environment variables may be configured to pass data into Terraform. If the data is sensitive, consider using [secrets](#secrets) instead.
125+
126+
**This is a fork of [Terraform Github Actions](https://github.com/hashicorp/terraform-github-actions).**

action.yml

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
name: 'Terraform GitHub Actions'
2-
description: 'Runs Terraform commands via GitHub Actions.'
3-
author: 'HashiCorp, Inc. Terraform Team <[email protected]>'
1+
name: 'Terragrunt GitHub Actions'
2+
description: 'Runs Terragrunt commands via GitHub Actions.'
3+
author: 'HashiCorp, Inc. Terraform Team <[email protected]>'
44
branding:
5-
icon: 'terminal'
5+
icon: 'cloud'
66
color: 'purple'
77
inputs:
88
tf_actions_subcommand:
9-
description: 'Terraform subcommand to execute.'
9+
description: 'Terraform or Terragrunt subcommand to execute.'
1010
required: true
1111
tf_actions_version:
1212
description: 'Terraform version to install.'
@@ -25,20 +25,20 @@ inputs:
2525
description: 'Whether or not to comment on pull requests.'
2626
default: true
2727
tf_actions_working_dir:
28-
description: 'Terraform working directory.'
28+
description: 'Terragrunt working directory.'
2929
default: '.'
3030
tf_actions_fmt_write:
31-
description: 'Write Terraform fmt changes to source files.'
31+
description: 'Write Terragrunt fmt changes to source files.'
3232
default: false
3333
outputs:
3434
tf_actions_output:
35-
description: 'The Terraform outputs in JSON format.'
35+
description: 'The Terragrunt outputs in JSON format.'
3636
tf_actions_plan_has_changes:
37-
description: 'Whether or not the Terraform plan contained changes.'
37+
description: 'Whether or not the Terragrunt plan contained changes.'
3838
tf_actions_plan_output:
39-
description: 'The Terraform plan output.'
39+
description: 'The Terragrunt plan output.'
4040
tf_actions_fmt_written:
41-
description: 'Whether or not the Terraform formatting was written to source files.'
41+
description: 'Whether or not the Terragrunt formatting was written to source files.'
4242
runs:
4343
using: 'docker'
4444
image: './Dockerfile'

examples/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Examples
22

3-
Here are some examples showing common workflows using Terraform GitHub Actions.
3+
Here are some examples showing common workflows using Terragrunt GitHub Actions.

examples/arguments.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ Arguments can be passed to each subcommand in two ways.
44

55
## Using Arguments
66

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.
7+
GitHub Actions supports an `args` attribute that will pass arguments to the Terragrunt subcommand. Using this `args` attribute will place the arguments at the end of the entire `terragrunt` 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 `terragrunt init` command.
88

99
```yaml
10-
name: 'Terraform GitHub Actions'
10+
name: 'Terragrunt GitHub Actions'
1111
on:
1212
- pull_request
1313
jobs:
14-
terraform:
15-
name: 'Terraform'
14+
terragrunt:
15+
name: 'Terragrunt'
1616
runs-on: ubuntu-latest
1717
steps:
1818
- name: 'Checkout'
1919
uses: actions/checkout@master
20-
- name: 'Terraform Init'
21-
uses: hashicorp/terraform-github-actions@master
20+
- name: 'Terragrunt Init'
21+
uses: hashicorp/terragrunt-github-actions@master
2222
with:
2323
tf_actions_version: 0.12.13
2424
tf_actions_subcommand: 'init'
@@ -32,21 +32,21 @@ jobs:
3232
3333
## Using Environment Variables
3434
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.
35+
Terragrunt 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 `terragrunt init` command.
3636

3737
```yaml
38-
name: 'Terraform GitHub Actions'
38+
name: 'Terragrunt GitHub Actions'
3939
on:
4040
- pull_request
4141
jobs:
42-
terraform:
43-
name: 'Terraform'
42+
terragrunt:
43+
name: 'Terragrunt'
4444
runs-on: ubuntu-latest
4545
steps:
4646
- name: 'Checkout'
4747
uses: actions/checkout@master
48-
- name: 'Terraform Init'
49-
uses: hashicorp/terraform-github-actions@master
48+
- name: 'Terragrunt Init'
49+
uses: hashicorp/terragrunt-github-actions@master
5050
with:
5151
tf_actions_version: 0.12.13
5252
tf_actions_subcommand: 'init'

examples/backends.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
# Terraform Backends
1+
# Terragrunt Backends
22

3-
Terraform GitHub Actions supports initializing a `backend` block using the `-backend-config` option.
3+
Terragrunt GitHub Actions supports initializing a `backend` block using the `-backend-config` option.
44

55
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.
66

77
```yaml
8-
name: 'Terraform GitHub Actions'
8+
name: 'Terragrunt GitHub Actions'
99
on:
1010
- pull_request
1111
jobs:
12-
terraform:
13-
name: 'Terraform'
12+
terragrunt:
13+
name: 'Terragrunt'
1414
runs-on: ubuntu-latest
1515
steps:
1616
- name: 'Checkout'
1717
uses: actions/checkout@master
18-
- name: 'Terraform Init'
19-
uses: hashicorp/terraform-github-actions@master
18+
- name: 'Terragrunt Init'
19+
uses: hashicorp/terragrunt-github-actions@master
2020
with:
2121
tf_actions_version: 0.12.13
2222
tf_actions_subcommand: 'init'

examples/credentials-file.md

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
1-
# Terraform CLI Credentials File
1+
# Terragrunt CLI Credentials File
22

33
The Terraform CLI credentials file is used to authenticate to Terraform Cloud/Enterprise. This is useful if the Terraform configuration contains many `terraform_remote_state` data sources that read from the same Terraform Cloud/Enterprise instance or if the configuration uses modules located in the Private Module Registry.
44

55
This example shows how to pass the hostname and token needed to create the CLI credentials file.
66

77
```yaml
8-
name: 'Terraform GitHub Actions'
8+
name: 'Terragrunt GitHub Actions'
99
on:
1010
- pull_request
1111
jobs:
1212
terraform:
13-
name: 'Terraform'
13+
name: 'Terragrunt'
1414
runs-on: ubuntu-latest
1515
steps:
1616
- name: 'Checkout'
1717
uses: actions/checkout@master
18-
- name: 'Terraform Init'
19-
uses: hashicorp/terraform-github-actions@master
18+
- name: 'Terragrunt Init'
19+
uses: hashicorp/terragrunt-github-actions@master
2020
with:
2121
tf_actions_version: 0.12.13
22+
tg_actions_version: 'latest'
2223
tf_actions_subcommand: 'init'
2324
tf_actions_working_dir: '.'
2425
tf_actions_comment: true
2526
tf_actions_cli_credentials_hostname: app.terraform.io
2627
tf_actions_cli_credentials_token: ${{ secrets.TF_API_TOKEN }}
2728
env:
2829
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29-
- name: 'Terraform Plan'
30-
uses: hashicorp/terraform-github-actions@master
30+
- name: 'Terragrunt Plan'
31+
uses: hashicorp/terragrunt-github-actions@master
3132
with:
3233
tf_actions_version: 0.12.13
34+
tg_actions_version: 'latest'
3335
tf_actions_subcommand: 'plan'
3436
tf_actions_working_dir: '.'
3537
```

examples/output.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
# Terraform Output
1+
# Terragrunt Output
22

33
If you need the outputs of your Terraform configuration later in your GitHub Actions workflow, you can use the `output` subcommand.
44

55
```yaml
6-
name: 'Terraform GitHub Actions'
6+
name: 'Terragrunt GitHub Actions'
77
on:
88
- push
99
jobs:
1010
terraform:
11-
name: 'Terraform'
11+
name: 'Terragrunt'
1212
runs-on: ubuntu-latest
1313
steps:
1414
- name: 'Checkout'
@@ -18,6 +18,7 @@ jobs:
1818
uses: hashicorp/terraform-github-actions@master
1919
with:
2020
tf_actions_version: 0.12.13
21+
tg_actions_version: 'latest'
2122
tf_actions_subcommand: 'output'
2223
tf_actions_working_dir: '.'
2324
- name: 'Use Terraform Output'

examples/tainting.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
# Terraform Tainting
1+
# Terragrunt Tainting
22

33
Resources to taint can be specified using the `args` with option.
44

55
```yaml
6-
name: 'Terraform GitHub Actions'
6+
name: 'Terragrunt GitHub Actions'
77
on:
88
- pull_request
99
jobs:
1010
terraform:
11-
name: 'Terraform'
11+
name: 'Terragrunt'
1212
runs-on: ubuntu-latest
1313
steps:
1414
- name: 'Checkout'
1515
uses: actions/checkout@master
16-
- name: 'Terraform Init'
16+
- name: 'Terragrunt Init'
1717
uses: hashicorp/terraform-github-actions@master
1818
with:
1919
tf_actions_version: 0.12.13
20+
tg_actions_version: 'latest'
2021
tf_actions_subcommand: 'init'
2122
tf_actions_working_dir: '.'
2223
tf_actions_comment: true
@@ -27,6 +28,7 @@ jobs:
2728
uses: hashicorp/terraform-github-actions@master
2829
with:
2930
tf_actions_version: 0.12.13
31+
tg_actions_version: 'latest'
3032
tf_actions_subcommand: 'taint'
3133
tf_actions_working_dir: '.'
3234
tf_actions_comment: true

0 commit comments

Comments
 (0)