Skip to content

Commit

Permalink
feat: support the option to use -lock=false during Terraform plan (#10
Browse files Browse the repository at this point in the history
)
  • Loading branch information
tchupp committed Mar 2, 2022
1 parent 41944bd commit 19b4775
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,42 @@ jobs:
run: |
terraform apply -auto-approve
```

### Disable locking for `terraform plan`

In some situation, you want to disabling workspace locking when running `terraform plan`.

In your `.github/workflows/terraform.yml` file you would have:
```yaml
on:
push:
branches:
- main
pull_request:
branches:
- main
paths:
- '**.tf'
- '.github/workflows/terraform.yml'
jobs:
terraform:
name: "Terraform"
runs-on: ubuntu-latest
env:
TF_WORKSPACE: "default"
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: ~1.0.0
cli_config_credentials_token: ${{ secrets.TF_TOKEN }}
- uses: tchupp/actions-terraform-pr@v1
with:
apply-branch: "main"
lock-for-plan: false
```
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ inputs:
description: "Custom title for the PR comment. Defaults to '${TF_WORKSPACE}' if not specified."
required: false
default: ""
lock-for-plan:
description: "Should we use a workspace lock for the `terraform plan`? https://www.terraform.io/language/state/locking"
required: false
default: true
runs:
using: "composite"
steps:
Expand Down Expand Up @@ -73,7 +77,7 @@ runs:
run: |
if [[ '${{ github.ref }}' != 'refs/heads/${{ inputs.apply-branch }}' ]]; then
cd ${{ inputs.path }}
if terraform plan -no-color; then
if terraform plan -no-color -lock=${{ inputs.lock-for-plan }}; then
echo "::set-output name=plan-outcome::success"
else
echo "::set-output name=plan-outcome::failure"
Expand Down

0 comments on commit 19b4775

Please sign in to comment.