Oracle Reserved IP assignment

Hi there,

I’ve been working with Terraform for a while trying to set up most of the infrastructure automatically, however there’s one issue/problem that I can’t specify a reserved IP to a newly created instance.

I have the following instance:

resource "oci_core_instance" "gitlab_instance" {

  availability_domain = data.oci_identity_availability_domains.ads.availability_domains[0].name
  compartment_id      = oci_identity_compartment.tf-compartment.id
  shape               = "VM.Standard.A1.Flex"

  source_details {
    source_id               = var.ubuntu_image_source_id
    source_type             = "image"
    boot_volume_size_in_gbs = var.gitlab_instance_source_details_boot_volume_size_in_gbs
  }

  display_name = "gitlab-server"

  create_vnic_details {
    assign_public_ip = false
    subnet_id        = oci_core_subnet.vcn-public-subnet.id
    nsg_ids          = [oci_core_network_security_group.gitlab_network_security_group.id]
    hostname_label   = "gitlab-server"
  }

  is_pv_encryption_in_transit_enabled = true

  metadata = {
    ssh_authorized_keys = file(var.ssh_authorized_keys_path)
  }


  shape_config {
    memory_in_gbs = var.gitlab_memory
    ocpus         = var.gitlab_ocpus
  }

  preserve_boot_volume = true

  depends_on = [oci_core_network_security_group.gitlab_network_security_group]
}

And the reserved IP:

resource "oci_core_public_ip" "gitlab_public_ip" {
  #Required
  compartment_id = oci_identity_compartment.tf-compartment.id
  lifetime       = "RESERVED"

  #Optional
  display_name  = "gitlab-reserved-public-ip"
}

However, I am unable to assign the reserved IP address to the newly (or updatedly; either way…) created instance. The docs, at least to my understanding, don’t provide a way to do that. But this seems like such a trivial task that I’m almost certain that I’m missing something here.

Relevant links:
oci_core_instance
oci_core_public_ip

1 Like

You can set private_ip_id in oci_core_public_ip.

resource "oci_core_public_ip" "gitlab_public_ip" {
  #Required
  compartment_id = oci_identity_compartment.tf-compartment.id
  lifetime       = "RESERVED"

  #Optional
  display_name  = "gitlab-reserved-public-ip"
  private_ip_id = "(Private IP's OCID)"
}