【问题标题】:Why do I get this IAM error when deploying my terraform template?为什么我在部署 terraform 模板时会收到此 IAM 错误?
【发布时间】:2022-08-14 00:03:34
【问题描述】:

我想在我的 ubuntu docker 容器上部署我的 terraform 模板。我在 env vars、terraform 和 /.aws/credentials 中设置了容器中的键。起初我有具有管理员权限的密钥,但后来我也尝试了 root 密钥但没有成功。

我尝试过的 terraform 版本是 0.14 和 1.2.6

这是错误:

状态码:403,请求 id:xxx,主机 id:xxx =:timestamp=2022-08-12T16:18:50.169Z 2022/08/12 16:18:50 [DEBUG] aws_s3_bucket.root_bucket: 应用错误,但我们\' 表示通过错误指针而不是返回它:创建 S3 存储桶时出错:AccessDenied: Access Denied status code: 403, request id: xxx, host id: xxx =

这是代码和json:

resource \"aws_s3_bucket\" \"root_bucket\" {
  bucket = var.bucket_name
  acl    = \"public-read\"
  policy = templatefile(\"templates/s3-policy.json\", { bucket = var.bucket_name })

  website {
    redirect_all_requests_to = \"https://www.${var.domain_name}\"
  }

  tags = var.common_tags
}

# json below
{
    \"Version\": \"2012-10-17\",
    \"Statement\": [
        {
            \"Sid\": \"PublicReadGetObject\",
            \"Effect\": \"Allow\",
            \"Principal\": \"*\",
            \"Action\": \"s3:GetObject\",
            \"Resource\": \"arn:aws:s3:::${bucket}/*\"
        }
    ]
}

# provider file below 
terraform {
  required_version = \"~> 1.2.6\"

  required_providers {
    aws = {
      source  = \"hashicorp/aws\"
      version = \"~> 3.0\"
    }
  }

  backend \"s3\" {
    bucket = \"skapawebb-terraform\"
    key    = \"prod/terraform.tfstate\"
    region = \"eu-north-1\"
    access_key = “xxx”
    secret_key = “xxx\" 
  }
}

provider \"aws\" {
  region = \"eu-north-1\"
  access_key = “xxx”
  secret_key = “xxx”  
}

provider \"aws\" {
  alias  = \"acm_provider\"
  region = \"us-east-1\"
}


  • 代码是什么?
  • 您是如何配置 aws 提供程序块和哪个版本的?
  • 我目前正在运行 v.1.2.6 在描述@BinhNguyen 中添加了提供程序文件

标签: amazon-web-services amazon-s3 terraform amazon-iam


【解决方案1】:

发生这种情况可能有两个原因:

  1. 您正在向存储桶添加公共策略,并且
  2. 您已为该帐户启用block public access settings for your account

    您必须先禁用帐户的阻止公共访问设置,然后才能使用公共策略创建任何存储桶。

【讨论】:

  • 谢谢回答。我试过了。确保所有这 4 个设置都已关闭。不过还是一样的错误。不知道该怎么做atm ..有什么想法吗? @Marcin
猜你喜欢
  • 2021-11-27
  • 2022-01-18
  • 1970-01-01
  • 1970-01-01
  • 2018-06-22
  • 2016-01-01
  • 2013-05-18
相关资源
最近更新 更多