동시에 같은 파일을 수정하지 못하도록 하기 위해 DynamoDB에 작업에 대한 Lock을 생성합니다.
실습
1. terraform/init/dayone-id/init.tf 파일을 수정합니다.
vim terraform/init/dayone-id/init.tf
provider"aws"{region="ap-northeast-2"# Please use the default region IDversion="~> 2.49.0"# Please choose any version or delete this line if you want the latest version}# S3 bucket for backendresource"aws_s3_bucket""tfstate"{bucket="${var.account_id}-apnortheast2-tfstate"versioning{enabled=true# Prevent from deleting tfstate file }}# DynamoDB for terraform state lockresource"aws_dynamodb_table""terraform_state_lock"{name="terraform-lock"hash_key="LockID"billing_mode="PAY_PER_REQUEST"attribute{name="LockID"type="S" }}variable"account_id"{default="dayone-id"# Please use the account alias for id}
Plan: 2 to add, 0 to change, 0 to destroy. 이 나오면 정상입니다.
4. 이제 리소를 생성합니다.
$ terraform apply -parallelism=30
(... 중략 ...)
Plan: 2 to add, 0 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes <------ 정확히 yes라고 입력하셔야 합니다.
aws_dynamodb_table.terraform_state_lock: Creating...
aws_s3_bucket.tfstate: Creating...
aws_s3_bucket.tfstate: Creation complete after 3s [id=dayone-id-apnortheast2-tfstate]
aws_dynamodb_table.terraform_state_lock: Creation complete after 7s [id=terraform-lock]
Apply complete! Resources: 2 added, 0 changed, 0 destroyed.