How to associate floating ip address to a instance in openstack using terraform

0

i am using terraform to create couple of instances in openstack and i would like to automatically assign floatings ip address to them without any manual intervention.

my .tf file is as below:

resource "openstack_networking_floatingip_v2" "floating-ip" {
 count  = 4
 pool = "floating-ip-pool" 
}

resource "openstack_compute_floatingip_associate_v2" "fip-associate" {
floating_ip = openstack_networking_floatingip_v2.floating-ip.address[count.0]
instance_id = openstack_compute_instance_v2.terraform-vm.id[count.0]
}`

i am getting an error "Error: Missing resource instance key

on image-provisioning.tf line 33, in resource “openstack_compute_floatingip_associate_v2” “fip-associate”: 33: instance_id = openstack_compute_instance_v2.terraform-vm.id[count.0]"

my terraform version is : Terraform v0.12.24 + provider.openstack 1.26.0