gpt4 book ai didi

amazon-web-services - 如何解决错误加载状态: AccessDenied: Access Denied status code: 403 when trying to use s3 for terraform backend?

转载 作者:行者123 更新时间:2023-12-03 14:00:09 25 4
gpt4 key购买 nike

我的简单terraform文件是:

provider "aws" {
region = "region"
access_key = "key"
secret_key = "secret_key"
}

terraform {
backend "s3" {
# Replace this with your bucket name!
bucket = "great-name-terraform-state-2"
key = "global/s3/terraform.tfstate"
region = "eu-central-1"
# Replace this with your DynamoDB table name!
dynamodb_table = "great-name-locks-2"
encrypt = true
}
}

resource "aws_s3_bucket" "terraform_state" {
bucket = "great-name-terraform-state-2"
# Enable versioning so we can see the full revision history of our
# state files
versioning {
enabled = true
}
server_side_encryption_configuration {
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}
}

resource "aws_dynamodb_table" "terraform_locks" {
name = "great-name-locks-2"
billing_mode = "PAY_PER_REQUEST"
hash_key = "LockID"
attribute {
name = "LockID"
type = "S"
}
}
我要做的就是从本地替换后端以存储在S3中。
我正在执行以下操作:
  • terraform init(当terrafrom {}块为注释时)
  • terrafrom apply-我可以在AWS中看到创建了存储桶以及Dynmpo表。
  • 现在,我取消注释terrafrom块,并再次注释terraform init,出现以下错误:
  • Error loading state:
    AccessDenied: Access Denied
    status code: 403, request id: xxx, host id: xxxx
    我的IAM具有 管理员访问权限
    我正在使用 Terraform v0.12.24可以看到,我直接在文件中写入了我的AWS key 和 secret
    我究竟做错了什么?
    感谢您的帮助!

    最佳答案

    我以前遇到过
    以下是可帮助您克服该错误的步骤-

  • 删除.terraform目录
  • 将access_key和secret_key放在后端块下。像下面给定的代码
  • 运行terraform初始化
  •   backend "s3" {
    bucket = "great-name-terraform-state-2"
    key = "global/s3/terraform.tfstate"
    region = "eu-central-1"
    access_key = "<access-key>"
    secret_key = "<secret-key>"
    }
    }
    该错误应该消失了。

    关于amazon-web-services - 如何解决错误加载状态: AccessDenied: Access Denied status code: 403 when trying to use s3 for terraform backend?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61851903/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com