Skip to content

Commit aced65b

Browse files
committed
Update docs for state-locked, lock-info and unlock-state
1 parent 5731513 commit aced65b

File tree

4 files changed

+75
-71
lines changed

4 files changed

+75
-71
lines changed

terraform-apply/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,28 @@ These input values must be the same as any `terraform-plan` for the same configu
222222

223223
- `apply-failed` - The Terraform apply operation failed.
224224
- `plan-changed` - The approved plan is no longer accurate, so the apply will not be attempted.
225+
- `state-locked` - The Terraform state lock could not be obtained because it was already locked.
225226

226227
If the job fails for any other reason this will not be set.
227228
This can be used with the Actions expression syntax to conditionally run steps.
228229

230+
* `lock-info`
231+
232+
When the job outcome is `failure` and the failure-reason is `state-locked`, this output will be set.
233+
234+
It is a json object containing any available state lock information and typically has the form:
235+
```json
236+
{
237+
"ID": "838fbfde-c5cd-297f-84a4-d7578b4a4880",
238+
"Path": "terraform-github-actions/test-unlock-state",
239+
"Operation": "OperationTypeApply",
240+
"Who": "root@e9d43b0c6478",
241+
"Version": "1.3.7",
242+
"Created": "2023-01-28 00:16:41.560904373 +0000 UTC",
243+
"Info": ""
244+
}
245+
```
246+
229247
* `run_id`
230248

231249
If the root module uses the `remote` or `cloud` backend in remote execution mode, this output will be set to the remote run id.

terraform-destroy-workspace/README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,30 @@ This action uses the `terraform destroy` command to destroy all resources in a t
101101

102102
* `failure-reason`
103103

104-
When the job outcome is `failure` because the terraform destroy operation failed, this is set to `destroy-failed`.
104+
When the job outcome is `failure`, this output may be set. The value may be one of:
105+
106+
- `destroy-failed` - The Terraform destroy operation failed.
107+
- `state-locked` - The Terraform state lock could not be obtained because it was already locked.
108+
105109
If the job fails for any other reason this will not be set.
106-
This can be used with the Actions expression syntax to conditionally run a step when the destroy fails.
110+
This can be used with the Actions expression syntax to conditionally run a steps.
111+
112+
* `lock-info`
113+
114+
When the job outcome is `failure` and the failure-reason is `state-locked`, this output will be set.
115+
116+
It is a json object containing any available state lock information and typically has the form:
117+
```json
118+
{
119+
"ID": "838fbfde-c5cd-297f-84a4-d7578b4a4880",
120+
"Path": "terraform-github-actions/test-unlock-state",
121+
"Operation": "OperationTypeApply",
122+
"Who": "root@e9d43b0c6478",
123+
"Version": "1.3.7",
124+
"Created": "2023-01-28 00:16:41.560904373 +0000 UTC",
125+
"Info": ""
126+
}
127+
```
107128

108129
## Environment Variables
109130

terraform-destroy/README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,30 @@ This action uses the `terraform destroy` command to destroy all resources in a t
108108

109109
* `failure-reason`
110110

111-
When the job outcome is `failure` because the terraform destroy operation failed, this is set to `destroy-failed`.
111+
When the job outcome is `failure`, this output may be set. The value may be one of:
112+
113+
- `destroy-failed` - The Terraform destroy operation failed.
114+
- `state-locked` - The Terraform state lock could not be obtained because it was already locked.
115+
112116
If the job fails for any other reason this will not be set.
113-
This can be used with the Actions expression syntax to conditionally run a step when the destroy fails.
117+
This can be used with the Actions expression syntax to conditionally run a steps.
118+
119+
* `lock-info`
120+
121+
When the job outcome is `failure` and the failure-reason is `state-locked`, this output will be set.
122+
123+
It is a json object containing any available state lock information and typically has the form:
124+
```json
125+
{
126+
"ID": "838fbfde-c5cd-297f-84a4-d7578b4a4880",
127+
"Path": "terraform-github-actions/test-unlock-state",
128+
"Operation": "OperationTypeApply",
129+
"Who": "root@e9d43b0c6478",
130+
"Version": "1.3.7",
131+
"Created": "2023-01-28 00:16:41.560904373 +0000 UTC",
132+
"Info": ""
133+
}
134+
```
114135

115136
## Environment Variables
116137

terraform-unlock-state/README.md

Lines changed: 11 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -2,75 +2,35 @@
22

33
This is one of a suite of terraform related actions - find them at [dflook/terraform-github-actions](https://github.com/dflook/terraform-github-actions).
44

5-
This actions is intially planned to manually unlock the state for the defined configuration.
6-
7-
The `GITHUB_TOKEN` environment variable must be set for the PR comment to be added.
8-
The action can be run on other events, which prints the plan to the workflow log.
5+
Force unlocks a Terraform remote state.
96

107
## Inputs
118

129
* `path`
1310

14-
Path to the terraform root module to apply
11+
Path to the terraform root module that defines the remote state to unlock
1512

1613
- Type: string
1714
- Optional
1815
- Default: The action workspace
1916

2017
* `workspace`
2118

22-
Terraform workspace to run
19+
Terraform workspace to unlock the remote state for
2320

2421
- Type: string
2522
- Optional
2623
- Default: `default`
2724

2825
* `lock_id`
2926

30-
Lock id from the defined configuration
27+
The ID of the state lock to release
3128

3229
- Type: string
3330
- Required
3431

3532
## Environment Variables
3633

37-
* `GITHUB_TOKEN`
38-
39-
The GitHub authorization token to use to create comments on a PR.
40-
The token provided by GitHub Actions can be used - it can be passed by
41-
using the `${{ secrets.GITHUB_TOKEN }}` expression, e.g.
42-
43-
```yaml
44-
env:
45-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46-
```
47-
48-
The token provided by GitHub Actions will work with the default permissions.
49-
The minimum permissions are `pull-requests: write`.
50-
It will also likely need `contents: read` so the job can checkout the repo.
51-
52-
You can also use any other App token that has `pull-requests: write` permission.
53-
54-
You can use a fine-grained Personal Access Token which has repository permissions:
55-
- Read access to metadata
56-
- Read and Write access to pull requests
57-
58-
You can also use a classic Personal Access Token which has the `repo` scope.
59-
60-
The GitHub user or app that owns the token will be the PR comment author.
61-
62-
- Type: string
63-
- Optional
64-
65-
* `TERRAFORM_ACTIONS_GITHUB_TOKEN`
66-
67-
When this is set it is used instead of `GITHUB_TOKEN`, with the same behaviour.
68-
The GitHub terraform provider also uses the `GITHUB_TOKEN` environment variable,
69-
so this can be used to make the github actions and the terraform provider use different tokens.
70-
71-
- Type: string
72-
- Optional
73-
7434
* `TERRAFORM_CLOUD_TOKENS`
7535

7636
API tokens for terraform cloud hosts, of the form `<host>=<token>`. Multiple tokens may be specified, one per line.
@@ -133,22 +93,6 @@ The action can be run on other events, which prints the plan to the workflow log
13393
- Type: string
13494
- Optional
13595

136-
* `TF_PLAN_COLLAPSE_LENGTH`
137-
138-
When PR comments are enabled, the terraform output is included in a collapsable pane.
139-
140-
If a terraform plan has fewer lines than this value, the pane is expanded
141-
by default when the comment is displayed.
142-
143-
```yaml
144-
env:
145-
TF_PLAN_COLLAPSE_LENGTH: 30
146-
```
147-
148-
- Type: integer
149-
- Optional
150-
- Default: 10
151-
15296
* `TERRAFORM_PRE_RUN`
15397

15498
A set of commands that will be ran prior to `terraform init`. This can be used to customise the environment before running terraform.
@@ -181,26 +125,26 @@ on:
181125
workflow_dispatch:
182126
inputs:
183127
path:
184-
description: "Path to the terraform files configuration"
128+
description: "Path to the terraform root module"
185129
required: true
186130
lock_id:
187131
description: "Lock ID to be unlocked"
188132
required: true
189133
134+
env:
135+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
136+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
137+
190138
jobs:
191139
unlock:
192-
name: Setup and unlock
140+
name: Unlock
193141
runs-on: ubuntu-latest
194-
env:
195-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
196142
steps:
197143
- name: Checkout current branch
198144
uses: actions/checkout@v3
199-
with:
200-
fetch-depth: 0
201145
202146
- name: Terraform Unlock
203-
uses: patricktalmeida/terraform-github-actions/terraform-unlock-state@add-unlock-state
147+
uses: dflook/terraform-unlock-state@v1
204148
with:
205149
path: ${{ github.event.inputs.path }}
206150
lock_id: ${{ github.event.inputs.lock_id }}

0 commit comments

Comments
 (0)