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

ignore_changes lifecycle policies preventing initialization of a resource element #5280

Closed
lussier opened this issue Feb 23, 2016 · 8 comments

Comments

@lussier
Copy link

lussier commented Feb 23, 2016

Hi,

When I set a lifecycle policy to ignore_changes, it won't let me apply an initial value to the targeted parameter. Is this the expected behavior?

For example, let's say I assign this policy to an aws_network_interface:

lifecycle { "ignore_changes" = ["private_ips"] }

And I also configure this as part of the resource:

private_ip = "10.1.1.1"

Then when I apply for the first time, Terraform (current master version) will ignore the 10.1.1.1 private_ip I configured. I was expecting it to ignore changes that arise after creation, but not to ignore my initial configuration.

@mtougeron
Copy link
Contributor

I'm having this same issue. Here is some code to reproduce this problem.

The code itself:

provider "openstack" {}

resource "openstack_compute_instance_v2" "server" {
  name = "tf-ignore-change-bug"

  key_pair = "terraform"

  region = "RegionOne"
  availability_zone = "sjc1-prod-1a"
  image_name = "centos_6.4_20150128"
  flavor_name = "m1.small"

  network {
    uuid = "c60e802c-516d-42f8-8b01-d9b120f245a9"
  }

  security_groups = [
    "default-internal-only"
  ]

  lifecycle {
    ignore_changes = ["key_pair", "image_name"]
    create_before_destroy = true
  }
}

Running the terraform plan shows no problems.

$> terraform plan
Refreshing Terraform state prior to plan...


The Terraform execution plan has been generated and is shown below.
Resources are shown in alphabetical order for quick scanning. Green resources
will be created (or destroyed and then created if an existing resource
exists), yellow resources are being changed in-place, and red resources
will be destroyed.

Note: You didn't specify an "-out" parameter to save this plan, so when
"apply" is called, Terraform can't guarantee this is what will execute.

+ openstack_compute_instance_v2.server
    access_ip_v4:               "" => "<computed>"
    access_ip_v6:               "" => "<computed>"
    availability_zone:          "" => "sjc1-prod-1a"
    flavor_id:                  "" => "<computed>"
    flavor_name:                "" => "m1.small"
    image_id:                   "" => "<computed>"
    name:                       "" => "tf-ignore-change-bug"
    network.#:                  "" => "1"
    network.0.access_network:   "" => "0"
    network.0.fixed_ip_v4:      "" => "<computed>"
    network.0.fixed_ip_v6:      "" => "<computed>"
    network.0.floating_ip:      "" => "<computed>"
    network.0.mac:              "" => "<computed>"
    network.0.name:             "" => "<computed>"
    network.0.port:             "" => "<computed>"
    network.0.uuid:             "" => "c60e802c-516d-42f8-8b01-d9b120f245a9"
    region:                     "" => "RegionOne"
    security_groups.#:          "" => "1"
    security_groups.2993421007: "" => "default-internal-only"
    volume.#:                   "" => "<computed>"


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

But when trying to run terraform apply it fails.

$> terraform apply
openstack_compute_instance_v2.server: Creating...
  access_ip_v4:               "" => "<computed>"
  access_ip_v6:               "" => "<computed>"
  availability_zone:          "" => "sjc1-prod-1a"
  flavor_id:                  "" => "<computed>"
  flavor_name:                "" => "m1.small"
  image_id:                   "" => "<computed>"
  name:                       "" => "tf-ignore-change-bug"
  network.#:                  "" => "1"
  network.0.access_network:   "" => "0"
  network.0.fixed_ip_v4:      "" => "<computed>"
  network.0.fixed_ip_v6:      "" => "<computed>"
  network.0.floating_ip:      "" => "<computed>"
  network.0.mac:              "" => "<computed>"
  network.0.name:             "" => "<computed>"
  network.0.port:             "" => "<computed>"
  network.0.uuid:             "" => "c60e802c-516d-42f8-8b01-d9b120f245a9"
  region:                     "" => "RegionOne"
  security_groups.#:          "" => "1"
  security_groups.2993421007: "" => "default-internal-only"
  volume.#:                   "" => "<computed>"
Error applying plan:

1 error(s) occurred:

* openstack_compute_instance_v2.server: Neither a boot device, image ID, or image name were able to be determined.

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.

@mtougeron
Copy link
Contributor

Also related to this is another scenario that isn't working as expected with ignore_changes

I've created a server using the same bug.tf that I showed previously but with the ignore_changes commented out.

$> terraform apply
openstack_compute_instance_v2.server: Creating...
  access_ip_v4:               "" => "<computed>"
  access_ip_v6:               "" => "<computed>"
  availability_zone:          "" => "sjc1-prod-1a"
  flavor_id:                  "" => "<computed>"
  flavor_name:                "" => "m1.small"
  image_id:                   "" => "<computed>"
  image_name:                 "" => "centos_6.4_20150128"
  key_pair:                   "" => "terraform"
  name:                       "" => "tf-ignore-change-bug"
  network.#:                  "" => "1"
  network.0.access_network:   "" => "0"
  network.0.fixed_ip_v4:      "" => "<computed>"
  network.0.fixed_ip_v6:      "" => "<computed>"
  network.0.floating_ip:      "" => "<computed>"
  network.0.mac:              "" => "<computed>"
  network.0.name:             "" => "<computed>"
  network.0.port:             "" => "<computed>"
  network.0.uuid:             "" => "c60e802c-516d-42f8-8b01-d9b120f245a9"
  region:                     "" => "RegionOne"
  security_groups.#:          "" => "1"
  security_groups.2993421007: "" => "default-internal-only"
  volume.#:                   "" => "<computed>"
openstack_compute_instance_v2.server: Creation complete

Apply complete! Resources: 1 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

Immediately after creation, I ran terraform plan to see if there were any changes. There were none shown.

$> terraform plan 
Refreshing Terraform state prior to plan...

openstack_compute_instance_v2.server: Refreshing state... (ID: 6be5ead6-48a4-4efc-8f65-1dfa4ddaffbc)

No changes. Infrastructure is up-to-date. This means that Terraform
could not detect any differences between your configuration and
the real physical resources that exist. As a result, Terraform
doesn't need to do anything.

Then I put back in the ignore_changes = ["key_pair", "image_name"] and changed the resource's image_name to image_name = "centos_6.4_20160114" and ran terraform plan again. This time it showed that there were a lot of changes to be made. It should have found that there was nothing to change as the only thing changed was image_name and that was listed in the ignore_changes list.

$> terraform plan
Refreshing Terraform state prior to plan...

openstack_compute_instance_v2.server: Refreshing state... (ID: 6be5ead6-48a4-4efc-8f65-1dfa4ddaffbc)

The Terraform execution plan has been generated and is shown below.
Resources are shown in alphabetical order for quick scanning. Green resources
will be created (or destroyed and then created if an existing resource
exists), yellow resources are being changed in-place, and red resources
will be destroyed.

Note: You didn't specify an "-out" parameter to save this plan, so when
"apply" is called, Terraform can't guarantee this is what will execute.

-/+ openstack_compute_instance_v2.server
    access_ip_v4:               "10.161.34.194" => "<computed>"
    access_ip_v6:               "" => "<computed>"
    availability_zone:          "sjc1-prod-1a" => "sjc1-prod-1a"
    flavor_id:                  "286a01ad-dea5-4a6c-8763-6912cc5acf55" => "<computed>"
    flavor_name:                "m1.small" => "m1.small"
    image_id:                   "14641da2-4bbe-4de3-bd9b-ddbe56fed9f6" => "<computed>"
    name:                       "tf-ignore-change-bug" => "tf-ignore-change-bug"
    network.#:                  "1" => "1"
    network.0.access_network:   "false" => "0"
    network.0.fixed_ip_v4:      "10.161.34.194" => "<computed>"
    network.0.fixed_ip_v6:      "" => "<computed>"
    network.0.floating_ip:      "" => "<computed>"
    network.0.mac:              "02:af:70:06:4d:0b" => "<computed>"
    network.0.name:             "dev-1-private-1a" => "<computed>"
    network.0.port:             "" => "<computed>"
    network.0.uuid:             "c60e802c-516d-42f8-8b01-d9b120f245a9" => "c60e802c-516d-42f8-8b01-d9b120f245a9"
    region:                     "RegionOne" => "RegionOne"
    security_groups.#:          "1" => "1"
    security_groups.2993421007: "default-internal-only" => "default-internal-only"
    volume.#:                   "0" => "<computed>"


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

I ran terraform apply anyway to determine if the bug was also in the apply code. This resulted in a hard crash of terraform. ;(

$> terraform apply
openstack_compute_instance_v2.server: Refreshing state... (ID: 6be5ead6-48a4-4efc-8f65-1dfa4ddaffbc)
Error applying plan:

1 error(s) occurred:

* openstack_compute_instance_v2.server: diffs didn't match during apply. This is a bug with Terraform and should be reported as a GitHub Issue.

Please include the following information in your report:

    Terraform Version: 0.6.12
    Resource ID: openstack_compute_instance_v2.server
    Mismatch reason: diff RequiresNew; old: false, new: true
    Diff One (usually from plan): *terraform.InstanceDiff{Attributes:map[string]*terraform.ResourceAttrDiff{"network.#":*terraform.ResourceAttrDiff{Old:"1", New:"1", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "network.0.access_network":*terraform.ResourceAttrDiff{Old:"false", New:"0", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "name":*terraform.ResourceAttrDiff{Old:"tf-ignore-change-bug", New:"tf-ignore-change-bug", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "flavor_id":*terraform.ResourceAttrDiff{Old:"286a01ad-dea5-4a6c-8763-6912cc5acf55", New:"", NewComputed:true, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "flavor_name":*terraform.ResourceAttrDiff{Old:"m1.small", New:"m1.small", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "security_groups.2993421007":*terraform.ResourceAttrDiff{Old:"default-internal-only", New:"default-internal-only", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "volume.#":*terraform.ResourceAttrDiff{Old:"0", New:"", NewComputed:true, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "availability_zone":*terraform.ResourceAttrDiff{Old:"sjc1-prod-1a", New:"sjc1-prod-1a", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "access_ip_v4":*terraform.ResourceAttrDiff{Old:"10.161.34.194", New:"", NewComputed:true, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "network.0.name":*terraform.ResourceAttrDiff{Old:"dev-1-private-1a", New:"", NewComputed:true, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "access_ip_v6":*terraform.ResourceAttrDiff{Old:"", New:"", NewComputed:true, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "network.0.uuid":*terraform.ResourceAttrDiff{Old:"c60e802c-516d-42f8-8b01-d9b120f245a9", New:"c60e802c-516d-42f8-8b01-d9b120f245a9", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "network.0.fixed_ip_v6":*terraform.ResourceAttrDiff{Old:"", New:"", NewComputed:true, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "network.0.fixed_ip_v4":*terraform.ResourceAttrDiff{Old:"10.161.34.194", New:"", NewComputed:true, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "network.0.floating_ip":*terraform.ResourceAttrDiff{Old:"", New:"", NewComputed:true, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "image_id":*terraform.ResourceAttrDiff{Old:"14641da2-4bbe-4de3-bd9b-ddbe56fed9f6", New:"", NewComputed:true, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "region":*terraform.ResourceAttrDiff{Old:"RegionOne", New:"RegionOne", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "network.0.mac":*terraform.ResourceAttrDiff{Old:"02:af:70:06:4d:0b", New:"", NewComputed:true, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "security_groups.#":*terraform.ResourceAttrDiff{Old:"1", New:"1", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "network.0.port":*terraform.ResourceAttrDiff{Old:"", New:"", NewComputed:true, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}}, Destroy:false, DestroyTainted:false}
    Diff Two (usually from apply): *terraform.InstanceDiff{Attributes:map[string]*terraform.ResourceAttrDiff{"flavor_name":*terraform.ResourceAttrDiff{Old:"", New:"m1.small", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "network.0.floating_ip":*terraform.ResourceAttrDiff{Old:"", New:"", NewComputed:true, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "image_id":*terraform.ResourceAttrDiff{Old:"", New:"", NewComputed:true, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:true, Type:0x0}, "network.0.access_network":*terraform.ResourceAttrDiff{Old:"", New:"0", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "network.0.port":*terraform.ResourceAttrDiff{Old:"", New:"", NewComputed:true, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "network.0.uuid":*terraform.ResourceAttrDiff{Old:"", New:"c60e802c-516d-42f8-8b01-d9b120f245a9", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "name":*terraform.ResourceAttrDiff{Old:"", New:"tf-ignore-change-bug", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "network.0.mac":*terraform.ResourceAttrDiff{Old:"", New:"", NewComputed:true, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "flavor_id":*terraform.ResourceAttrDiff{Old:"", New:"", NewComputed:true, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "volume.#":*terraform.ResourceAttrDiff{Old:"", New:"", NewComputed:true, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "access_ip_v6":*terraform.ResourceAttrDiff{Old:"", New:"", NewComputed:true, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "security_groups.#":*terraform.ResourceAttrDiff{Old:"", New:"1", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "network.0.fixed_ip_v6":*terraform.ResourceAttrDiff{Old:"", New:"", NewComputed:true, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "region":*terraform.ResourceAttrDiff{Old:"", New:"RegionOne", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:true, Type:0x0}, "network.#":*terraform.ResourceAttrDiff{Old:"", New:"1", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:true, Type:0x0}, "network.0.name":*terraform.ResourceAttrDiff{Old:"", New:"", NewComputed:true, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "network.0.fixed_ip_v4":*terraform.ResourceAttrDiff{Old:"", New:"", NewComputed:true, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "security_groups.2993421007":*terraform.ResourceAttrDiff{Old:"", New:"default-internal-only", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "availability_zone":*terraform.ResourceAttrDiff{Old:"", New:"sjc1-prod-1a", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:true, Type:0x0}, "access_ip_v4":*terraform.ResourceAttrDiff{Old:"", New:"", NewComputed:true, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}}, Destroy:false, DestroyTainted:false}

Also include as much context as you can about your config, state, and the steps you performed to trigger this error.


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.

Please let me know if you need any additional information for reproducing this issue.

Thanks,
Mike

@jtopjian
Copy link
Contributor

Hi guys,

Thanks for the info and sorry to see you're running into this. I'll take a look as soon as I can and see if I can pinpoint the problem.

Thanks,
Joe

@mtougeron
Copy link
Contributor

Thanks @jtopjian! Let me know if you need anything.

@jtopjian
Copy link
Contributor

I re-read this issue and missed the first message that included aws_network_interface. Since this is affecting both the AWS and OpenStack provider, I'm going to re-classify this as a "core" bug.

@phinze
Copy link
Contributor

phinze commented Mar 14, 2016

Hi folks, I'm working on ignore_changes problems today and I've opened an issue to consolidate everything: #5627

@phinze phinze closed this as completed Mar 14, 2016
@mtougeron
Copy link
Contributor

Thanks!

@ghost
Copy link

ghost commented Apr 27, 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 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants