|
1 | 1 | # Terraform GitHub Actions |
2 | 2 |
|
3 | | -Terraform GitHub Actions allow you to run Terraform commands within GitHub Actions. |
| 3 | +Terraform GitHub Actions allow you to execute Terraform commands within GitHub Actions. |
4 | 4 |
|
5 | 5 | 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. |
6 | 6 |
|
| 7 | +Terraform GitHub Actions are a single GitHub Action that executes different Terraform subcommands depending on the content of the GitHub Actions YAML file. |
| 8 | + |
7 | 9 | ## Success Criteria |
8 | 10 |
|
9 | 11 | An exit code of `0` is considered a successful execution. |
10 | 12 |
|
11 | 13 | ## Usage |
12 | 14 |
|
13 | | -The most common use case is to run `terraform fmt`, `terraform init`, `terraform validate`, and `terraform plan` on a pull request. A comment will be posted to the pull request depending on the output of the Terraform command being executed. |
| 15 | +The most common workflow is to run `terraform fmt`, `terraform init`, `terraform validate`, and `terraform plan` 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. |
14 | 16 |
|
15 | 17 | ```yaml |
16 | | -name: 'Terraform Pull Request Workflow' |
| 18 | +name: 'Terraform GitHub Actions' |
17 | 19 | on: |
18 | 20 | - pull_request |
19 | 21 | jobs: |
20 | | - example: |
21 | | - name: 'Terraform Actions' |
| 22 | + terraform: |
| 23 | + name: 'Terraform' |
22 | 24 | runs-on: ubuntu-latest |
23 | 25 | steps: |
24 | 26 | - name: 'Checkout' |
@@ -61,36 +63,38 @@ jobs: |
61 | 63 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
62 | 64 | ``` |
63 | 65 |
|
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. |
| 66 | +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. |
65 | 67 |
|
66 | 68 | ## Inputs |
67 | 69 |
|
68 | | -| Name | Required | Default | Description | |
69 | | -|--------------------------|----------|---------|---------------------------------------------------------------------------------------------------| |
70 | | -| `tf_actions_version` | `true` | | Terraform version to install and execute. | |
71 | | -| `tf_actions_subcommand` | `true` | | Terraform subcommand to execute. Valid values are `fmt`, `init`, `validate`, `plan`, and `apply`. | |
72 | | -| `tf_actions_working_dir` | `false` | `.` | The working directory to change into before executing Terraform commands. | |
73 | | -| `tf_actions_comment` | `false` | `true` | Whether or not to comment on pull requests. | |
| 70 | +Inputs configure Terraform GitHub Actions to perform different actions. |
| 71 | + |
| 72 | +* `tf_actions_version` - (Required) The Terraform version to install and execute. |
| 73 | +* `tf_actions_subcommand` - (Required) The Terraform subcommand to execute. Valid values are `fmt`, `init`, `validate`, `plan`, and `apply`. |
| 74 | +* `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. |
| 75 | +* `tf_actions_comment` - (Optional) Whether or not to comment on GitHub pull requests. Defaults to `true`. |
74 | 76 |
|
75 | 77 | ## Outputs |
76 | 78 |
|
77 | | -| Name | Description | |
78 | | -|-------------------------------|------------------------------------------------------| |
79 | | -| `tf_actions_plan_has_changes` | Whether or not the Terraform plan contained changes. | |
| 79 | +Outputs are used to pass information to subsequent GitHub Actions steps. |
| 80 | + |
| 81 | +* `tf_actions_plan_has_changes` - Whether or not the Terraform plan contained changes. |
80 | 82 |
|
81 | 83 | ## Secrets |
82 | 84 |
|
83 | | -| Name | Description | |
84 | | -|--------------------------|----------------------------------------------------------------------------------------------------------------------| |
85 | | -| `GITHUB_TOKEN` | The GitHub API token used to post comments to pull requests. Not required if `tf_actions_comment` is set to `false`. | |
| 85 | +Secrets are similar to inputs except that they are encrypted and only used by GitHub Actions. It's a convenient way to keep sensitive data out of the GitHub Actions workflow YAML file. |
86 | 86 |
|
87 | | -Other secrets may be needed to authenticate with Terraform backends and providers. |
| 87 | +* `GITHUB_TOKEN` - (Optional) The GitHub API token used to post comments to pull requests. Not required if the `tf_actions_comment` input is set to `false`. |
88 | 88 |
|
89 | | -**WARNING:** These secrets could be exposed if the action is executed on a malicious Terraform file. To avoid this, it is recommended to not use this action on public repos or repos where untrusted users can submit pull requests. |
| 89 | +Other secrets may be needed to authenticate with Terraform backends and providers. |
| 90 | + |
| 91 | +**WARNING:** These secrets could be exposed if the action is executed on a malicious Terraform file. To avoid this, it is recommended not to use these Terraform GitHub Actions on repositories where untrusted users can submit pull requests. |
90 | 92 |
|
91 | 93 | ## Environment Variables |
92 | 94 |
|
93 | | -The usual [Terraform environment variables](https://www.terraform.io/docs/commands/environment-variables.html) are supported. Here are the environment variables that might be the most beneficial. |
| 95 | +Environment variables are exported in the environment where the Terraform GitHub Actions are executed. This allows a user to modify the behavior of certain GitHub Actions. |
| 96 | + |
| 97 | +The usual [Terraform environment variables](https://www.terraform.io/docs/commands/environment-variables.html) are supported. Here are a few of the more commonly used environment variables. |
94 | 98 |
|
95 | 99 | * [`TF_LOG`](https://www.terraform.io/docs/commands/environment-variables.html#tf_log) |
96 | 100 | * [`TF_VAR_name`](https://www.terraform.io/docs/commands/environment-variables.html#tf_var_name) |
|
0 commit comments