Skip to content

Commit

Permalink
Update README and test workflow for v1
Browse files Browse the repository at this point in the history
  • Loading branch information
chroju committed May 31, 2020
1 parent 2ef62df commit 5852423
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 7 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
on:
push:
pull_request:
branches:
- master
Expand All @@ -11,7 +10,7 @@ jobs:
- uses: actions/checkout@v2
- name: check version
id: check
uses: chroju/terraform-cloud-updater@master
uses: chroju/terraform-cloud-updater@v1
with:
working_dir: ./test
comment_pr: true
Expand All @@ -27,10 +26,10 @@ jobs:
- uses: actions/checkout@v2
- name: check version
id: check
uses: chroju/terraform-cloud-updater@master
uses: chroju/terraform-cloud-updater@v1
with:
working_dir: ./test
force_update: true
auto_update: true
comment_pr: true
env:
TFE_TOKEN: ${{ secrets.TFE_TOKEN }}
Expand Down
74 changes: 74 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,76 @@
terraform-cloud-updater
======

This action automates the terraform version update of your Terraform cloud workspace, based on the remote config file.

## Usage

This action parses the remote config file and checks which Terraform version is configured in your Terraform cloud workspace. If the latest Terraform version is not set, it will notice. It is also possible to automatically update the latest version.

For example, if you use `. /terraform` directory, including the following remote config file.

```hcl
terraform {
backend "remote" {
hostname = "app.terraform.io"
organization = "sample"
workspaces {
name = "sample"
}
}
required_version = "> 0.12.0, <= 0.12.23"
}
```

GitHub Actions are configuread as follows.

```yaml
on:
push:
pull_request:
branches:
- master

jobs:
tf_cloud_update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: check update
id: check
uses: chroju/terraform-cloud-updater@v1
with:
working_dir: ./terraform
comment_pr: true
env:
TFE_TOKEN: ${{ secrets.TFE_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: result
run: echo "${{ steps.check.outputs.result }}"
if: "${{ steps.check.outputs.is_available_update == 'true' }}"
```
When action finds a new version, it will comment on the pull request. Action will also check for consistency with the required version and will not automatically update to a non-conforming version (In this case, it will not be updated to `0.12.24` ). Sample pull request is [here](https://github.com/chroju/terraform-cloud-updater/pull/17).

## Inputs

* `working_dir` - (Optional) Terraform working directory. Defaults to `./` (root of the GitHub repository) .
* `auto_update` - (Optional) Not only notice, automatically update Terraform Cloud workspace to the latest version compatible with required version. Defaults to `false` .
* `comment_pr` - (Optional) Whether or not to post a comment on GitHub pull requests. If you set it to true, you need to set the `GITHUB_TOKEN` environment variable. Defaults to `false` .

## Outputs

* `is_available_update` - Wherther or not available update ('true' or 'false') .
* `output` - result message (empty if new version is not released) .

## Environment Variables

* `TFE_TOKEN` - (Required) Terraform Cloud API token.
* `GITHUB_TOKEN` - (Optional) The GitHub API token used to post comments to pull requests. Not required if the `comment_pr` input is set to `false` .

## Notes

### Support for Terraform Enterprise

Since Terraform Cloud and Terraform Enterprise have a common API, this action is likely to be available for Terraform Enterprise as well. However, we have not verified the operation using Terraform Enterprise.
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ inputs:
working_dir:
description: "Terraform working directory"
default: "./"
force_update:
description: "Force to update the latest version compatible with required versions"
auto_update:
description: "Whether automatically update Terraform Cloud workspace to the latest version compatible with required version"
default: false
comment_pr:
description: "Whether or not to post a comment on GitHub pull requests"
Expand Down
2 changes: 1 addition & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

function parseInputs {
subcommand="check"
if [[ "${INPUT_FORCE_UPDATE}" == "true" ]]; then
if [[ "${INPUT_AUTO_UPDATE}" == "true" ]]; then
subcommand="update latest"
elif [[ -n "${INPUT_SPECIFIC_VERSION}" ]]; then
subcommand="update ${INPUT_SPECIFIC_VERSION}"
Expand Down

0 comments on commit 5852423

Please sign in to comment.