Skip to content

Instantly share code, notes, and snippets.

@falzm
Created May 7, 2019 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save falzm/18d7b38fec3303cfbba8837adceb245c to your computer and use it in GitHub Desktop.
Save falzm/18d7b38fec3303cfbba8837adceb245c to your computer and use it in GitHub Desktop.
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
Copy link
Author

falzm 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