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

tf 0.5.0 :: Resource "template_file" instance :: "diffs didn't match during apply" bug #1866

Closed
nuallain opened this issue May 8, 2015 · 9 comments · Fixed by #4787
Closed
Assignees

Comments

@nuallain
Copy link

nuallain commented May 8, 2015

I'm being told by Terraform that I should report a bug. Details below.

$ terraform --version
Terraform v0.5.0

$ consul --version
Consul v0.5.0
Consul Protocol: 2 (Understands back to: 1)

$ terraform apply
template_file.deployment: Creating...
  filename:                      "" => "deployment.json"
  rendered:                      "" => "<computed>"
  vars.#:                        "0" => "2"
  vars.application_name:         "" => "bootstrap"
  vars.deployment_configuration: "" => "default"
template_file.deployment: Creation complete
consul_keys.application_service: Creating...
  datacenter:            "" => "<computed>"
  key.#:                 "" => "1"
  key.449824328.default: "" => ""
  key.449824328.delete:  "" => "0"
  key.449824328.name:    "" => "deployment"
  key.449824328.path:    "" => "node/deployment"
  key.449824328.value:   "" => "{\n    \"application_name\": \"bootstrap\",\n    \"deployment_configuration\": \"default\"\n}\n"
  var.#:                 "" => "<computed>"
consul_keys.application_service: Creation complete

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

The state of your infrastructure has been saved to the path
below. This state is required to modify and destroy your
infrastructure, so keep it safe. To inspect the complete state
use the `terraform show` command.

State path: terraform.tfstate

$ terraform apply
template_file.deployment: Refreshing state... (ID: 8cca96a9cc6f7174f1a2)
consul_keys.application_service: Refreshing state... (ID: consul)
template_file.deployment: Creating...
  filename:                      "" => "deployment.json"
  rendered:                      "" => "<computed>"
  vars.#:                        "0" => "2"
  vars.application_name:         "" => "bootstrap"
  vars.deployment_configuration: "" => "default"
template_file.deployment: Creation complete
Error applying plan:

1 error(s) occurred:

* 1 error(s) occurred:

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

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.

$cat application_service.tf 
variable "application_name" {
    default = "bootstrap"
}

variable "deployment_configuration" {
    default = "default"
}

# add node's configuration to consul
resource "template_file" "deployment" {
    filename = "deployment.json"
    vars {
       application_name = "${var.application_name}"
       deployment_configuration = "${var.deployment_configuration}"
    }
}

resource "consul_keys" "application_service" {

    key {
        name = "deployment"
        path = "node/deployment"
        value = "${template_file.deployment.rendered}"
    }
}
@mitchellh
Copy link
Contributor

Can you please gist your debug log? Please cmd-f it for secrets at first. And please use gist, since it'll be quite large.

@nuallain
Copy link
Author

nuallain commented May 8, 2015

@phinze phinze self-assigned this May 8, 2015
@phinze
Copy link
Contributor

phinze commented May 8, 2015

Thanks for this. Looks like an empty diff on the apply side.

consul_keys.application_service: diffs didn't match
consul_keys.application_service: reason: attribute mismatch: key.~449824328.delete
diff one: *terraform.InstanceDiff{Attributes:map[string]*terraform.ResourceAttrDiff{
  "key.~449824328.default":*terraform.ResourceAttrDiff{Old:"", New:"", NewComputed:false, NewRemoved:true, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0},
  "key.~449824328.delete":*terraform.ResourceAttrDiff{Old:"0", New:"0", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0},
  "key.~449824328.name":*terraform.ResourceAttrDiff{Old:"deployment", New:"deployment", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0},
  "key.~449824328.path":*terraform.ResourceAttrDiff{Old:"node/deployment", New:"node/deployment", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0},
  "key.~449824328.value":*terraform.ResourceAttrDiff{Old:"{\n    \"application_name\": \"bootstrap\",\n    \"deployment_configuration\": \"default\"\n}\n", New:"${template_file.deployment.rendered}", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}}, Destroy:false, DestroyTainted:false}

diff two: *terraform.InstanceDiff{Attributes:map[string]*terraform.ResourceAttrDiff(nil), Destroy:false, DestroyTainted:false}

I'll continue to dig in.

@phinze
Copy link
Contributor

phinze commented May 8, 2015

Okay I think #1879 might be masking the issue here. Going to go and solve that first.

@mschuett
Copy link

mschuett commented May 9, 2015

Just FYI, I encountered the same problem with aws_iam_user_policy.

phinze added a commit to phinze/terraform-issues that referenced this issue May 9, 2015
@phinze
Copy link
Contributor

phinze commented May 9, 2015

I've reproduced the same diff mismatch without the template_file by just having consul_keys depend on a computed attribute.

Config: https://github.com/phinze/terraform-issues/tree/master/1866-template-diff-mismatch

Diff mismatch resulting from changing var.planet and applying:

2015/05/09 15:48:42 [ERROR] consul_keys.hello: diffs didn't match
2015/05/09 15:48:42 [ERROR] consul_keys.hello: reason: attribute mismatch: key.~1809182598.delete
2015/05/09 15:48:42 [ERROR] consul_keys.hello: diff one: *terraform.InstanceDiff{Attributes:map[string]*terraform.ResourceAttrDiff{"key.~1809182598.default":*terraform.ResourceAttrDiff{Old:"", New:"", NewComputed:false, NewRemoved:true, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "key.~1809182598.delet
e":*terraform.ResourceAttrDiff{Old:"0", New:"0", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "key.~1809182598.name":*terraform.ResourceAttrDiff{Old:"hello", New:"hello", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "
key.~1809182598.path":*terraform.ResourceAttrDiff{Old:"world", New:"world", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "key.~1809182598.value":*terraform.ResourceAttrDiff{Old:"Hello earth!\n", New:"${aws_instance.public.tags.Hello}", NewComputed:false, NewRemoved:f
alse, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}}, Destroy:false, DestroyTainted:false}
2015/05/09 15:48:42 [ERROR] consul_keys.hello: diff two: *terraform.InstanceDiff{Attributes:map[string]*terraform.ResourceAttrDiff(nil), Destroy:false, DestroyTainted:false}

Note the second diff is empty.

@mschuett can you toss up a bit of config demonstrating the problem you hit? I'd like to see if I can correlate this to something common between aws_iam_policy and consul_keys

@mschuett
Copy link

Here is a small example for aws_iam_policy with config file, ftstate file, and debug output: https://gist.github.com/mschuett/141fe2fd07c9e5643bd5

@nuallain
Copy link
Author

FYI, we've got full encryption enabled for consul - gossip and authentication.

phinze added a commit that referenced this issue May 11, 2015
This reworks the template lifecycle a bit such that we get nicer diff
behavior.

First, we tick ForceNew on for both filename and vars, so that the diff
indicates that the template will be "replaced" on change. This is mostly
cosmetic, but it also tracks conceptually with the fact that the
identifier we use is a hash of the contents, so any change essentially
makes a "new resource".

Second, we change the Exists implementation to only return `false` when
there has been a change in the rendered template. This lets descendent
resources see the computed value changing so that they'll properly
trigger in the plan.

Fixes #1898
Refs #1866 (but does not fix, there's another deeper issue there)
phinze added a commit that referenced this issue Jan 21, 2016
Implementation notes:

 * The hash implementation was not considering key value, causing "diffs
   did not match" errors when a value was updated. Switching to default
   HashResource implementation fixes this
 * Using HashResource as a default exposed a bug in helper/schema that
   needed to be fixed so the Set function is picked up properly during
   Read
 * Stop writing back values into the `key` attribute; it triggers extra
   diffs when `default` is used. Computed values all just go into `var`.
 * Skip setting back `datacenter`, as it is unnecessary

In the tests:

 * Switch from leaning on the public demo Consul instance to requiring a
   CONSUL_HTTP_ADDR variable be set pointing to a `consul agent -dev`
   instance to be used only for testing.
 * Add a test that exposes the updating issues and covers the fixes

Fixes #774
Fixes #1866
Fixes #3023
phinze added a commit that referenced this issue Jan 25, 2016
Implementation notes:

 * The hash implementation was not considering key value, causing "diffs
   did not match" errors when a value was updated. Switching to default
   HashResource implementation fixes this
 * Using HashResource as a default exposed a bug in helper/schema that
   needed to be fixed so the Set function is picked up properly during
   Read
 * Stop writing back values into the `key` attribute; it triggers extra
   diffs when `default` is used. Computed values all just go into `var`.

In the tests:

 * Switch from leaning on the public demo Consul instance to requiring a
   CONSUL_HTTP_ADDR variable be set pointing to a `consul agent -dev`
   instance to be used only for testing.
 * Add a test that exposes the updating issues and covers the fixes

Fixes #774
Fixes #1866
Fixes #3023
phinze added a commit that referenced this issue Jan 26, 2016
Implementation notes:

 * The hash implementation was not considering key value, causing "diffs
   did not match" errors when a value was updated. Switching to default
   HashResource implementation fixes this
 * Using HashResource as a default exposed a bug in helper/schema that
   needed to be fixed so the Set function is picked up properly during
   Read
 * Stop writing back values into the `key` attribute; it triggers extra
   diffs when `default` is used. Computed values all just go into `var`.
 * Includes a state migration to prevent unnecessary diffs based on
   "key" attribute hashcodes changing.

In the tests:

 * Switch from leaning on the public demo Consul instance to requiring a
   CONSUL_HTTP_ADDR variable be set pointing to a `consul agent -dev`
   instance to be used only for testing.
 * Add a test that exposes the updating issues and covers the fixes

Fixes #774
Fixes #1866
Fixes #3023
joshmyers pushed a commit to joshmyers/terraform that referenced this issue Feb 18, 2016
Implementation notes:

 * The hash implementation was not considering key value, causing "diffs
   did not match" errors when a value was updated. Switching to default
   HashResource implementation fixes this
 * Using HashResource as a default exposed a bug in helper/schema that
   needed to be fixed so the Set function is picked up properly during
   Read
 * Stop writing back values into the `key` attribute; it triggers extra
   diffs when `default` is used. Computed values all just go into `var`.
 * Includes a state migration to prevent unnecessary diffs based on
   "key" attribute hashcodes changing.

In the tests:

 * Switch from leaning on the public demo Consul instance to requiring a
   CONSUL_HTTP_ADDR variable be set pointing to a `consul agent -dev`
   instance to be used only for testing.
 * Add a test that exposes the updating issues and covers the fixes

Fixes hashicorp#774
Fixes hashicorp#1866
Fixes hashicorp#3023
bigkraig pushed a commit to bigkraig/terraform that referenced this issue Mar 1, 2016
Implementation notes:

 * The hash implementation was not considering key value, causing "diffs
   did not match" errors when a value was updated. Switching to default
   HashResource implementation fixes this
 * Using HashResource as a default exposed a bug in helper/schema that
   needed to be fixed so the Set function is picked up properly during
   Read
 * Stop writing back values into the `key` attribute; it triggers extra
   diffs when `default` is used. Computed values all just go into `var`.
 * Includes a state migration to prevent unnecessary diffs based on
   "key" attribute hashcodes changing.

In the tests:

 * Switch from leaning on the public demo Consul instance to requiring a
   CONSUL_HTTP_ADDR variable be set pointing to a `consul agent -dev`
   instance to be used only for testing.
 * Add a test that exposes the updating issues and covers the fixes

Fixes hashicorp#774
Fixes hashicorp#1866
Fixes hashicorp#3023
@ghost
Copy link

ghost commented Apr 28, 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 Apr 28, 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.

4 participants