Tfe v0.12.29 aws_route53_record alias causes error

Hello, I’m pretty new to tfe and would like some help if possible. I’m trying to setup a static website with S3, cloudfront and route53. Trying to create a aws_route53_record resource and added an alias as per documentation (https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record)

However, on terraform plan, I get the following error: An argument named “alias” is not expected here. Did you mean to define a block of type “alias”?

Any help would be appreciated.

Here is a snippet of my script:

resource "aws_cloudfront_distribution" "frontend_s3_distribution" {
  origin {
    domain_name = aws_s3_bucket.frontend_s3.bucket_domain_name
    origin_id   = var.bucket_name
  }

  enabled             = true
  is_ipv6_enabled     = true
  default_root_object = "index.html"

  aliases = [var.domain]

  default_cache_behavior {
    viewer_protocol_policy = "redirect-to-https"
    compress               = true
    allowed_methods        = ["GET", "HEAD"]
    cached_methods         = ["GET", "HEAD"]
    target_origin_id       = var.bucket_name
    min_ttl                = 0
    default_ttl            = 86400
    max_ttl                = 31536000

    forwarded_values {
      query_string = false

      cookies {
        forward = "none"
      }
    }
  }

  restrictions {
    geo_restriction {
      restriction_type = "none"
    }
  }

  viewer_certificate {
    acm_certificate_arn = data.aws_acm_certificate.ssl_cert.arn
    ssl_support_method  = "sni-only"
  }
}

resource "aws_route53_record" "frontend_record" {
  zone_id = data.aws_route53_zone.main.zone_id
  name    = var.domain
  type    = "A"
  alias = {
    name                   = aws_cloudfront_distribution.frontend_s3_distribution.domain_name
    zone_id                = aws_cloudfront_distribution.frontend_s3_distribution.host_zone_id
    evaluate_target_health = false
  }
}

I believe that the problem here is that you are defining a value for an alias argument (using alias = {…}, but the resource has an alias block (no = sign, just alias {…}).

Try this:

resource “aws_route53_record” “frontend_record” {
  zone_id = data.aws_route53_zone.main.zone_id
  name = var.domain
  type = “A”
  alias {
    name = aws_cloudfront_distribution.frontend_s3_distribution.domain_name
    zone_id = aws_cloudfront_distribution.frontend_s3_distribution.host_zone_id
    evaluate_target_health = false
  }
}

There’s a little more detail on defining attributes using block syntax in the documentation.

It worked like a charm. Thanks for helping with my silly mistake. :slight_smile:

1 Like