terraform-providers / terraform-provider-opc

Terraform Oracle Public Cloud provider
https://www.terraform.io/docs/providers/opc/
Mozilla Public License 2.0
29 stars 25 forks source link

Problem with opc_compute_ip_address_association #151

Closed adrianotanaka closed 6 years ago

adrianotanaka commented 6 years ago

Hi for all,

I'm with a problem creating an ip reservation and assign this to an instance.

Terraform Version

Terraform v0.11.7

Affected Resource(s)

Please list the resources as a list, for example: opc_compute_ip_address_association

Terraform Configuration Files

##Source

resource "opc_compute_storage_volume" "boot-volume" {
  size = "20"
  name = "boot-${var.nome_maquina}-${var.cliente}"
  bootable = true
  image_list = "/oracle/public/OL_7.2_UEKR4_x86_64"
  image_list_entry = 1
}

resource "opc_compute_ip_address_reservation" "reserva_ip" {
  name            = "IPPUB-${var.nome_maquina}-${var.cliente}"
  ip_address_pool = "public-ippool"
}

resource "opc_compute_ip_address_association" "default" {
  name                   = "IPAddressAssociation1"
  ip_address_reservation = "${opc_compute_ip_address_reservation.reserva_ip.name}"
  vnic                   = "eth1"

}

resource "opc_compute_instance" "vm" {
  name       = "${var.nome_maquina}-${var.cliente}"
  hostname   = "${var.nome_maquina}"
  label      = "${var.nome_maquina}${var.cliente}"
  shape      = "oc3"

 #Discos
 storage {
    index = 1
    volume = "${opc_compute_storage_volume.boot-volume.name}"
  }
  boot_order = [ 1 ]

  #Rede
  #networking_info {
   # index = 1
    #ip_network = "APP"
    #is_default_gateway = "TRUE"
    #vnic_sets = ["VNICSET_SSH"]
    #vnic= "eth1"
    #shared_network = "FALSE"
    #nat = ["IPPUB-${var.nome_maquina}-${var.cliente}"]

  #}

ssh_keys   = ["${opc_compute_ssh_key.chave.name}"]
}

Debug Output

https://gist.github.com/adrianotanaka/141282605c6b6992f39748e8f30b5864

Expected Behavior

Create an IP Reservation on IP Network, Assign created IP reservation with Instance.

Actual Behavior

Steps to Reproduce

  1. terraform apply with provided .tf file
scross01 commented 6 years ago

You are combining two methods of assigning the IP reservation, you don't need to use the opc_compute_ip_address_association resource if you are assigning the opc_compute_ip_address_reservation to the interface directly in the networking_info config.

The difference is: when assigning the ip reservation in the nat attribute of the networking_info the Public IP is associated to the instance automatically on instance creation. If the nat config is ommited, the opc_compute_ip_address_association resource can be used to associate the public IP after the instance has been created.

A couple of other recommendations:

resource "opc_compute_instance" "vm" {
  name       = "${var.nome_maquina}-${var.cliente}"
  hostname   = "${var.nome_maquina}"
  label      = "${var.nome_maquina}${var.cliente}"
  shape      = "oc3"

  storage {
    index = 1
    volume = "${opc_compute_storage_volume.boot-volume.name}"
  }
  boot_order = [ 1 ]

  networking_info {
    index = 1
    ip_network = "APP"
    is_default_gateway = true
    vnic_sets = ["VNICSET_SSH"]
    vnic= "${var.nome_maquina}-${var.cliente}_eth1"
    shared_network = false
    nat = ["opc_compute_ip_address_reservation.reserva_ip.name"]
  }
  ssh_keys   = ["${opc_compute_ssh_key.chave.name}"]
}

Take a look at the example Compute Instance with Public IP Address Reservation on an IP Network Interface for a full example of using IP Networks IP Address Reservations.

adrianotanaka commented 6 years ago

Thanks Stephen, with your help I finished the environment.

This is the final version of .tf file:

##Source

resource "opc_compute_storage_volume" "boot-volume" {
  size = "20"
  name = "boot-${var.nome_maquina}-${var.cliente}"
  bootable = true
  image_list = "/oracle/public/OL_7.2_UEKR4_x86_64"
  image_list_entry = 1
}

resource "opc_compute_ip_address_reservation" "reserva_ip" {
  name            = "IPPUB-${var.nome_maquina}-${var.cliente}"
  ip_address_pool = "public-ippool"
}

resource "opc_compute_instance" "vm" {
  name       = "${var.nome_maquina}-${var.cliente}"
  hostname   = "${var.nome_maquina}"
  label      = "${var.nome_maquina}${var.cliente}"
  shape      = "oc3"

 #Discos
 storage {
    index = 1
    volume = "${opc_compute_storage_volume.boot-volume.name}"
  }
  boot_order = [ 1 ]

  #Rede
  networking_info {
   index = 1
    ip_network = "APP"
    is_default_gateway = "TRUE"
    vnic_sets = ["VNICSET_SSH"]
    vnic= "${var.nome_maquina}-${var.cliente}_eth1"
    shared_network = "FALSE"
    nat = ["${opc_compute_ip_address_reservation.reserva_ip.name}"]

  }

ssh_keys   = ["${opc_compute_ssh_key.chave.name}"]
}

output "public_ip_address" {
  value = "${opc_compute_ip_address_reservation.reserva_ip.ip_address}"
}