Search code examples
amazon-web-servicesterraformterraform-provider-awsterraform-template-file

What is wrong with this terraform template?


I get an error message │ An argument named "default_action" is not expected here. Did you mean to define a block of type "default_action"? trying to apply this part of the tf template

resource "aws_lb_listener" "HTTPS443" {

  load_balancer_arn = aws_lb.alb.arn

  port = "443"

  protocol = "HTTPS"

  ssl_policy = "ELBSecurityPolicy-TLS-1-0-2015-04"

  certificate_arn = "${aws_acm_certificate.acm.arn}"


  default_action {

    type = "fixed-response"


    fixed_response = {

      content_type = "application/json"

      message_body = "Nothing to see here"

      status_code  = "200"

    }

  }

}

However, based on the terraform documentation, this is how you define fixed response.

Am I missing something? My Terraform version is v1.2.9.


Solution

  • You need to remove the = sign from the fixed_response [1] configuration block:

      default_action {

        type = "fixed-response"


        fixed_response {

          content_type = "application/json"

          message_body = "Nothing to see here"
    
      status_code  = "200"

        }
    
  }
    

    As a side note, make sure to replace certificate_arn = "${aws_acm_certificate.acm.arn}" with certificate_arn = aws_acm_certificate.acm.arn as if you do not remove it terraform will treat it as a string literal.


    [1] https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lb_listener#fixed-response-action