简体   繁体   English

Terraform - 启用访问负载平衡器日志 InvalidConfigurationRequest:存储桶的访问被拒绝

[英]Terraform - Enabling Access Load balancer logs InvalidConfigurationRequest: Access Denied for bucket

I'm using terraform to provision an ELB & want to Enable Access logs for ELB in a S3 bucket.我正在使用 terraform 来配置 ELB 并希望在 S3 存储桶中为 ELB 启用访问日志。 When I try to apply the resources, I get the below error - InvalidConfiguration: Access Denied for bucket:当我尝试应用资源时,出现以下错误 - InvalidConfiguration: Access Denied for bucket:

Below are my TF resources with the S3 bucket policy created using the IAM Policy Document.下面是我的 TF 资源,其中包含使用 IAM 策略文档创建的 S3 存储桶策略。

resource "aws_lb" "this" {
  name               = var.name
  load_balancer_type = "application"

  access_logs {
    bucket  = aws_s3_bucket.this.bucket
    prefix  = var.name
    enabled = true
  }
}

resource "aws_s3_bucket" "this" {
  bucket        = "${var.bucket_name}"
  acl           = "log-delivery-write"
  force_destroy = true

}

resource "aws_s3_bucket_policy" "this" {
  bucket = "aws_s3_bucket.this.id"
  policy = "${data.aws_iam_policy_document.s3_bucket_lb_write.json}"
}


data "aws_iam_policy_document" "s3_bucket_lb_write" {
  policy_id = "s3_bucket_lb_logs"

  statement {
    actions = [
      "s3:PutObject",
    ]
    effect = "Allow"
    resources = [
      "${aws_s3_bucket.this.arn}/*",
    ]

    principals {
      identifiers = ["${data.aws_elb_service_account.main.arn}"]
      type        = "AWS"
    }
  }

  statement {
    actions = [
      "s3:PutObject"
    ]
    effect = "Allow"
    resources = ["${aws_s3_bucket.this.arn}/*"]
    principals {
      identifiers = ["delivery.logs.amazonaws.com"]
      type        = "Service"
    }
  }


  statement {
    actions = [
      "s3:GetBucketAcl"
    ]
    effect = "Allow"
    resources = ["${aws_s3_bucket.this.arn}"]
    principals {
      identifiers = ["delivery.logs.amazonaws.com"]
      type        = "Service"
    }
  }
}

output "bucket_name" {
  value = "${aws_s3_bucket.this.bucket}"
}

I get the following error我收到以下错误

Error: Error putting S3 policy: NoSuchBucket: The specified bucket does not exist
        status code: 404, request id: 5932CFE816059A8D, host id: j5ZBQ2ptHXivx+fu7ai5jbM8PSQR2tCFo4IAvcLkuocxk8rn/r0TG/6YbfRloBFR2WSy8UE7K8Q=

Error: Failure configuring LB attributes: InvalidConfigurationRequest: Access Denied for bucket: test-logs-bucket-xyz. Please check S3bucket permission
        status code: 400, request id: ee101cc2-5518-42c8-9542-90dd7bb05e3c

terraform version Terraform v0.12.23 terraform 版本 Terraform v0.12.23

  • provider.aws v3.6.0 provider.aws v3.6.0

There is mistake in:有以下错误:

resource "aws_s3_bucket_policy" "this" {
  bucket = "aws_s3_bucket.this.id"
  policy = "${data.aws_iam_policy_document.s3_bucket_lb_write.json}"
}

it should be:它应该是:

resource "aws_s3_bucket_policy" "this" {
  bucket = aws_s3_bucket.this.id
  policy = data.aws_iam_policy_document.s3_bucket_lb_write.json
}

The orginal version ( bucket = "aws_s3_bucket.this.id" ) will just try to look for bucket literally called "aws_s3_bucket.this.id".原始版本 ( bucket = "aws_s3_bucket.this.id" ) 只会尝试查找字面上称为“aws_s3_bucket.this.id”的存储桶。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Terraform InvalidConfigurationRequest:S3 存储桶的访问被拒绝 - Terraform InvalidConfigurationRequest: Access denied for S3 bucket 为Application Load Balancer启用访问日志 - Enabling access logs for Application Load Balancer 为 Classic Load Balancer 启用访问日志:存储桶未出现在控制台中 - Enable Access Logs for Classic Load Balancer: Bucket does not appear in console 如何配置 s3 存储桶以允许 aws 应用程序负载均衡器(不是类)使用它? 当前抛出“拒绝访问” - how to configure s3 bucket to allow aws application load balancer (not class) use it? currently throws' access denied' AWS 网络负载均衡器访问日志修改 - AWS Network Load Balancer access logs modification AWS CDK:为经典负载均衡器启用访问日志记录 - AWS CDK: enabling access logging for classical load balancer Terraform KMS 访问被拒绝? - Terraform KMS access denied? 对存储桶的访问被拒绝 ****** - Access denied to the bucket ****** 如何在AWS Application Load Balancer访问日志和Cloudfront访问日志中特定查询参数值 - how to specific query parameter value in aws application load balancer access logs and cloudfront access logs S3存储桶中的访问被拒绝 - Access Denied in S3 Bucket
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM