Terraform: panic: value is not known

Created on 2 Apr 2020  ·  4Comments  ·  Source: hashicorp/terraform

A Crash and error message of panic: value is not known when creating nested blocks containing lists of unknown sizes.

Terraform Version

0.12.2

Terraform Configuration Files

resource "aws_lb_listener_rule" "host_and_path_conditions" {
  listener_arn = "arn:aws:elasticloadbalancing:eu-west-1:0123456678910:listener/app/loadbalancer/0123456789abcdef/abcdef0123456789"

  action {
    type             = "forward"
    target_group_arn = "arn:aws:elasticloadbalancing:eu-west-1:0123456678910:targetgroup/targetgroup-name/0123456789abcdef"
  }

  condition {
    host_header {
      values = ["mydomain.example.com"]
    }
  }

  condition {
    path_pattern {
      values = [
        "/mypath.jsp",
        "/mypathalias",
      ]
    }
  }
}

Debug Output

debug output gist

Crash Output

crash.log gist

Expected Behavior

It should have created a load balancer listener rule with 2 conditions

Actual Behavior

Terraform panic and crash

Steps to Reproduce

  1. Create a LB listener rule with 2 condition blocks (host_header & path_pattern)
  2. Run terraform plan. Observe the 2 conditions both containing host_header & path_pattern)
  3. Run terraform apply

Additional Context

plan output for resource:

  # module.staging.aws_lb_listener_rule.host_and_path_conditions will be created
  + resource "aws_lb_listener_rule" "host_and_path_conditions" {
      + arn          = (known after apply)
      + id           = (known after apply)
      + listener_arn = "arn:aws:elasticloadbalancing:eu-west-1:0123456678910:listener/app/loadbalancer/0123456789abcdef/abcdef0123456789"
      + priority     = (known after apply)

      + action {
          + order            = (known after apply)
          + target_group_arn = "arn:aws:elasticloadbalancing:eu-west-1:0123456678910:targetgroup/targetgroup-name/0123456789abcdef"
          + type             = "forward"
        }

      + condition {
          + field  = (known after apply)
          + values = (known after apply)

          + host_header {
              + values = (known after apply)
            }

          + path_pattern {
              + values = [
                  + "/mypathalias",
                  + "/mypath.jsp",
                ]
            }
        }
      + condition {
          + field  = (known after apply)
          + values = (known after apply)

          + host_header {
              + values = [
                  + "mydomain.example.com",
                ]
            }

          + path_pattern {
              + values = (known after apply)
            }
        }
    }

I'm not sure the relevance of each condition block containing both host_header & path_pattern

References

  • #23108
bug crash v0.12

Most helpful comment

Hi @completenovice

This bug is fixed in terraform v0.12.24. The fix commit is probably here. (https://github.com/hashicorp/terraform/commit/7a183a0e90619bc04032ffaf646018e117cfd05a)

I've checked if this bug is fixed in terraform v0.12.24.

Test Environment

$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.14.6
BuildVersion:   18G87

$ terraform -version
Terraform v0.12.24
+ provider.aws v2.57.0

Test Result

tf file

$ cat main.tf
...
resource "aws_lb_listener_rule" "host_and_path_conditions" {
  listener_arn = aws_lb_listener.front_end.arn

  action {
    type             = "forward"
    target_group_arn = aws_lb_target_group.test.arn
  }

  condition {
    host_header {
      values = ["mydomain.example.com"]
    }
  }

  condition {
    path_pattern {
      values = [
        "/mypath.jsp",
        "/mypathalias",
      ]
    }
  }
}

plan result

------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # aws_lb_listener_rule.host_and_path_conditions will be created
  + resource "aws_lb_listener_rule" "host_and_path_conditions" {
      + arn          = (known after apply)
      + id           = (known after apply)
      + listener_arn = "arn:aws:elasticloadbalancing:ap-northeast-1:221684517171:listener/app/test-lb-tf/481890571e3cef47/d78001390289aebb"
      + priority     = (known after apply)

      + action {
          + order            = (known after apply)
          + target_group_arn = "arn:aws:elasticloadbalancing:ap-northeast-1:221684517171:targetgroup/tf-example-lb-tg/bd3df14d3de44e3e"
          + type             = "forward"
        }

      + condition {
          + field  = (known after apply)
          + values = (known after apply)

          + host_header {
              + values = (known after apply)
            }

          + path_pattern {
              + values = [
                  + "/mypath.jsp",
                  + "/mypathalias",
                ]
            }
        }
      + condition {
          + field  = (known after apply)
          + values = (known after apply)

          + host_header {
              + values = [
                  + "mydomain.example.com",
                ]
            }

          + path_pattern {
              + values = (known after apply)
            }
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.

------------------------------------------------------------------------

apply result

$ terraform apply -auto-approve
aws_lb.test: Refreshing state... [id=arn:aws:elasticloadbalancing:ap-northeast-1:221684517171:loadbalancer/app/test-lb-tf/481890571e3cef47]
aws_lb_target_group.test: Refreshing state... [id=arn:aws:elasticloadbalancing:ap-northeast-1:221684517171:targetgroup/tf-example-lb-tg/bd3df14d3de44e3e]
aws_lb_listener.front_end: Refreshing state... [id=arn:aws:elasticloadbalancing:ap-northeast-1:221684517171:listener/app/test-lb-tf/481890571e3cef47/d78001390289aebb]
aws_lb_listener_rule.host_and_path_conditions: Creating...
aws_lb_listener_rule.host_and_path_conditions: Creation complete after 1s [id=arn:aws:elasticloadbalancing:ap-northeast-1:221684517171:listener-rule/app/test-lb-tf/481890571e3cef47/d78001390289aebb/347414889bd9cba7]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

All 4 comments

Hi @completenovice

This bug is fixed in terraform v0.12.24. The fix commit is probably here. (https://github.com/hashicorp/terraform/commit/7a183a0e90619bc04032ffaf646018e117cfd05a)

I've checked if this bug is fixed in terraform v0.12.24.

Test Environment

$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.14.6
BuildVersion:   18G87

$ terraform -version
Terraform v0.12.24
+ provider.aws v2.57.0

Test Result

tf file

$ cat main.tf
...
resource "aws_lb_listener_rule" "host_and_path_conditions" {
  listener_arn = aws_lb_listener.front_end.arn

  action {
    type             = "forward"
    target_group_arn = aws_lb_target_group.test.arn
  }

  condition {
    host_header {
      values = ["mydomain.example.com"]
    }
  }

  condition {
    path_pattern {
      values = [
        "/mypath.jsp",
        "/mypathalias",
      ]
    }
  }
}

plan result

------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # aws_lb_listener_rule.host_and_path_conditions will be created
  + resource "aws_lb_listener_rule" "host_and_path_conditions" {
      + arn          = (known after apply)
      + id           = (known after apply)
      + listener_arn = "arn:aws:elasticloadbalancing:ap-northeast-1:221684517171:listener/app/test-lb-tf/481890571e3cef47/d78001390289aebb"
      + priority     = (known after apply)

      + action {
          + order            = (known after apply)
          + target_group_arn = "arn:aws:elasticloadbalancing:ap-northeast-1:221684517171:targetgroup/tf-example-lb-tg/bd3df14d3de44e3e"
          + type             = "forward"
        }

      + condition {
          + field  = (known after apply)
          + values = (known after apply)

          + host_header {
              + values = (known after apply)
            }

          + path_pattern {
              + values = [
                  + "/mypath.jsp",
                  + "/mypathalias",
                ]
            }
        }
      + condition {
          + field  = (known after apply)
          + values = (known after apply)

          + host_header {
              + values = [
                  + "mydomain.example.com",
                ]
            }

          + path_pattern {
              + values = (known after apply)
            }
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.

------------------------------------------------------------------------

apply result

$ terraform apply -auto-approve
aws_lb.test: Refreshing state... [id=arn:aws:elasticloadbalancing:ap-northeast-1:221684517171:loadbalancer/app/test-lb-tf/481890571e3cef47]
aws_lb_target_group.test: Refreshing state... [id=arn:aws:elasticloadbalancing:ap-northeast-1:221684517171:targetgroup/tf-example-lb-tg/bd3df14d3de44e3e]
aws_lb_listener.front_end: Refreshing state... [id=arn:aws:elasticloadbalancing:ap-northeast-1:221684517171:listener/app/test-lb-tf/481890571e3cef47/d78001390289aebb]
aws_lb_listener_rule.host_and_path_conditions: Creating...
aws_lb_listener_rule.host_and_path_conditions: Creation complete after 1s [id=arn:aws:elasticloadbalancing:ap-northeast-1:221684517171:listener-rule/app/test-lb-tf/481890571e3cef47/d78001390289aebb/347414889bd9cba7]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Thanks, @completenovice and @htamakos! I'm going to close this issue because it looks like @completenovice confirmed with a 👍 that it's fixed in 0.12.24. Please feel free to re-open or leave a comment if this is wrong.

Nope bang on. Cheers guys! 👍

I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings