Kay*_*Kay 5 amazon-s3 terraform
您好,当我将 s3 存储桶指定为后端时,我遇到了 terraform 无法看到 s3 存储桶的问题
aws --profile terraform s3api create-bucket --bucket "some_name_here" --region "eu-west-2" \
--create-bucket-configuration LocationConstraint="eu-west-2"
Run Code Online (Sandbox Code Playgroud)
地形初始化
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=
Run Code Online (Sandbox Code Playgroud)
后端.tf
terraform {
backend "s3" {
bucket = "some_name_here"
key = "networking/terraform.tfstate"
region = "eu-west-2"
}
}
Run Code Online (Sandbox Code Playgroud)
提供商.tf
provider "aws" {
region = "eu-west-2"
shared_credentials_file = "$HOME/.aws/credentials"
profile = "terraform"
}
Run Code Online (Sandbox Code Playgroud)
我可以在仪表板中看到该存储桶
看起来您正在命令中使用配置文件来创建存储桶。因此,您可能需要在运行 terraform 的环境中导出一个变量才能使用相同的配置文件。我想象没有此配置文件或其他具有足够权限的 terraform 无法从存储桶中读取数据。
export AWS_PROFILE=terraform
terraform init
Run Code Online (Sandbox Code Playgroud)
或者,您可以将配置文件传递到后端配置中,例如:
terraform {
backend "s3" {
bucket = "some_name_here"
key = "networking/terraform.tfstate"
profile = "terraform"
region = "eu-west-2"
}
}
Run Code Online (Sandbox Code Playgroud)
总结一下,最简单的配置是:
terraform {
backend "s3" {
bucket = "some_name_here"
key = "networking/terraform.tfstate"
region = "eu-west-2"
}
}
provider "aws" {
region = "eu-west-2"
}
Run Code Online (Sandbox Code Playgroud)
然后:
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12528 次 |
| 最近记录: |