Closed wongak closed 8 months ago
@wongak Hello I cannot reproduce this case even with more than one ports attached to instance:
data "opentelekomcloud_networking_secgroup_v2" "default_sg" {
name = "default"
}
resource "opentelekomcloud_networking_floatingip_v2" "instance_fip" {
port_id = opentelekomcloud_networking_port_v2.instance_port_1.id
}
resource "opentelekomcloud_networking_port_v2" "instance_port_1" {
name = "instance-port-1"
admin_state_up = "true"
network_id = data.opentelekomcloud_vpc_subnet_v1.shared_subnet.network_id
security_group_ids = [
data.opentelekomcloud_networking_secgroup_v2.default_sg.id
]
}
resource "opentelekomcloud_networking_port_v2" "instance_port_2" {
name = "instance-port-2"
admin_state_up = "true"
network_id = data.opentelekomcloud_vpc_subnet_v1.shared_subnet.network_id
security_group_ids = [
data.opentelekomcloud_networking_secgroup_v2.default_sg.id
]
}
resource "opentelekomcloud_compute_instance_v2" "instance_1" {
name = "instance_1"
image_id = data.opentelekomcloud_images_image_v2.latest_image.id
availability_zone = "%s"
metadata = {
foo = "bar"
}
network {
port = opentelekomcloud_networking_port_v2.instance_port_1.id
}
network {
port = opentelekomcloud_networking_port_v2.instance_port_2.id
}
tags = {
muh = "value-create"
kuh = "value-create"
}
}
Maybe you have some dependencies inside tf config? Please provide more details.
P.S.: port detaching happens inside api we cannot detach it like in openstack, but we did all possible check and waits in terraform and do not leave resources in active state while detaching
I have pretty much the same config. Since this happens intermittently I am suspecting that it is a race condition.
This occurred now a couple of times on our domain.
data "opentelekomcloud_networking_secgroup_v2" "default_sg" { name = "default" } resource "opentelekomcloud_networking_floatingip_v2" "instance_fip" { count = var.create ? 1 : 0 port_id = opentelekomcloud_networking_port_v2.instance_port_1[0].id } resource "opentelekomcloud_networking_port_v2" "instance_port_1" { . count = var.create ? 1 : 0 name = "instance-port-1" admin_state_up = "true" network_id = data.opentelekomcloud_vpc_subnet_v1.shared_subnet.network_id security_group_ids = [ data.opentelekomcloud_networking_secgroup_v2.default_sg.id ] } resource "opentelekomcloud_networking_port_v2" "instance_port_2" { name = "instance-port-2" admin_state_up = "true" network_id = data.opentelekomcloud_vpc_subnet_v1.shared_subnet.network_id security_group_ids = [ data.opentelekomcloud_networking_secgroup_v2.default_sg.id ] } resource "opentelekomcloud_compute_instance_v2" "instance_1" { . count = var.create ? 1 : 0 name = "instance_1" image_id = data.opentelekomcloud_images_image_v2.latest_image.id availability_zone = "%s" metadata = { foo = "bar" } network { port = opentelekomcloud_networking_port_v2.instance_port_1.id } network { port = opentelekomcloud_networking_port_v2.instance_port_2.id } tags = { muh = "value-create" kuh = "value-create" } }
We do have conditional creation of the resources though. Maybe this happens if we set var.create
to 0, which should destroy the resources as well.
Terraform provider version
Affected Resource(s)
terraform apply
Expected Behavior
Resources are created.
Actual Behavior
No problem.
terraform destroy
Expected Behavior
Instance and Port are destroyed
Actual Behavior
Intermittently the port cannot be destroyed, since it is still in a connected state to the destroyed instance.
Important Factoids
This leaves the port, subnet, network in an unmanageable state, since the port resource cannot be detroyed.
It might be a race condition, since it happens intermittently. The port should always be disconnected before destroying the instance.
Openstack provides a flag for that: https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest/docs/resources/compute_instance_v2#detach_ports_before_destroy