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

Using template output fails because of unknown value #2744

Closed
dalehamel opened this issue Jul 15, 2015 · 5 comments · Fixed by #2788
Closed

Using template output fails because of unknown value #2744

dalehamel opened this issue Jul 15, 2015 · 5 comments · Fixed by #2788
Assignees

Comments

@dalehamel
Copy link

I am using the output of a template to get a dns record value.

When I try to change the count on that template, it will put the unknown value in the diff:

 module.chef_instance.aws_route53_record.srvrecord
    records.#:          "2" => "3"
    records.1158792681: "0 0 80 srvtest1.test.us-east-1.shopifyvpc.com" => "0 0 80 srvtest1.test.us-east-1.shopifyvpc.com"
    records.1274424632: "0 0 80 srvtest0.test.us-east-1.shopifyvpc.com" => "0 0 80 srvtest0.test.us-east-1.shopifyvpc.com"
    records.2068225513: "" => "0 0 80 74D93920-ED26-11E3-AC10-0800200C9A66"

This then fails to apply with the message:

* aws_route53_record.srvrecord: diffs didn't match during apply. This is a bug with Terraform and should be reported.

Now that the value is known, because the template resource actually exists, if I run a plan:

~ module.chef_instance.aws_route53_record.srvrecord
    records.#:          "2" => "3"
    records.1158792681: "0 0 80 srvtest1.test.us-east-1.shopifyvpc.com" => "0 0 80 srvtest1.test.us-east-1.shopifyvpc.com"
    records.1274424632: "0 0 80 srvtest0.test.us-east-1.shopifyvpc.com" => "0 0 80 srvtest0.test.us-east-1.shopifyvpc.com"
    records.1446640794: "" => "0 0 80 srvtest2.test.us-east-1.shopifyvpc.com"

It's able to actually GET the value, and it actually applies.

@phinze any idea how this can be fixed? Maybe we just need to teach the 'apply diffs must match' check resolve unknown values rather than crying?

@dalehamel
Copy link
Author

@thegedge theorizes this because route53 uses 'TypeSet' instead of 'TypeList'

@mitchellh
Copy link
Contributor

Hey @dalehamel. Thanks! Can you give us a sample TF config that triggers this? Thanks!

@dalehamel
Copy link
Author

@mitchellh this is the most minimal example I could produce

provider "aws" {
  region = "us-east-1"
}

variable "instances" {
  default = 2
}

resource "template_file" "node_name" {
  count = "${var.instances}"
  filename = "${path.module}/template.tpl"
  vars {
    index = "${count.index}"
  }
}

resource "aws_route53_zone" "dev" {
  name = "example.com"

  tags {
    Environment = "dev"
  }
}

resource "aws_route53_record" "srvrecord" {
  count = "${var.instances}"
  zone_id = "${aws_route53_zone.dev.id}"
  name = "foo.example.com"
  type = "SRV"
  ttl = "1"
  records = ["${formatlist("0 0 %s", template_file.node_name.*.rendered)}"]
}

it generates a plan like this:

+ aws_route53_record.srvrecord.0
    fqdn:               "" => "<computed>"
    name:               "" => "foo.example.com"
    records.#:          "" => "1"
    records.1485628133: "" => "0 0 74D93920-ED26-11E3-AC10-0800200C9A66"
    ttl:                "" => "1"
    type:               "" => "SRV"
    zone_id:            "" => "${aws_route53_zone.dev.id}"

+ aws_route53_record.srvrecord.1
    fqdn:               "" => "<computed>"
    name:               "" => "foo.example.com"
    records.#:          "" => "1"
    records.1485628133: "" => "0 0 74D93920-ED26-11E3-AC10-0800200C9A66"
    ttl:                "" => "1"
    type:               "" => "SRV"
    zone_id:            "" => "${aws_route53_zone.dev.id}"

+ aws_route53_zone.dev
    comment:          "" => "Managed by Terraform"
    name:             "" => "examplec.om"
    name_servers.#:   "" => "<computed>"
    tags.#:           "" => "1"
    tags.Environment: "" => "dev"
    vpc_region:       "" => "<computed>"
    zone_id:          "" => "<computed>"

+ template_file.node_name.0
    filename:   "" => "template.tpl"
    rendered:   "" => "<computed>"
    vars.#:     "" => "1"
    vars.index: "" => "0"

+ template_file.node_name.1
    filename:   "" => "template.tpl"
    rendered:   "" => "<computed>"
    vars.#:     "" => "1"
    vars.index: "" => "1"

Notice how the records all have the "unknown value" of 74D93920-ED26-11E3-AC10-0800200C9A66? This will cause the diff sanity check to fail.

cc @phinze @thegedge

@mitchellh
Copy link
Contributor

Got it, thanks @dalehamel

@ghost
Copy link

ghost commented May 1, 2020

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.

@ghost ghost locked and limited conversation to collaborators May 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants