微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

用于Terraform后端的S3存储桶的访问被拒绝

如何解决用于Terraform后端的S3存储桶的访问被拒绝

我的terraform代码如下:

# PROVIDERS
provider "aws" {
  profile = var.aws_profile
  region  = var.region
}

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 1.0.4"
    }
  }
}

terraform {
  backend "s3" {
    bucket = "terraform-backend-20200102"
    key    = "test.tfstate"
  }
}
# DATA

data "aws_availability_zones" "available" {}

data "template_file" "public_cidrsubnet" {
  count    = var.subnet_count
  template = "$${cidrsubnet(vpc_cidr,8,current_count)}"
  vars = {
    vpc_cidr      = var.network_address_space
    current_count = count.index
  }
}

# RESOURCES
module "vpc" {
  source          = "terraform-aws-modules/vpc/aws"
  name            = var.name
  version         = "2.62.0"
  cidr            = var.network_address_space
  azs             = slice(data.aws_availability_zones.available.names,var.subnet_count)
  public_subnets  = []
  private_subnets = data.template_file.public_cidrsubnet[*].rendered
  tags            = local.common_tags
}

但是,当我运行terraform init时,它给了我一个错误

$ terraform.exe init -reconfigure
Initializing modules...

Initializing the backend...
region
  AWS region of the S3 Bucket and DynamoDB Table (if used).

  Enter a value: ap-southeast-2


Successfully configured the backend "s3"! terraform will automatically
use this backend unless the backend configuration changes.
Error refreshing state: AccessDenied: Access Denied
        status code: 403,request id: A2EB50094A12E22F,host id: JFwXo11eiAW3N0JL1Yoi/i1k03aqzSIwj34NOgMT/ScgmBEC/nncjsK/GKik0SFIT6Ym8Mr/j6U=



/vpc_create
$ aws s3 ls --profile=tcp-aws-sandBox-31
2020-11-02 23:05:48 terraform-backend-20200102

请注意,我可以通过 aws s3 ls 命令列出我的存储分区,那么为什么terraform有任何问题!?

P.S::我正尝试转到本地状态文件,因此注释掉了后端块,但仍然给我一个错误,请协助。

# terraform {
#   backend "s3" {
#     bucket = "terraform-backend-20200102"
#     key    = "test.tfstate"
#   }
# }

解决方法

运行 aws configure ,然后运行。 由于某种原因,即使考虑了错误的原因,我还是在〜.aws / credentials 文件中设置了正确的 aws配置文件

我意识到使用错误帐户的方式是在 导出TF_LOG = DEBUG

之后运行地形应用

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。