Current Terraform Version
terraform -v
v0.12.19
Use-cases
i have created many vms into one resource and i want to delete only one vm tagged by its key
terraform state list
cloudplatform_compute_instance.vms["AmbariMaas"]
I am using a custommized provider
resource "cloudplatform_compute_instance" "vms" {
for_each = {
for server in local.all_servers : "${server.name}" => server
}
name = each.value.name
flavor_ref = data.cloudplatform_compute_flavor.flavor[each.value.flavor].id
port = cloudplatform_compute_port.fixed_ip[each.value.port].id
image_ref = data.cloudplatform_compute_image.test.id
key_name = var.ssh_key_name
availability_zone = var.az
description = ""
tags = each.value.tags
server_group = cloudplatform_compute_server_group.cluster[each.value.group].id
resource "cloudplatform_compute_volume" "volumes" {
for_each = {
for volume in local.all_volumes : "${volume.suffix}.${volume.server}" => volume
}
name = format("%s-%s", each.value.server, each.value.suffix )
size = each.value.size
volume_type = "tiefighter"
availability_zone = var.az
}
resource "cloudplatform_compute_volume_attachement" "mount" {
for_each = {
for volume in local.all_volumes : "${volume.suffix}.${volume.server}" => volume
}
volume_id = cloudplatform_compute_volume.volumes[each.key].id
server_id = cloudplatform_compute_instance.vms[each.value.server].id
}
in terraform.tfvars
servers_definitions = {
AmbariMaas = {
names = ["AmbariMaas"]
tags = [ "MaasDev", "hdf-masternode-01" ]
group = "maas_master_group"
flavor = "Large-mem16 4vCPU-16GB"
volumes = {
volume1 = {
"suffix" = "hadoop"
"size" = "450"
"moun_dir" = "/DATA/hadoop"
}
volume2 = {
"suffix" = "log"
"size" = "50"
"moun_dir" = "/DATA/log"
}
}
}
}
in vars.tf
locals {
all_volumes = flatten([
for server in var.servers_definitions : [
for name in server.names : [
for volume in server.volumes : {
size = volume.size
suffix = volume.suffix
server = name
}
]
]
])
all_servers = flatten([
for server in var.servers_definitions : [
for name in server.names : [
{
name = name
port = format("%sPort", name)
tags = server.tags
flavor = server.flavor
group = server.group
volumes = server.volumes
}
]
]
])
}
Attempted Solutions
I have tried this command
terraform plan -destroy -target 'cloudplatform_compute_instance.vms["AmbariMaas"]'
But it will planify to destroy the vm as well as its all resource dependecies (volumes and mount) of other servers.
when i try to destroy a specific element of mount resource, it is working because it does not have dependencies.
Do you recommend another method to define my global architecture of servers?