Terraform S3 后端与 DynamoDB 锁配置后端片段(`main.tf`)terraform {
backend "s3" {
bucket = "tf-state"
key = "prod/terraform.tfstate"
region = "us-east-1"
dynamodb_table = "tf-locks"
encrypt = true
}
}
资源创建(示意)aws s3api create-bucket --bucket tf-state --region us-east-1 --create-bucket-configuration LocationConstraint=us-east-1
aws dynamodb create-table --table-name tf-locks --attribute-definitions AttributeName=LockID,AttributeType=S --key-schema AttributeName=LockID,KeyType=HASH --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5
初始化terraform init
总结S3+DynamoDB 后端提供远端状态与并发锁,提升团队协作与安全。

发表评论 取消回复