Skip to content
This repository has been archived by the owner on Jul 5, 2023. It is now read-only.

(feature) Updates starter workflow to use new yaml format for GitHub Actions v2 #942

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 33 additions & 48 deletions content/source/docs/github-actions/getting-started/index.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,54 +31,39 @@ Terraform's GitHub Actions on new and updated pull requests.

1. Replace the default workflow with the following:

```hcl
workflow "Terraform" {
resolves = "terraform-plan"
on = "pull_request"
}

action "filter-to-pr-open-synced" {
uses = "actions/bin/filter@master"
args = "action 'opened|synchronize'"
}

action "terraform-fmt" {
uses = "hashicorp/terraform-github-actions/fmt@v<latest version>"
needs = "filter-to-pr-open-synced"
secrets = ["GITHUB_TOKEN"]
env = {
TF_ACTION_WORKING_DIR = "."
}
}

action "terraform-init" {
uses = "hashicorp/terraform-github-actions/init@v<latest version>"
needs = "terraform-fmt"
secrets = ["GITHUB_TOKEN"]
env = {
TF_ACTION_WORKING_DIR = "."
}
}

action "terraform-validate" {
uses = "hashicorp/terraform-github-actions/validate@v<latest version>"
needs = "terraform-init"
secrets = ["GITHUB_TOKEN"]
env = {
TF_ACTION_WORKING_DIR = "."
}
}

action "terraform-plan" {
uses = "hashicorp/terraform-github-actions/plan@v<latest version>"
needs = "terraform-validate"
secrets = ["GITHUB_TOKEN"]
env = {
TF_ACTION_WORKING_DIR = "."
# If you're using Terraform workspaces, set this to the workspace name.
TF_ACTION_WORKSPACE = "default"
}
}
```yaml
on: pull_request
name: Terraform
jobs:
filter-to-pr-open-synced:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: filter-to-pr-open-synced
uses: actions/bin/filter@master
with:
args: action 'opened|synchronize'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This step is outdated in the YAML syntax. We've added event filtering directly to the YAML. You can achieve this by movig the types up into the on trigger above. In this case:

on:
  pull_request:
    types: [ opened, synchronize ]

However, the default triggers for on: pull_request are actually opened, synchronized, reopened which seem like reasonable defaults here, too, so you might just remove this step and not update the on: pull_request line at all.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally with the latest release of 0.4.2, you no longer have to run these checks exclusively on PRs. You can just run it on a normal push

- name: terraform-fmt
uses: hashicorp/terraform-github-actions/fmt@v<latest version>
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TF_ACTION_WORKING_DIR: .
- name: terraform-init
uses: hashicorp/terraform-github-actions/init@v<latest version>
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TF_ACTION_WORKING_DIR: .
- name: terraform-validate
uses: hashicorp/terraform-github-actions/validate@v<latest version>
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TF_ACTION_WORKING_DIR: .
- name: terraform-plan
uses: hashicorp/terraform-github-actions/plan@v<latest version>
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TF_ACTION_WORKING_DIR: .
TF_ACTION_WORKSPACE: default
```
1. Find the latest version from [https://github.com/hashicorp/terraform-github-actions/releases](https://github.com/hashicorp/terraform-github-actions/releases)
and replace all instances of `@v<latest version>`. For example: `uses = "hashicorp/terraform-github-actions/plan@v3.0"`.
Expand Down