Hi,
I ran into a situation where Terraform does not update/delete resources, and I’d like to learn if this is a bug (either in the Oracle OCI provider or in Terraform) and if there is an alternative solution.
First, I create a VCN and subnet:
locals {
tenancy_id = "..."
}
resource "oci_core_vcn" "main_vcn" {
compartment_id = local.tenancy_id
cidr_blocks = ["10.0.0.0/16"]
display_name = "main-vcn"
}
resource "oci_core_subnet" "main_subnet" {
cidr_block = "10.0.0.0/24"
compartment_id = local.tenancy_id
vcn_id = oci_core_vcn.main_vcn.id
display_name = "main-subnet"
}
Terraform successfully creates these resources. Now I add a security list:
resource "oci_core_security_list" "main_security_list" {
compartment_id = local.tenancy_id
vcn_id = oci_core_vcn.main_vcn.id
display_name = "main_security_list"
}
resource "oci_core_subnet" "main_subnet" {
cidr_block = "10.0.0.0/24"
compartment_id = local.tenancy_id
vcn_id = oci_core_vcn.main_vcn.id
display_name = "main-subnet"
security_list_ids = [oci_core_security_list.main_security_list.id]
}
Terraform succeeds in creating the security list and updating the subnet to use the security list.
The problem is: if I now rollback to the first version (without the security list), Terraform only plans to destroy the security list. However, OCI won’t let you destroy a security list that is used by a subnet. The right thing to do is to 1. update the subnet to no longer use the security list and then 2. delete the security list.
How come Terraform does not understand this? Is this a bug in the OCI Terraform provider or in Terraform itself? And what is the best practice in this situation?