Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Terraform sample configuration illustrating a bug with targeted "destroy" command
# This example uses the Exoscale provider:
# https://github.com/exoscale/terraform-provider-exoscale/
locals {
zone = "ch-gva-2"
key_pair = "default"
hostnames = [
"ch2771-test1",
"ch2771-test2",
"ch2771-test3",
]
}
resource "exoscale_network" "privnet" {
zone = "${local.zone}"
name = "ch2771"
network_offering = "PrivNet"
}
resource "exoscale_compute" "machine" {
count = "${length(local.hostnames)}"
zone = "${local.zone}"
display_name = "${element(local.hostnames, count.index)}"
size = "Micro"
disk_size = "10"
template = "Linux Ubuntu 18.04 LTS 64-bit"
key_pair = "${local.key_pair}"
}
resource "exoscale_nic" "machine" {
count = "${length(local.hostnames)}"
compute_id = "${exoscale_compute.machine.*.id[count.index]}"
network_id = "${exoscale_network.privnet.id}"
}
@falzm

This comment has been minimized.

Copy link
Owner Author

commented May 7, 2019

The problem: when trying to destroy one of the exoscale_compute instances using the -target option, all the exoscale_nic resources would be destroyed by Terraform although only the one corresponding to the targeted instance should:

$ terraform destroy -target 'exoscale_compute.machine[2]'
exoscale_compute.machine[2]: Refreshing state... (ID: cb24c3a4-4e6f-4b07-8ade-f0db49b2d9de)

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

Terraform will perform the following actions:

  - exoscale_compute.machine[2]

  - exoscale_nic.machine[0]

  - exoscale_nic.machine[1]

  - exoscale_nic.machine[2]


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

Do you really want to destroy all resources?
  Terraform will destroy all your managed infrastructure, as shown above.
  There is no undo. Only 'yes' will be accepted to confirm.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.