[英]Terraform init Error: Failed to get existing workspaces: S3 bucket does not exist
嗨,当我将 terraform 指定为后端时,我无法看到 s3 存储桶
aws --profile terraform s3api create-bucket --bucket "some_name_here" --region "eu-west-2" \
--create-bucket-configuration LocationConstraint="eu-west-2"
terraform 初始化
Initializing modules...
Initializing the backend...
Error: Failed to get existing workspaces: S3 bucket does not exist.
The referenced S3 bucket must have been previously created. If the S3 bucket
was created within the last minute, please wait for a minute or two and try
again.
Error: NoSuchBucket: The specified bucket does not exist
status code: 404, request id: QYJT8KP0W4TM986A, host id: a7R1EOOnIhP6YzDcKd66zdyCJ8wk6lVom/tohsc0ipUe5yEJK1/V4bLGX9khi4q4/J7d4BgYXCc=
后端.tf
terraform {
backend "s3" {
bucket = "some_name_here"
key = "networking/terraform.tfstate"
region = "eu-west-2"
}
}
提供者.tf
provider "aws" {
region = "eu-west-2"
shared_credentials_file = "$HOME/.aws/credentials"
profile = "terraform"
}
我可以在仪表板中看到存储桶
看起来您正在命令中使用配置文件来创建存储桶。 因此,您可能需要在运行 terraform 的环境中导出一个变量以使用相同的配置文件。 我想 terraform 没有此配置文件或另一个具有足够权限的配置文件无法从存储桶中读取。
export AWS_PROFILE=terraform
terraform init
或者,您可以将 配置文件传递到后端配置中,例如:
terraform {
backend "s3" {
bucket = "some_name_here"
key = "networking/terraform.tfstate"
profile = "terraform"
region = "eu-west-2"
}
}
总结一下,最简单的配置是:
terraform {
backend "s3" {
bucket = "some_name_here"
key = "networking/terraform.tfstate"
region = "eu-west-2"
}
}
provider "aws" {
region = "eu-west-2"
}
然后:
export AWS_PROFILE=terraform
aws s3api create-bucket --bucket "some_name_here" --region "eu-west-2" --create-bucket-configuration LocationConstraint="eu-west-2"
terraform init
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.