minamijoyo / tflock Goto Github PK
View Code? Open in Web Editor NEWLock your Terraform state manually
License: MIT License
Lock your Terraform state manually
License: MIT License
Lock should be fail if there is no lock setting.
tflock v0.0.1
lock fails
no error
Given the following configuration
terraform {
backend "s3" {
region = "ap-northeast-1"
bucket = "hoge"
key = "fuga/terraform.tfstate"
// dynamodb_table = "tflock"
}
}
Run tflock
$ tflock
$ echo $?
0
Check terraform plan
$ terraform plan
=> no error
When I run tflock
, I hit the following error:
> terraform init
...
> tflock
Backend reinitialization required. Please run "terraform init".
Reason: Backend configuration changed for "gcs"
The "backend" is the interface that Terraform uses to store state,
perform operations, etc. If this message is showing up, it means that the
Terraform configuration you're using is using a custom configuration for
the Terraform backend.
Changes to backend configurations require reinitialization. This allows
Terraform to set up the new configuration, copy existing state, etc. This is
only done during "terraform init". Please run that command now then try again.
If the change reason above is incorrect, please verify your configuration
hasn't changed and try again. At this point, no changes to your existing
configuration or state have been made.
Error loading the state: Initialization required. Please see the error message above.
Running terraform plan
after the above error still works as well.
Environment info:
We're using the gcs backend with terraform 1.4.6 and used rev 528959cb04c76b71454220b5c9b39aa9ae7f26ba
to build tflock
.
Let me know if I can provide any more details or if I'm doing something obviously wrong.
It would be useful to have an official github release that contained a set of binaries already built and easy to install for endusers.
Using something like https://github.com/mitchellh/gox it is very easy to manage the build.
When i run tflock on terraform scripts i get the following segmentation fault error
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x101143eec]
goroutine 1 [running]:
github.com/hashicorp/terraform/command/views.(*StateLockerHuman).Locking(0x14000061450?)
/Users/kishanb/go/pkg/mod/github.com/hashicorp/terraform@v0.15.1/command/views/state_locker.go:35 +0x1c
github.com/hashicorp/terraform/internal/helper/slowmessage.Do(0x102a5b890?, 0x140006f2a00, 0x1400099fcb8)
/Users/kishanb/go/pkg/mod/github.com/hashicorp/terraform@v0.15.1/internal/helper/slowmessage/slowmessage.go:29 +0xec
github.com/hashicorp/terraform/command/clistate.(*locker).Lock(0x140000613b0, {0x12b7e0f58?, 0x1400094be00}, {0x1020bec6f, 0x6})
/Users/kishanb/go/pkg/mod/github.com/hashicorp/terraform@v0.15.1/command/clistate/state.go:120 +0x248
main.(*LockCommand).Run(0x1400017c700, {0x0?, 0x103a31bc0?, 0x14000164a80?})
/Users/kishanb/Programming/Personal/tflock/main.go:40 +0x188
github.com/mitchellh/cli.(*CLI).Run(0x140000c8c80)
/Users/kishanb/go/pkg/mod/github.com/mitchellh/cli@v1.1.2/cli.go:262 +0x4a8
main.main()
/Users/kishanb/Programming/Personal/tflock/main.go:116 +0x318
$ terraform version
Terraform v1.3.7
on darwin_arm64
To simulate run the tflock
command and run terraform plan
command for this sample terraform file after creating the state bucket and dynamodb table
terraform {
backend "s3" {
bucket = "state-bucket-cc5b487c-a7d8-4751-b436-43f50994e962"
key = "path/file"
region = "us-east-2"
encrypt = true
dynamodb_table = "terraform-state-lock-table"
}
}
resource "aws_s3_bucket" "spike_data_bucket" {
bucket = "spike-data-bucket-cc5b487c-a7d8-4751-b436-43f50994e962"
}
It would be great if the release contained binary artifacts that can be just installed in a target machine. as of now the process involves cloning this repo and running go build.
I highly recommend https://goreleaser.com/ to achieve the same
For an example you can see releases in one of my repository https://github.com/kishaningithub/rdapp/releases
Happy to contribute a PR if you agree with this idea :-)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.