<commit_before>variable datacenter { default = "openstack" }
variable floating_ips { default = "" }
variable blockstorage_metadata_attached_mode { default = "rw" }
variable blockstorage_metadata_readonly { default = "False" }
variable count  {}
variable count_offset { default = 0 } #start numbering from X
variable count_format { default = "%02d" } #server number format (-01, -02, etc.)
variable flavor_name {}
variable image_name {}
variable keypair_name {}
variable name { default = "mantl" }
variable network_uuid {}
variable role { default = "instance" }
variable security_groups { default = "default" }
variable ssh_user { default = "cloud-user" }
variable volume_size { default = 20 }
variable volume_device { default = "/dev/vdb" }

resource "openstack_blockstorage_volume_v1" "blockstorage" {
  name = "${var.name}-${format(var.count_format, var.count_offset+count.index+1) }"
  description = "${var.name}-${format(var.count_format, var.count_offset+count.index+1) }"
  size = "${var.volume_size}"
  metadata = {
    attached_mode = "${var.blockstorage_metadata_attached_mode}"
    readonly = "${var.blockstorage_metadata_readonly}"
    usage = "${var.name}-${var.role}-blockstorage"
  }
  count = "${var.count}"
}

resource "openstack_compute_instance_v2" "instance" {
  floating_ip = "${ element(split(",", var.floating_ips), count.index) }"
  name = "${var.name}-${var.role}-${format(var.count_format, var.count_offset+count.index+1)}"
  key_pair = "${var.keypair_name}"
  image_name = "${var.image_name}"
  flavor_name = "${var.flavor_name}"
  security_groups  = [ "${ var.security_groups }" ]

  network  = { 
    uuid = "${var.network_uuid}" 
  }

  volume = {
    volume_id = "${element(openstack_blockstorage_volume_v1.blockstorage.*.id, count.index)}"
    device = "${var.volume_device}"
  }

  metadata = {
    dc = "${var.datacenter}"
    role = "${var.role}"
    ssh_user = "${var.ssh_user}"
  }

  count = "${var.count}"
}

output hostname_list {
  value = "${join(",", openstack_compute_instance_v2.instance.*.name)}"
}

output ip_v4_list {
  value = "${join(",", openstack_compute_instance_v2.instance.*.access_ip_v4)}"
}<commit_msg>Add support for instance user_data<commit_after>variable datacenter { default = "openstack" }
variable floating_ips { default = "" }
variable blockstorage_metadata_attached_mode { default = "rw" }
variable blockstorage_metadata_readonly { default = "False" }
variable count  {}
variable count_offset { default = 0 } #start numbering from X
variable count_format { default = "%02d" } #server number format (-01, -02, etc.)
variable flavor_name {}
variable image_name {}
variable keypair_name {}
variable name { default = "mantl" }
variable network_uuid {}
variable role { default = "instance" }
variable security_groups { default = "default" }
variable ssh_user { default = "cloud-user" }
variable volume_size { default = 20 }
variable volume_device { default = "/dev/vdb" }
variable user_data { default = "" }

resource "openstack_blockstorage_volume_v1" "blockstorage" {
  name = "${var.name}-${format(var.count_format, var.count_offset+count.index+1) }"
  description = "${var.name}-${format(var.count_format, var.count_offset+count.index+1) }"
  size = "${var.volume_size}"
  metadata = {
    attached_mode = "${var.blockstorage_metadata_attached_mode}"
    readonly = "${var.blockstorage_metadata_readonly}"
    usage = "${var.name}-${var.role}-blockstorage"
  }
  count = "${var.count}"
}

resource "openstack_compute_instance_v2" "instance" {
  floating_ip = "${ element(split(",", var.floating_ips), count.index) }"
  name = "${var.name}-${var.role}-${format(var.count_format, var.count_offset+count.index+1)}"
  key_pair = "${var.keypair_name}"
  image_name = "${var.image_name}"
  flavor_name = "${var.flavor_name}"
  security_groups  = [ "${ var.security_groups }" ]

  network  = { 
    uuid = "${var.network_uuid}" 
  }

  volume = {
    volume_id = "${element(openstack_blockstorage_volume_v1.blockstorage.*.id, count.index)}"
    device = "${var.volume_device}"
  }

  metadata = {
    dc = "${var.datacenter}"
    role = "${var.role}"
    ssh_user = "${var.ssh_user}"
  }

  count = "${var.count}"

  user_data = "${var.user_data}"
}

output hostname_list {
  value = "${join(",", openstack_compute_instance_v2.instance.*.name)}"
}

output ip_v4_list {
  value = "${join(",", openstack_compute_instance_v2.instance.*.access_ip_v4)}"
}
{'fraction_non_alphanumeric': 0.16065350578624915, 'fraction_numerical': 0.008622645790787383, 'mean_word_length': 4.83841059602649, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5509158', 'n_tokens_mistral': 1481, 'n_tokens_neox': 1448, 'n_words': 275}