cn-terraform / terraform-aws-s3-static-website

Terraform Module for AWS to host Static Website on S3
https://registry.terraform.io/modules/cn-terraform/s3-static-website/aws
Apache License 2.0
20 stars 33 forks source link

Error putting S3 policy: MalformedPolicy: Missing required field Principal cannot be empty! #38

Closed ptwohig closed 2 years ago

ptwohig commented 2 years ago

Getting this error trying to create a static web site.

Error: Error putting S3 policy: MalformedPolicy: Missing required field Principal cannot be empty!
    status code: 400, request id: [redacted], host id: [redacted]

   with module.mainsite.module.main_static_site.module.s3_logs_bucket.aws_s3_bucket_policy.logs_access_policy,
   on .terraform/modules/mainsite.main_static_site.s3_logs_bucket/main.tf line 70, in resource "aws_s3_bucket_policy" "logs_access_policy":
   70: resource "aws_s3_bucket_policy" "logs_access_policy" {

This is the terraform code taht produces this issue:

module "main_static_site" {
  source  = "cn-terraform/s3-static-website/aws"
  version = "0.0.17"
  name_prefix=var.deployment_name
  website_domain_name=var.main_site_domain_name
  create_route53_hosted_zone = false
  route53_hosted_zone_id = aws_route53_zone.main.zone_id
  providers = {
    aws.main = aws
    aws.acm_provider = aws
  }
}

Where the following applies:
* var.main_deployment_name = "production"
* var.main_site_domain_name = "mydomain.com"

I'm creating a hosted zone manually and passing it in.

The line in the associated module shows this on line 70:

```hcl
resource "aws_s3_bucket_policy" "logs_access_policy" {
  bucket = aws_s3_bucket.logs.id
  policy = data.aws_iam_policy_document.logs_access_policy_document.json
}

I'm not sure which field is missing, but this is the result from AWS. Is there a known workaround for this?

ptwohig commented 2 years ago

Also my Terraform version

Terraform v1.2.3
on linux_amd64

Your version of Terraform is out of date! The latest version
is 1.2.6. You can update by downloading from https://www.terraform.io/downloads.html

I'm going to try updating Terraform, as well.

ptwohig commented 2 years ago

Seems like this would be a better place for the issue.

https://github.com/cn-terraform/terraform-aws-logs-s3-bucket/issues/4