Terraform初始化错误:获取现有工作区失败:S3存储桶不存在



嗨,我有一个问题,当我将terraform指定为后端时,它无法看到s3 bucket

aws --profile terraform s3api create-bucket --bucket "some_name_here" --region "eu-west-2" 
--create-bucket-configuration LocationConstraint="eu-west-2"

地形初始化

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"
}

我可以在仪表板上看到水桶

看起来您正在使用命令中的概要文件来创建bucket。因此,您可能需要在运行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

最新更新