Terraform openstack instance doesn't return floating ip

932 views Asked by At

Im setting up and openstack instance using terraform. Im writing to a file the ip returned but for some reason its alwayse empty (i have looked at the instance in openstack consol and everythign is correct with ip, securitygroups etc etc)

resource "openstack_compute_instance_v2" "my-deployment-web" {
  count = "1"
  name = "my-name-WEB"
  flavor_name = "m1.medium"
  image_name = "RHEL7Secretname"
  security_groups = [
    "our_security_group"]
  key_pair = "our-keypair"   


  network {
    name = "public"
  }

  metadata {
    expire = "2",
    owner = ""
  }

  connection {
    type = "ssh"
    user = "vagrant"
    private_key = "config/vagrant_private.key"
    agent = "false"
    timeout = "15m"
  }

  ##Create Ansible host in staging inventory
  provisioner "local-exec" {
    command =  "echo -e '\n[web]\n${openstack_compute_instance_v2.my-deployment-web.network.0.floating_ip}' > ../ansible/inventories/staging/hosts"
    interpreter = ["sh", "-c"]
  }    
}

The host file generated only gets [web] but no ip. Anyone know why?

[web]
1

There are 1 answers

0
Marthin On BEST ANSWER

Modifying the variable from

${openstack_compute_instance_v2.my-deployment-web.network.0.floating_ip}

to

${openstack_compute_instance_v2.my-deployment-web.network.0.access_ip_v4}

solved the problem. Thank you @Matt Schuchard