Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S3 Bucket not found #90

Closed
JohnShortland opened this issue Jul 20, 2020 · 2 comments · Fixed by #142
Closed

S3 Bucket not found #90

JohnShortland opened this issue Jul 20, 2020 · 2 comments · Fixed by #142
Labels
bug 🐛 An issue with the system

Comments

@JohnShortland
Copy link

JohnShortland commented Jul 20, 2020

Describe the Bug

Ran using the example from repo and get the following error:

Error: Failed getting S3 bucket: NotFound: Not Found
        status code: 404, request id: EAC7428BD0E1699D, host id: rQ8gPW9bBhoBc6IOtIIslXHcioIr3VFwti9wxiPCZ6FqkUn/n2+qvqaVefuhcUzDteJdOavMLSU= Bucket: "BUCKET_NAME.DOMAIN.COM"

  on .terraform/modules/cloudfront_s3_cdn/main.tf line 176, in data "aws_s3_bucket" "selected":
 176: data "aws_s3_bucket" "selected" {

This is being ran on an organisation account in eu-west-1

Expected Behavior

Bucket to be created and cloudfront distro created

Screenshots

module "cloudfront_s3_cdn" {
  source                   = "git::https://github.com/cloudposse/terraform-aws-cloudfront-s3-cdn.git?ref=tags/0.26.0"
  namespace                = "${terraform.workspace}"
  stage                    = var.stage
  name                     = "BUCKET_NAME"
  use_regional_s3_endpoint = true
  origin_force_destroy     = true
  cors_allowed_headers     = ["*"]
  cors_allowed_methods     = ["GET", "HEAD", "PUT"]
  cors_allowed_origins     = ["*.${var.domain}"]
  cors_expose_headers      = ["ETag"]
  acm_certificate_arn      = aws_acm_certificate.BUCKET_NAME.arn
  aliases                  = ["BUCKET_NAME.${var.domain}"]
  origin_bucket            = "BUCKET_NAME.${var.domain}"
}

Environment (please complete the following information):

  • OS: WSL
  • Version: 2.0
@JohnShortland JohnShortland added the bug 🐛 An issue with the system label Jul 20, 2020
@shushry
Copy link

shushry commented Aug 11, 2020

I ran into this also - I think there is some confusion about the parameter "origin_bucket". If you were like me, you were assuming you could define the name of a NEW bucket to contain your origin, using that parameter. However, the module wants to name a new bucket FOR you, dynamically, based on the values of namespace, stage, etc. If you specify "origin_bucket" it's looking for an EXISTING bucket that you might already have out there.

Docs should be updated to clarify this.

@nitrocode
Copy link
Member

nitrocode commented Mar 27, 2021

Yes, the origin_bucket is for an existing s3 bucket.

This is interesting. It looks like if local.bucket is not defined, it will try to use var.static_s3_bucket. In this case, var.origin_bucket is defined, so it's trying to see if the bucket BUCKET_NAME.${var.domain} exists and since it doesn't, it throws an error.

data "aws_s3_bucket" "selected" {
bucket = local.bucket == "" ? var.static_s3_bucket : local.bucket
}
locals {
using_existing_origin = signum(length(var.origin_bucket)) == 1
using_existing_cloudfront_origin = var.cloudfront_origin_access_identity_iam_arn != "" && var.cloudfront_origin_access_identity_path != ""
bucket = join("",
compact(
concat([var.origin_bucket], concat([""], aws_s3_bucket.origin.*.id))
)
)

I put in PR #142 to update the description of this variable and provided an example in the README to clarify the inputs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 An issue with the system
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants