oracle / terraform-provider-oci

Terraform Oracle Cloud Infrastructure provider
https://www.terraform.io/docs/providers/oci/
Mozilla Public License 2.0
759 stars 675 forks source link

oci_core_public_ip: terraform wants to remove private_ip_id if it is assigned via another resource #1479

Open EugZol opened 2 years ago

EugZol commented 2 years ago

Community Note

Terraform Version and Provider Version

Terraform v1.0.10
on linux_amd64
+ provider registry.terraform.io/hashicorp/oci v4.51.0

Affected Resource(s)

oci_core_public_ip

Terraform Configuration Files

variable "tenancy_ocid" {}
variable "user_ocid" {}
variable "fingerprint" {}
variable "region" {}
variable "compartment_ocid" {}

provider "oci" {
  tenancy_ocid = "${var.tenancy_ocid}"
  user_ocid = "${var.user_ocid}"
  fingerprint = "${var.fingerprint}"
  private_key_path = "secrets/private_api_key.pem"
  region = "${var.region}"
}

resource "oci_core_vcn" "lb_vcn" {
  compartment_id = var.compartment_ocid
  cidr_blocks = ["10.0.0.0/16"]
}

resource "oci_core_subnet" "lb_subnet" {
  compartment_id = var.compartment_ocid
  cidr_block = "10.0.0.0/16"
  vcn_id = oci_core_vcn.lb_vcn.id
}

resource "oci_load_balancer_load_balancer" "lb" {
  compartment_id = var.compartment_ocid
  subnet_ids = [oci_core_subnet.lb_subnet.id]
  is_private = false
  display_name = "Test LB"
  shape = "flexible"
  reserved_ips {
    id = oci_core_public_ip.lb_public_ip.id
  }
  shape_details {
    minimum_bandwidth_in_mbps = 10
    maximum_bandwidth_in_mbps = 200
  }
}

resource "oci_core_public_ip" "lb_public_ip" {
  compartment_id = var.compartment_ocid
  lifetime = "RESERVED"
}

Debug Output

First terraform apply: https://gist.github.com/EugZol/cf694a8ae3987ebf79017cdb535db851 Second terraform apply: https://gist.github.com/EugZol/6c861244f1c9dffb3633dbe8dcc11256

Expected Behavior

Terraform doesn't try to unassign private IP from public IP resource.

Actual Behavior

Terraform does try to unassign private IP from public IP resource, when the same configuration is applied second (and subsequent) time.

Steps to Reproduce

  1. terraform apply
  2. terraform apply
johnlane commented 1 year ago

I had to work around this by adding the association back into the config after the first run. This is far from ideal however

resource "oci_core_public_ip" "ip" {
  compartment_id = local.compartment_ocid
  display_name   = "${var.name}-public-ip"
  lifetime       = "RESERVED"
  private_ip_id  = "ocid1.privateip.oc1.uk-london-1.abw...kya" # manually inserted after creation to stop tf trying to delete it. https://github.com/oracle/terraform-provider-oci/issues/1708
  lifecycle {
    prevent_destroy = true
  }
}
tf-oci-pub commented 1 year ago

Thank you for reporting the issue. We have raised an internal ticket to track this. Our service engineers will get back to you.