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

Terraform does mot respect explicit dependency in some cases #16420

Closed
HWE70 opened this issue Oct 23, 2017 · 1 comment
Closed

Terraform does mot respect explicit dependency in some cases #16420

HWE70 opened this issue Oct 23, 2017 · 1 comment

Comments

@HWE70
Copy link

HWE70 commented Oct 23, 2017

Terraform Version

Terraform v0.10.7

Terraform Configuration Files

# -------------------------------------------------------------------------------------------------------------
# Allocate block storage for Service VMs
# -------------------------------------------------------------------------------------------------------------

resource "null_resource" "service_voldef" {
  count       = "${length(local.os_service_vols_def)}"

  triggers {
        node                = "${element(local.os_service_vols_node, count.index)}"
        volume_type         = "${element(split(":",element(local.os_service_vols_def, count.index)),0)}"
        device              = "${element(split(":",element(local.os_service_vols_def, count.index)),1)}"
        rel_name            = "${element(split(":",element(local.os_service_vols_def, count.index)),2)}"
        size                = "${element(split(":",element(local.os_service_vols_def, count.index)),3)}"
        mountpoint          = "${element(split(":",element(local.os_service_vols_def, count.index)),4)}"
        availability_zone   = "${element(local.os_service_vols_az, count.index)}"
  }
}

resource "openstack_blockstorage_volume_v2" "setup_service_volumes" {
  depends_on           = ["null_resource.service_voldef"]
  count                = "${length(local.os_service_vols_def)}"
  name                 = "${element(null_resource.service_voldef.*.triggers.node, count.index)}_${element(null_resource.service_voldef.*.triggers.rel_name, count.index)}"
  description          = "Persitent storage for ${element(null_resource.service_voldef.*.triggers.node, count.index)} device ${element(null_resource.service_voldef.*.triggers.device, count.index)}"
  size                 = "${element(null_resource.service_voldef.*.triggers.size, count.index)}"
  volume_type          = "${element(null_resource.service_voldef.*.triggers.volume_type, count.index)}"
  availability_zone    = "${element(null_resource.service_voldef.*.triggers.availability_zone, count.index)}"

  #lifecycle {
  #    prevent_destroy = true
  #}
}

# --------------------------------------------------------------------------------------------------
# Attach block storage to Service VMs
# --------------------------------------------------------------------------------------------------

#
# Search for matching pairs of instance and volume ids
#
resource "null_resource" "service_volid" {
  depends_on           = ["openstack_blockstorage_volume_v2.setup_service_volumes","openstack_compute_instance_v2.service"]
  count                = "${length(local.os_service_vols_def)}"

  triggers {
        volume_id      = "${element(openstack_blockstorage_volume_v2.setup_service_volumes.*.id, count.index)}"
        instance_id    = "${element(openstack_compute_instance_v2.service.*.id, index(openstack_compute_instance_v2.service.*.name, element(local.os_service_vols_node, count.index)))}"
  }
}

#
# Attach persistent storage
#
resource "openstack_compute_volume_attach_v2" "service" {
  depends_on  = ["null_resource.service_volid","openstack_blockstorage_volume_v2.setup_service_volumes","openstack_compute_instance_v2.service"]
  count       = "${length(local.os_service_vols_def)}"
  instance_id = "${element(null_resource.service_volid.*.triggers.instance_id, count.index)}"
  volume_id   = "${element(null_resource.service_volid.*.triggers.volume_id, count.index)}"
  device      = "${element(null_resource.service_voldef.*.triggers.device, count.index)}"
}

#
# Dummy resource for build process
#
resource "null_resource" "target_service_volumes" {
        depends_on = ["openstack_blockstorage_volume_v2.setup_service_volumes",
                      "openstack_compute_volume_attach_v2.service",
                      "null_resource.service_volid"]
}

Output

Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

null_resource.nodes_service[0]: Refreshing state... (ID: 6013027129072800198)
null_resource.nodes_service[1]: Refreshing state... (ID: 1842577283801475772)
null_resource.volumes_service[0]: Refreshing state... (ID: 931939086905373848)
null_resource.volumes_service[2]: Refreshing state... (ID: 4302373968823752440)
null_resource.volumes_service[1]: Refreshing state... (ID: 8676549776352687611)
null_resource.volumes_service[3]: Refreshing state... (ID: 3907152824123562973)
openstack_compute_instance_v2.service[0]: Refreshing state... (ID: 39749ebf-f15a-4547-bd3d-0e7344acddf9)
openstack_compute_instance_v2.service[1]: Refreshing state... (ID: 7605c41d-71a1-42d2-a4a9-5e94fe07241c)

------------------------------------------------------------------------
Error running plan: 1 error(s) occurred:

* openstack_compute_volume_attach_v2.service: 4 error(s) occurred:

* openstack_compute_volume_attach_v2.service[1]: Resource 'null_resource.service_volid' does not have attribute 'triggers.instance_id' for variable 'null_resource.service_volid.*.triggers.instance_id'
* openstack_compute_volume_attach_v2.service[3]: Resource 'null_resource.service_volid' does not have attribute 'triggers.instance_id' for variable 'null_resource.service_volid.*.triggers.instance_id'
* openstack_compute_volume_attach_v2.service[0]: Resource 'null_resource.service_volid' does not have attribute 'triggers.instance_id' for variable 'null_resource.service_volid.*.triggers.instance_id'
* openstack_compute_volume_attach_v2.service[2]: Resource 'null_resource.service_volid' does not have attribute 'triggers.volume_id' for variable 'null_resource.service_volid.*.triggers.volume_id'

Expected Behavior

The instnaces are already in place. Volumes should be created and attached in one step. Expected behaviour is:

  1. Calculate plan
  2. Create volumes
  3. Generate ids in "null_resource.service_volid"
  4. Attach volumes

Actual Behavior

Between setting up the volumes in "openstack_blockstorage_volume_v2.setup_service_volumes" and attaching them in "openstack_compute_volume_attach_v2.service" I need generate the imstnace ids the volumes have to be attached to using "null_resource.service_volid". For this reason explicite dependencies are defined. But terraform ignores the dependecy for "openstack_blockstorage_volume_v2.setup_service_volumes" in "null_resource.service_volid" and fails with the errors above.

Steps to Reproduce

  1. terraform plan -target=null_resource.target_service_volumes -out=/tmp/.sh_9398.tfplan
  2. terraform apply /tmp/.sh_9398.tfplan

Important Factoids

If splitting it off in two parts end first create the volumes:

terraform plan -target=openstack_blockstorage_volume_v2.setup_service_volumes -out=/tmp/tfplan
terraform apply /tmp/tfplan

Everything works fine.

References

@ghost
Copy link

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

3 participants