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

Commit 6862e45

Browse files
authored
Refactor into single GitHub Action (#88)
1 parent c91ce35 commit 6862e45

File tree

48 files changed

+951
-509
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+951
-509
lines changed

CHANGELOG.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Changelog
2+
3+
## v0.5.0
4+
5+
### Added
6+
7+
* Added new YAML syntax for GitHub Actions.
8+
9+
### Changed
10+
11+
* Completely refactored the codebase into one GitHub Action. Please refer to the README for current usage.
12+
13+
### Deprecated
14+
15+
N/A
16+
17+
### Removed
18+
19+
* Removed all `TF_ACTION` environment variables. Please refer to the README for current usage.
20+
* Removed HashiCorp Configuration Language (HCL) syntax.
21+
22+
### Fixed
23+
24+
* The actions now use the new YAML syntax. ([#67](https://github.com/hashicorp/terraform-github-actions/issues/67))
25+
* Added support for Terraform 0.11.14. ([#42](https://github.com/hashicorp/terraform-github-actions/issues/67))
26+
* Comments will not be posted to pull requests when `terraform plan` contains no changes. ([#29](https://github.com/hashicorp/terraform-github-actions/issues/67))
27+
* Added ability to specify a Terraform version to use. ([#23](https://github.com/hashicorp/terraform-github-actions/issues/67))
28+
29+
### Security
30+
31+
N/A

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM alpine:3
2+
3+
RUN ["/bin/sh", "-c", "apk add --update --no-cache bash ca-certificates curl git jq openssh"]
4+
5+
RUN ["bin/sh", "-c", "mkdir -p /src"]
6+
7+
COPY ["src", "/src/"]
8+
9+
ENTRYPOINT ["/src/main.sh"]

README.md

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,50 @@
11
# Terraform GitHub Actions
2-
These official Terraform GitHub Actions allow you to run `terraform fmt`, `validate`, `plan` and `apply` on your pull requests to help you review, validate and apply Terraform changes.
32

4-
## Getting Started
5-
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/).
3+
Terraform GitHub Actions allow you to run Terraform commands within GitHub Actions.
64

7-
## Actions
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.
86

9-
### Fmt Action
10-
Runs `terraform fmt` and comments back if any files are not formatted correctly.
11-
<img src="./assets/fmt.png" alt="Terraform Fmt Action" width="80%" />
7+
## Success Criteria
128

13-
### Validate Action
14-
Runs `terraform validate` and comments back on error.
15-
<img src="./assets/validate.png" alt="Terraform Validate Action" width="80%" />
9+
An exit code of `0` is considered a successful execution.
1610

17-
### Plan Action
18-
Runs `terraform plan` and comments back with the output.
19-
<img src="./assets/plan.png" alt="Terraform Plan Action" width="80%" />
11+
## Usage
2012

21-
### Apply Action
22-
Runs `terraform apply` and comments back with the output.
23-
<img src="./assets/apply.png" alt="Terraform Apply Action" width="80%" />
13+
Please refer to the examples within the `examples` directory for usage.
14+
15+
## Inputs
16+
17+
| Name | Required | Default | Description |
18+
|--------------------------|----------|---------|---------------------------------------------|
19+
| `tf_actions_version` | `true` | | Terraform version to install. |
20+
| `tf_actions_subcommand` | `true` | | Terraform subcommand to execute. |
21+
| `tf_actions_working_dir` | `false` | `.` | Terraform working directory. |
22+
| `tf_actions_comment` | `false` | `true` | Whether or not to comment on pull requests. |
23+
24+
## Outputs
25+
26+
| Name | Description |
27+
|-------------------------------|------------------------------------------------------|
28+
| `tf_actions_plan_has_changes` | Whether or not the Terraform plan contained changes. |
29+
30+
## Secrets
31+
32+
| Name | Description |
33+
|--------------------------|----------------------------------------------------------------------------------------------------------------------|
34+
| `GITHUB_TOKEN` | The GitHub API token used to post comments to pull requests. Not required if `tf_actions_comment` is set to `false`. |
35+
36+
Other secrets may be needed to authenticate with Terraform backends and providers.
37+
38+
**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.
39+
40+
## Environment Variables
41+
42+
The usual [Terraform environment variables](https://www.terraform.io/docs/commands/environment-variables.html) are supported. Here are the environments variables that might be the most beneficial.
43+
44+
* [`TF_LOG`](https://www.terraform.io/docs/commands/environment-variables.html#tf_log)
45+
* [`TF_VAR_name`](https://www.terraform.io/docs/commands/environment-variables.html#tf_var_name)
46+
* [`TF_CLI_ARGS`](https://www.terraform.io/docs/commands/environment-variables.html#tf_cli_args-and-tf_cli_args_name)
47+
* [`TF_CLI_ARGS_name`](https://www.terraform.io/docs/commands/environment-variables.html#tf_cli_args-and-tf_cli_args_name)
48+
* `TF_WORKSPACE`
49+
50+
Other environment variables may be configured to pass data into Terraform backends and providers. If the data is sensitive, consider using [secrets](#secrets) instead.

action.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: 'Terraform GitHub Actions'
2+
description: 'Runs Terraform commands via GitHub Actions.'
3+
author: 'HashiCorp, Inc. Terraform Team <[email protected]>'
4+
branding:
5+
icon: 'terminal'
6+
color: 'purple'
7+
inputs:
8+
tf_actions_version:
9+
description: 'Terraform version to install.'
10+
required: true
11+
tf_actions_subcommand:
12+
description: 'Terraform subcommand to execute.'
13+
required: true
14+
tf_actions_working_dir:
15+
description: 'Terraform working directory.'
16+
default: '.'
17+
tf_actions_comment:
18+
description: 'Whether or not to comment on pull requests.'
19+
default: true
20+
outputs:
21+
tf_actions_plan_has_changes:
22+
description: 'Whether or not the Terraform plan contained changes.'
23+
runs:
24+
using: 'docker'
25+
image: './Dockerfile'

apply/Dockerfile

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

apply/README.md

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

apply/entrypoint.sh

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

assets/apply.png

-32.8 KB
Binary file not shown.

assets/fmt.png

-73.8 KB
Binary file not shown.

assets/plan.png

-133 KB
Binary file not shown.

0 commit comments

Comments
 (0)