terraform-provider-aws: AWS S3 output fails for website_endpoint and website_domain

This issue was originally opened by @llibicpep as hashicorp/terraform#17759. It was migrated here as a result of the provider split. The original body of the issue is below.


Terraform Version

Terraform v0.11.3

Terraform Configuration Files

resource "aws_s3_bucket" "bucket" {
  bucket = "${var.bucket_name}"
  acl    = "${var.website == "true" ? "public-read" : "private"}"

  website = {
    index_document = "${var.index_document}"
  }
}
output "bucket_website_endpoint" {
  value = "${var.website == "true" ? aws_s3_bucket.bucket.website_endpoint : ""}"
}

output "bucket_website_domain" {
  value = "${var.website == "true" ? aws_s3_bucket.bucket.website_domain : ""}"
}

Debug Output

2018/04/02 18:06:12 [TRACE] [walkPlan] Exiting eval tree: module.vmn-s3-bucket_website.aws_s3_bucket_policy.website_policy
       2018/04/02 18:06:12 [TRACE] dag/walk: walking "provider.aws (close)"
       2018/04/02 18:06:12 [TRACE] vertex 'root.provider.aws (close)': walking
       2018/04/02 18:06:12 [TRACE] dag/walk: upstream errored, not walking "meta.count-boundary (count boundary fixup)"
       2018/04/02 18:06:12 [TRACE] vertex 'root.provider.aws (close)': evaluating
       2018/04/02 18:06:12 [TRACE] [walkPlan] Entering eval tree: provider.aws (close)
       2018/04/02 18:06:12 [TRACE] root: eval: *terraform.EvalCloseProvider
       2018/04/02 18:06:12 [TRACE] [walkPlan] Exiting eval tree: provider.aws (close)
       2018/04/02 18:06:12 [TRACE] dag/walk: upstream errored, not walking "root"

       2018/04/02 18:06:12 [DEBUG] plugin: waiting for all plugin processes to complete...
       Error: Error running plan: 2 error(s) occurred:

       * module.vmn-s3-bucket_private.output.bucket_website_endpoint: Resource 'aws_s3_bucket.bucket' does not have attribute 'website_endpoint' for variable 'aws_s3_bucket.bucket.website_endpoint'
       * module.vmn-s3-bucket_private.output.bucket_website_domain: Resource 'aws_s3_bucket.bucket' does not have attribute 'website_domain' for variable 'aws_s3_bucket.bucket.website_domain'

Expected Behavior

It fails

Actual Behavior

It should not

Steps to Reproduce

terraform apply

Additional Context

The docs says https://www.terraform.io/docs/providers/aws/r/s3_bucket.html#website_endpoint If not, this will be an empty string.. So this should not be failing even without a ternary operator - but it fails even with it.

References

Sounds like a regression after https://github.com/hashicorp/terraform/issues/14846

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 7
  • Comments: 17 (3 by maintainers)

Most upvoted comments

Hrm, I have a website stanza and I am still getting an error.

resource "aws_s3_bucket" "b" {
  bucket = "${local.domain_name}"
  acl    = "private"

  website {
    index_document = "index.html"
    error_document = "error.html"
  }
}

I am trying to use the website_endpoint to configure CloudFront like so:

resource "aws_cloudfront_distribution" "s3_distribution" {

   origin {
     domain_name = "${aws_s3_bucket.b.website_endpoint}"
     origin_id   = "${local.s3_origin_id}"
  }
}

This throws the following error:

aws_cloudfront_distribution.s3_distribution: Resource 'aws_s3_bucket.b' does not have attribute 'website_endpoint' for variable 'aws_s3_bucket.b.website_endpoint'

I experienced the same problem with a bucket that had already been created without the website directive. I worked around it by first applying the change to add the website to the bucket, then referring to the website_endpoint in the cloudfront distro after.

I’m having the same issue. The presence of website object in aws_s3_bucket resource doesn’t actually enable static website hosting when viewing in AWS console and also it’s not written to the .tfstate file. When I manually enable static website from AWS console and run terraform apply the bucket state is updated and terraform output shows the correct website_endpoint

▶ terraform --version
Terraform v0.11.8
+ provider.aws v1.35.0

Seems to be solved if I recreate the bucket from scratch with acl = "public-read"

We’ve fixed this in the customer TF we had, and it was related to moving from Terraform 0.10 -> 0.11 and hitting https://www.terraform.io/upgrade-guides/0-11.html#error-checking-for-output-values

Because the customer didn’t have astatic website enabled for those s3 buckets, which is enabled by adding a website stanza to the bucket resource, website_endpoint isn’t actually a valid attribute. In Terraform < 0.11, this will interpolate as empty string, in 0.11 onwards, this hard errors.

Deleting the website_endpoint output as it wasn’t being used fixed it.

As far as the documentation goes, either, this is a bug and the documentation is correct, or vice versa.

Think someone could pick this up easily, but need a steer from @catsby or other maintainers as to what “correct” should be (fix ‘bug’, or ‘fix’ documentation).

Relevant code is at https://github.com/terraform-providers/terraform-provider-aws/blob/master/aws/resource_aws_s3_bucket.go#L1093

okay i deleted the output, in my case it is only informational.