Skip to content

Commit e514b06

Browse files
committed
Migration script: performance: do not take a lock
It is useless as long as the operations are strictly on a local state file.
1 parent 511c122 commit e514b06

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
### Changes
2020

2121
- Migration script: do not print any more the count `>>> 1/N`, because each time N changed, this was causing N spurious diffs, hiding the real elements that changed. The `terravalet_output_format` is now 2.
22+
- Migration script: do not take a lock; it is useless as long as the operations are strictly on a local state file. This speeds up the runtime.
2223

2324
### New
2425

main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@ func script(matches map[string]string, statePath string, out io.Writer) error {
175175
fmt.Fprintf(out, "# This script will move %d items.\n\n", len(matches))
176176
fmt.Fprintf(out, "set -e\n\n")
177177

178-
cmd := fmt.Sprintf("terraform state mv -state=%s", statePath)
178+
// -lock=false greatly speeds up operations when the state has many elements
179+
// and is safe as long as we use -state=FILE, since this keeps operations
180+
// strictly local, without considering the configured backend.
181+
cmd := fmt.Sprintf("terraform state mv -lock=false -state=%s", statePath)
179182

180183
// Go maps are unordered. We want instead a stable iteration order, to make it
181184
// possible to compare scripts.

testdata/001_synthetic.down.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66

77
set -e
88

9-
terraform state mv -state=local.tfstate \
9+
terraform state mv -lock=false -state=local.tfstate \
1010
'aws_batch_compute_environment.concourse_gpu_batch' \
1111
'module.ci.aws_batch_compute_environment.concourse_gpu_batch'
1212

13-
terraform state mv -state=local.tfstate \
13+
terraform state mv -lock=false -state=local.tfstate \
1414
'aws_instance.bar' \
1515
'module.ci.aws_instance.bar'
1616

17-
terraform state mv -state=local.tfstate \
17+
terraform state mv -lock=false -state=local.tfstate \
1818
'aws_instance.foo["cloud"]' \
1919
'module.ci.aws_instance.foo["cloud"]'
2020

testdata/001_synthetic.up.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66

77
set -e
88

9-
terraform state mv -state=local.tfstate \
9+
terraform state mv -lock=false -state=local.tfstate \
1010
'module.ci.aws_batch_compute_environment.concourse_gpu_batch' \
1111
'aws_batch_compute_environment.concourse_gpu_batch'
1212

13-
terraform state mv -state=local.tfstate \
13+
terraform state mv -lock=false -state=local.tfstate \
1414
'module.ci.aws_instance.bar' \
1515
'aws_instance.bar'
1616

17-
terraform state mv -state=local.tfstate \
17+
terraform state mv -lock=false -state=local.tfstate \
1818
'module.ci.aws_instance.foo["cloud"]' \
1919
'aws_instance.foo["cloud"]'
2020

0 commit comments

Comments
 (0)