Skip to content

Bug: Seclist resource does not get deleted with VCN resource count is changed #411

@sanketdjain

Description

@sanketdjain

Terraform Version

Terraform v0.11.1

provider.null v1.0.0
provider.oci v2.0.5
provider.template v1.0.0

OCI Provider Version

oci_v2.0.5 
2018/01/05 09:35:28 [INFO] terraform-provider-oci 2.0.5

Description:

I have a virtual network resource with a conditional count (see test case below).

  1. Create the virtual network resource and the subnets and seclists
  2. Set count of virtual network resource to zero, this will automatically delete the VCN resource and subnet resource, but it does not delete the seclist resource.

Test case

networking.tf

locals {
  create_vcn   = "${var.vcn_id == "" ? 1 : 0}"
  subnet_count = "${local.create_vcn == 1 ? length(data.oci_identity_availability_domains.ADs.availability_domains) : 0}"
}

resource "oci_core_virtual_network" "vcn1" {
    count = "${local.create_vcn}"
    cidr_block = "${var.cidr_block}"
    compartment_id = "${oci_identity_compartment.comp_network.id}"
    display_name = "VCN_${replace(var.comp_name, "COMP_", "")}"
    dns_label    = "vcn${format("%0.5s", replace(var.comp_name, "COMP_", ""))}"
}

....
....

resource "oci_core_subnet" "sub_app" {
  count = "${local.subnet_count}"
  availability_domain = "${lookup(data.oci_identity_availability_domains.ADs.availability_domains[count.index], "name")}"
  cidr_block = "${cidrsubnet(var.cidr_block, 6, count.index + var.app_block)}"
  display_name = "${format("%s%s","sub_app", "${count.index}")}"
  dns_label = "${format("%s%s","subapp", "${count.index}")}"
  compartment_id = "${oci_core_virtual_network.vcn1.compartment_id}"
  vcn_id = "${oci_core_virtual_network.vcn1.id}"
  security_list_ids = ["${oci_core_security_list.sec_app.id}"]
  route_table_id = "${oci_core_default_route_table.rt_service.id}"
  dhcp_options_id = "${oci_core_virtual_network.vcn1.default_dhcp_options_id}"
  #prohibit_public_ip_on_vnic = true

  provisioner "local-exec" {
       command = "sleep 5"
  }
}

seclist.tf

/* app seclist */
resource "oci_core_security_list" "sec_app" {
  compartment_id = "${oci_core_virtual_network.vcn1.compartment_id}"
  vcn_id = "${oci_core_virtual_network.vcn1.id}"
  display_name = "sec_app"

  /* allow outbound tcp traffic on all ports */
  egress_security_rules {
    destination = "0.0.0.0/0"
    protocol = "6" // tcp
  }

  /* allow inbound ssh traffic */
  ingress_security_rules {
    protocol = "6" // tcp
    source = "0.0.0.0/0"
    stateless = false

    tcp_options {
      "min" = 22
      "max" = 22
    }
  }
}

variables.tf

variable "vcn_id" {
  default = ""
  description = "ID of existing VCN"
}

variable "cidr_block" {
  default = "10.0.0.0/16"
  description = "CIDR Block for VCN"
}

Terraform Plan

Terraform Plan is showing some sensitive information in shell scripts of templates, so I have included the test case above.

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  - destroy
 <= read (data resources)

Terraform will perform the following actions:

 <= data.oci_core_images.img
      id:             <computed>
      compartment_id: "ocid1.compartment.oc1..aaaaaaaanzpexwmcbowil3ghu4p6rljx7kcxpklkktka5bdy4o5fvt2i5rva"
      display_name:   "serv-image"
      images.#:       <computed>

  - oci_core_subnet.sub_app

  - oci_core_subnet.sub_app[1]

  - oci_core_subnet.sub_app[2]

  - oci_core_virtual_network.vcn1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions