retrieving fixed ip from port attached to instance on openstack

585 views
Skip to first unread message

vincent.g...@gmail.com

unread,
Jun 13, 2017, 3:22:30 AM6/13/17
to Terraform
Hello guys,
I am trying to create instances by attaching network ports because I have to allow specific IPs on the openstack network but I can't figure out how to get the fixed IP from instances to fill an inventory file for ansible,the list is still empty even if the VM is well configured when I connect on it and run an IP ADDR command.
Here is the code. Do you have any workaround ? 

resource "openstack_networking_port_v2" "node_port" {
region = "${var.region}"
count = "${var.node_count}"
name = "${var.cluster_name}-node-port-${count.index+1}"
network_id = "${openstack_networking_network_v2.node_network.id}"
admin_state_up = "true"
security_group_ids = ["${openstack_networking_secgroup_v2.node_secgroup.id}" ]
fixed_ip {
subnet_id = "${openstack_networking_subnet_v2.node_subnet.id}"
}
allowed_address_pairs {
ip_address = "10.233.0.0/18"
}
allowed_address_pairs {
ip_address = "10.233.64.0/18"
}

resource "openstack_compute_instance_v2" "node" {
count = "${var.node_count}"
name = "${var.cluster_name}-node-${count.index+1}"
region = "${var.region}"
flavor_name = "${var.node_flavor_name}"
image_id= "${data.openstack_images_image_v2.node_image.id}"
key_pair = "${openstack_compute_keypair_v2.keypair.name}"
//security_groups = [ "${openstack_networking_secgroup_v2.node_secgroup.id}" ]
floating_ip = "${element(openstack_networking_floatingip_v2.node_floatip.*.address,count.index+1)}"
network = {
//uuid = "${openstack_networking_network_v2.node_network.id}"
port = "${element(openstack_networking_port_v2.node_port.*.id, count.index)}"
}
}

output "node_private_address" {
value = ["${openstack_networking_port_v2.node_port.*.fixed_ip.0.ip_address}"]
}





>terraform output

node_private_address = [
    ,
    ,
    
]


Reply all
Reply to author
Forward
0 new messages