[OpenStack provider] Creating volume and knowing its ID ???

384 views
Skip to first unread message

Adrián López

unread,
Jul 3, 2015, 9:25:07 AM7/3/15
to terrafo...@googlegroups.com
Hello,

I need to create an instance with a volume attached.

The problem is that Terraform doesn't export the volume ID when created to a var I can use (but I can see in debug mode that it receives the volume_ID when created).
Can anyone help please?


My .tf:

resource "openstack_networking_floatingip_v2" "floatip_3" {
  region = "${var.region}"
  pool = "${var.floating_ip_pool}"
}

resource "openstack_blockstorage_volume_v1" "volume_3" {
  region = "${var.region}"
  name = "tf-cassandra-vol-3"
  description = "Volume for Cassandra3"
  size = 40
}


resource "openstack_compute_instance_v2" "cassandra-terraform-3" {
  name = "cassandra-terraform-3"
  image_name = "Ubuntu 14.04"
  region = "${var.region}"
  flavor_name = "m1.small"
  floating_ip = "${openstack_networking_floatingip_v2.floatip_3.address}"
  network {
    uuid = "XXXXXXXXX"
  }
  volume {
    volume_id =  "${openstack_blockstorage_volume_v1.volume_3.volumeID}"          --->>>>  This is what I need to get, but it seems Terraform isn't exporting it, as you can see in the docs (https://terraform.io/docs/providers/openstack/r/blockstorage_volume_v1.html)
  }
  metadata {
    this = "that"
  }
  key_pair = "${var.openstack_key_pair}"
  security_groups = ["XX"]
}

Alex Dupuy

unread,
Jul 4, 2015, 2:46:52 AM7/4/15
to terrafo...@googlegroups.com
Adrián López wrote:
resource "openstack_compute_instance_v2" "cassandra-terraform-3" {
  name = "cassandra-terraform-3"
  image_name = "Ubuntu 14.04"
  region = "${var.region}"
  flavor_name = "m1.small"
  floating_ip = "${openstack_networking_floatingip_v2.floatip_3.address}"
  network {
    uuid = "XXXXXXXXX"
  }
  volume {
    volume_id =  "${openstack_blockstorage_volume_v1.volume_3.volumeID}"
  }
  metadata {
    this = "that"
  }
  key_pair = "${var.openstack_key_pair}"
  security_groups = ["XX"]
}

You're pretty close.

  volume {
    volume_id =  "${openstack_blockstorage_volume_v1.volume_3.id}"
  }

will work.  Every Terraform resource has an id attribute, so they aren't explicitly listed - the OpenStack provider, at least, uses the underlying UUID of objects as the Terraform id, so anywhere that you need an OpenStack UUID, you can just grab the id attribute of the corresponding resource - they are pretty much one to one.

Note that if you actually plan on using the metadata this="that" on the created Cassandra system (as opposed to in the terraform configuration or in an application that is using the OpenStack nova API) you will need to add

config_drive = true

to your resource. You can then mount the config drive and get the data from /mnt/openstack/2013-10-17/meta_data.json - I have a Python script that does the mounting and extraction automatically, if you're interested.

@alex

Adrián López

unread,
Jul 4, 2015, 8:15:07 PM7/4/15
to terrafo...@googlegroups.com
Thanks a lot for your help, Alex!

Yes please, I'd appreciate that python script to automate the mounting. How do you use it? with remote-exec?

Thank you again :)
Regards,
Adrián.
Reply all
Reply to author
Forward
0 new messages