Error: Error acquiring the state lock
terraform plan
やterraform apply
のようなコマンドの実行中に、次のエラーが発生する場合があります。
bash
$ terraform plan
╷
│ Error: Error acquiring the state lock
│
│ Error message: ConditionalCheckFailedException: The conditional request failed
│ Lock Info:
│ ID: 03d3b219-5ea1-47b9-71a5-3e93e7102fdf
│ Path: terraform.tfstate
│ Operation: OperationTypeApply
│ Who: ryuseikakujo@whos-who.local
│ Version: 1.5.2
│ Created: 2023-07-16 19:17:52.561678 +0000 UTC
│ Info:
│
│ Terraform acquires a state lock to protect the state from being written
│ by multiple users at the same time. Please resolve the issue above and try
│ again. For most commands, you can disable locking with the "-lock=false"
│ flag, but this is not recommended.
もしDynamoDBでステートロック管理を構成している場合、apply
操作中にステートがロックされ、複数のユーザーが同時に処理されないようになっています。通常、apply
が完了するとロックは解除されます。しかし、操作が途中で中断されると、ステートファイルがロックされたままになります。
解決策
terraform force-unlock
コマンドを使用して、ロックを手動で解除します。
bash
$ terraform force-unlock --help
Usage: terraform [global options] force-unlock LOCK_ID
Manually unlock the state for the defined configuration.
This will not modify your infrastructure. This command removes the lock on the
state for the current workspace. The behavior of this lock is dependent
on the backend being used. Local state files cannot be unlocked by another
process.
Options:
-force Don't ask for input for unlock confirmation.
LOCK_ID
に入力するIDの値は、エラーメッセージ中で見つけることができます。(私の場合、03d3b219-5ea1-47b9-71a5-3e93e7102fdf
です)
bash
$ terraform force-unlock 03d3b219-5ea1-47b9-71a5-3e93e7102fdf
また、各コマンドを-lock=false
オプションを付けて実行することで、ロックを解除することもできます。
bash
$ terraform apply --lock=false
参考
AlloyDB
Amazon Cognito
Amazon EC2
Amazon ECS
Amazon QuickSight
Amazon RDS
Amazon Redshift
Amazon S3
API
Autonomous Vehicle
AWS
AWS API Gateway
AWS Chalice
AWS Control Tower
AWS IAM
AWS Lambda
AWS VPC
BERT
BigQuery
Causal Inference
ChatGPT
Chrome Extension
CircleCI
Classification
Cloud Functions
Cloud IAM
Cloud Run
Cloud Storage
Clustering
CSS
Data Engineering
Data Modeling
Database
dbt
Decision Tree
Deep Learning
Descriptive Statistics
Differential Equation
Dimensionality Reduction
Discrete Choice Model
Docker
Economics
FastAPI
Firebase
GIS
git
GitHub
GitHub Actions
Google
Google Cloud
Google Search Console
Hugging Face
Hypothesis Testing
Inferential Statistics
Interval Estimation
JavaScript
Jinja
Kedro
Kubernetes
LightGBM
Linux
LLM
Mac
Machine Learning
Macroeconomics
Marketing
Mathematical Model
Meltano
MLflow
MLOps
MySQL
NextJS
NLP
Nodejs
NoSQL
ONNX
OpenAI
Optimization Problem
Optuna
Pandas
Pinecone
PostGIS
PostgreSQL
Probability Distribution
Product
Project
Psychology
Python
PyTorch
QGIS
R
ReactJS
Regression
Rideshare
SEO
Singer
sklearn
Slack
Snowflake
Software Development
SQL
Statistical Model
Statistics
Streamlit
Tabular
Tailwind CSS
TensorFlow
Terraform
Transportation
TypeScript
Urban Planning
Vector Database
Vertex AI
VSCode
XGBoost