#terraform #openstack
Вопрос:
У меня есть среда с несколькими экземплярами OpenStack, настроенными с использованием Terraform 0.14.6. Теперь я хочу изменить только один экземпляр с помощью -target=<resource>
. Terraform правильно выбирает только один экземпляр, но он также нацелен на все зависимые ресурсы других экземпляров:
> terraform plan -destroy -var-file=env-prod.tfvars -target='openstack_compute_instance_v2.bamboo_agent[0]'
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:
# openstack_compute_floatingip_associate_v2.bamboo[0] will be destroyed
- resource "openstack_compute_floatingip_associate_v2" "bamboo" {
...
}
# openstack_compute_floatingip_associate_v2.bamboo[1] will be destroyed
- resource "openstack_compute_floatingip_associate_v2" "bamboo" {
...
}
# openstack_compute_floatingip_associate_v2.bamboo[2] will be destroyed
- resource "openstack_compute_floatingip_associate_v2" "bamboo" {
...
}
# openstack_compute_instance_v2.bamboo_agent[0] will be destroyed
- resource "openstack_compute_instance_v2" "bamboo_agent" {
...
}
# openstack_compute_volume_attach_v2.attach_agent[0] will be destroyed
- resource "openstack_compute_volume_attach_v2" "attach_agent" {
...
}
# openstack_compute_volume_attach_v2.attach_agent[1] will be destroyed
- resource "openstack_compute_volume_attach_v2" "attach_agent" {
...
}
# openstack_compute_volume_attach_v2.attach_agent[2] will be destroyed
- resource "openstack_compute_volume_attach_v2" "attach_agent" {
...
}
# openstack_compute_volume_attach_v2.attach_docker[0] will be destroyed
- resource "openstack_compute_volume_attach_v2" "attach_docker" {
...
}
# openstack_compute_volume_attach_v2.attach_docker[1] will be destroyed
- resource "openstack_compute_volume_attach_v2" "attach_docker" {
...
}
# openstack_compute_volume_attach_v2.attach_docker[2] will be destroyed
- resource "openstack_compute_volume_attach_v2" "attach_docker" {
...
}
Plan: 0 to add, 0 to change, 10 to destroy.
Часть конфигурации Terraform:
resource "openstack_compute_instance_v2" "bamboo_agent" {
name = var.agents[count.index].name
image_name = var.image
flavor_name = var.agents[count.index].flavor
user_data = file("scripts/cloud-config.yml")
network {
port = openstack_networking_port_v2.bamboo[count.index].id
}
count= length(var.agents)
}
# create Volume
resource "openstack_blockstorage_volume_v2" "volume_agent" {
name = format("volume-agent-${terraform.workspace}-%s", count.index)
description = "volume for bamboo agent data"
size = 50
count = length(var.agents)
}
...
# attach volume
resource "openstack_compute_volume_attach_v2" "attach_agent" {
instance_id = openstack_compute_instance_v2.bamboo_agent[count.index].id
volume_id = openstack_blockstorage_volume_v2.volume_agent[count.index].id
device = "/dev/vdc"
count = length(var.agents)
}
# Attach floating ip to instance
resource "openstack_compute_floatingip_associate_v2" "bamboo" {
floating_ip = var.agents[count.index].ip
instance_id = openstack_compute_instance_v2.bamboo_agent[count.index].id
count = length(var.agents)
}
...
env.prod.tfvars file (masked):
image = "XXX"
agents = [
{
name = "XXX-0"
uuid = "XXX"
id = "XXX"
ip = "x.x.x.x"
flavor = "XXX"
},
{
name = "XXX-1"
id = "XXX"
uuid = "XXX"
ip = "x.x.x.x"
flavor = "XXX"
},
{
name = "XXX-2"
id = "114393114"
uuid = "XXX"
ip = "x.x.x.x"
flavor = "XXX"
}
]
Как я могу применить только к одному экземпляру и его ресурсам, чтобы другие экземпляры продолжали работать?