Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

If statement in name parameter #685

Closed
ghost opened this issue Jan 9, 2019 · 2 comments
Closed

If statement in name parameter #685

ghost opened this issue Jan 9, 2019 · 2 comments

Comments

@ghost
Copy link

ghost commented Jan 9, 2019

This issue was originally opened by @Koleon as hashicorp/terraform#19948. It was migrated here as a result of the provider split. The original body of the issue is below.


Hello guys,
I'm trying to tweak this module as follows. When deploy only 1 VM do not add count index number to var.vm_name_prefix. Deploying 2 or more VMs add count index number to var.vm_name_prefix. The only modifications are name and hostname lines. Please see Modified vsphere_virutal_machine_linux.tf from module section below.
After that I run terraform plan the output looks good, see below. Unfortunately when I run terraform apply I got into crash. All 3 modification of name and hostname give me same plan output until I run the terraform apply.

Terraform Version

$ terraform -v
Terraform v0.11.11
+ provider.vsphere v1.9.0

Terraform Configuration Files

module "virtual_machines" {
  template_name        = "T_centos-7.5"
  source               = "./modules/terraform-vsphere-virtual-machine"
  datacenter           = "BM-LAB"
  datastore            = "lun_b_vmware"
  resource_pool        = "LAB/Resources"
  template_os_family   = "linux"
  vm_count             = "2"
  vm_name_prefix       = "testing-module-vm"
  ipv4_network_address = "10.8.21.0/24"
  ipv4_address_start   = "10"
  ipv4_gateway         = "10.8.21.1"
  network              = "LAB"
  wait_for_guest_net_timeout = "-1"
}

Modified vsphere_virutal_machine_linux.tf from module

resource "vsphere_virtual_machine" "virtual_machine_linux" {
  count            = "${var.template_os_family == "linux" ? var.vm_count : 0}"
  name             = "${var.vm_name_prefix}-${var.vm_count == 1 ? "" : "${count.index}"}"
  #name             = "${var.vm_name_prefix}-${format("%s", var.vm_count == 1 ? "" : "${count.index}")}"
  #name             = "${var.vm_count > 1 ? format("%s-%d", var.vm_name_prefix, var.vm_count) : var.vm_name_prefix}"
  resource_pool_id = "${data.vsphere_resource_pool.pool.id}"
  datastore_id     = "${data.vsphere_datastore.ds.id}"

  num_cpus = "${var.num_cpus}"
  memory   = "${var.memory}"
  guest_id = "${data.vsphere_virtual_machine.template.guest_id}"

  wait_for_guest_net_timeout = "${var.wait_for_guest_net_timeout}"

  network_interface {
    network_id = "${data.vsphere_network.network.id}"
  }

  disk {
    label            = "disk0"
    size             = "${var.disk_size != "" ? var.disk_size : data.vsphere_virtual_machine.template.disks.0.size}"
    thin_provisioned = "${var.linked_clone == "true" ? data.vsphere_virtual_machine.template.disks.0.thin_provisioned : true}"
    eagerly_scrub    = "${var.linked_clone == "true" ? data.vsphere_virtual_machine.template.disks.0.eagerly_scrub: false}"
  }

  clone {
    template_uuid = "${data.vsphere_virtual_machine.template.id}"
    linked_clone  = "${var.linked_clone}"

    customize {
      linux_options {
        host_name = "${var.vm_name_prefix}-${var.vm_count == 1 ? "" : "${count.index}"}"
        #host_name = "${var.vm_name_prefix}-${format("%s", var.vm_count == 1 ? "" : "${count.index}")}"
        #host_name = "${var.vm_count > 1 ? format("%s-%d", var.vm_name_prefix, var.vm_count) : var.vm_name_prefix}"
        domain    = "${var.domain_name}"
        time_zone = "${var.time_zone != "" ? var.time_zone : "UTC"}"
      }

      network_interface {
        ipv4_address = "${var.ipv4_network_address != "0.0.0.0/0" ? cidrhost(var.ipv4_network_address, var.ipv4_address_start + count.index) : ""}"
        ipv4_netmask = "${var.ipv4_network_address != "0.0.0.0/0" ? element(split("/", var.ipv4_network_address), 1) : 0}"
      }

      ipv4_gateway    = "${var.ipv4_gateway}"
      dns_server_list = ["${var.dns_servers}"]
      dns_suffix_list = ["${var.domain_name}"]
    }
  }
}

# vim: filetype=terraform

Terraform plan output:

------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  + module.virtual_machines.vsphere_virtual_machine.virtual_machine_linux[0]
      id:                                                   <computed>
      boot_retry_delay:                                     "10000"
      change_version:                                       <computed>
      clone.#:                                              "1"
      clone.0.customize.#:                                  "1"
      clone.0.customize.0.dns_suffix_list.#:                "1"
      clone.0.customize.0.ipv4_gateway:                     "10.8.21.1"
      clone.0.customize.0.linux_options.#:                  "1"
      clone.0.customize.0.linux_options.0.host_name:        "testing-module-vm-0"
      clone.0.customize.0.linux_options.0.hw_clock_utc:     "true"
      clone.0.customize.0.linux_options.0.time_zone:        "UTC"
      clone.0.customize.0.network_interface.#:              "1"
      clone.0.customize.0.network_interface.0.ipv4_address: "10.8.21.10"
      clone.0.customize.0.network_interface.0.ipv4_netmask: "24"
      clone.0.customize.0.timeout:                          "10"
      clone.0.linked_clone:                                 "false"
      clone.0.template_uuid:                                "42360369-20b3-d966-d88b-88f82d061801"
      clone.0.timeout:                                      "30"
      cpu_limit:                                            "-1"
      cpu_share_count:                                      <computed>
      cpu_share_level:                                      "normal"
      datastore_id:                                         "datastore-56"
      default_ip_address:                                   <computed>
      disk.#:                                               "1"
      disk.0.attach:                                        "false"
      disk.0.datastore_id:                                  "<computed>"
      disk.0.device_address:                                <computed>
      disk.0.disk_mode:                                     "persistent"
      disk.0.disk_sharing:                                  "sharingNone"
      disk.0.eagerly_scrub:                                 "false"
      disk.0.io_limit:                                      "-1"
      disk.0.io_reservation:                                "0"
      disk.0.io_share_count:                                "0"
      disk.0.io_share_level:                                "normal"
      disk.0.keep_on_remove:                                "false"
      disk.0.key:                                           "0"
      disk.0.label:                                         "disk0"
      disk.0.path:                                          <computed>
      disk.0.size:                                          "20"
      disk.0.thin_provisioned:                              "true"
      disk.0.unit_number:                                   "0"
      disk.0.uuid:                                          <computed>
      disk.0.write_through:                                 "false"
      ept_rvi_mode:                                         "automatic"
      firmware:                                             "bios"
      force_power_off:                                      "true"
      guest_id:                                             "centos64Guest"
      guest_ip_addresses.#:                                 <computed>
      host_system_id:                                       <computed>
      hv_mode:                                              "hvAuto"
      imported:                                             <computed>
      latency_sensitivity:                                  "normal"
      memory:                                               "1024"
      memory_limit:                                         "-1"
      memory_share_count:                                   <computed>
      memory_share_level:                                   "normal"
      migrate_wait_timeout:                                 "30"
      moid:                                                 <computed>
      name:                                                 "testing-module-vm-0"
      network_interface.#:                                  "1"
      network_interface.0.adapter_type:                     "vmxnet3"
      network_interface.0.bandwidth_limit:                  "-1"
      network_interface.0.bandwidth_reservation:            "0"
      network_interface.0.bandwidth_share_count:            <computed>
      network_interface.0.bandwidth_share_level:            "normal"
      network_interface.0.device_address:                   <computed>
      network_interface.0.key:                              <computed>
      network_interface.0.mac_address:                      <computed>
      network_interface.0.network_id:                       "dvportgroup-868"
      num_cores_per_socket:                                 "1"
      num_cpus:                                             "2"
      reboot_required:                                      <computed>
      resource_pool_id:                                     "resgroup-36"
      run_tools_scripts_after_power_on:                     "true"
      run_tools_scripts_after_resume:                       "true"
      run_tools_scripts_before_guest_shutdown:              "true"
      run_tools_scripts_before_guest_standby:               "true"
      scsi_bus_sharing:                                     "noSharing"
      scsi_controller_count:                                "1"
      scsi_type:                                            "pvscsi"
      shutdown_wait_timeout:                                "3"
      swap_placement_policy:                                "inherit"
      uuid:                                                 <computed>
      vapp_transport.#:                                     <computed>
      vmware_tools_status:                                  <computed>
      vmx_path:                                             <computed>
      wait_for_guest_net_routable:                          "true"
      wait_for_guest_net_timeout:                           "-1"

  + module.virtual_machines.vsphere_virtual_machine.virtual_machine_linux[1]
      id:                                                   <computed>
      boot_retry_delay:                                     "10000"
      change_version:                                       <computed>
      clone.#:                                              "1"
      clone.0.customize.#:                                  "1"
      clone.0.customize.0.dns_suffix_list.#:                "1"
      clone.0.customize.0.ipv4_gateway:                     "10.8.21.1"
      clone.0.customize.0.linux_options.#:                  "1"
      clone.0.customize.0.linux_options.0.host_name:        "testing-module-vm-1"
      clone.0.customize.0.linux_options.0.hw_clock_utc:     "true"
      clone.0.customize.0.linux_options.0.time_zone:        "UTC"
      clone.0.customize.0.network_interface.#:              "1"
      clone.0.customize.0.network_interface.0.ipv4_address: "10.8.21.11"
      clone.0.customize.0.network_interface.0.ipv4_netmask: "24"
      clone.0.customize.0.timeout:                          "10"
      clone.0.linked_clone:                                 "false"
      clone.0.template_uuid:                                "42360369-20b3-d966-d88b-88f82d061801"
      clone.0.timeout:                                      "30"
      cpu_limit:                                            "-1"
      cpu_share_count:                                      <computed>
      cpu_share_level:                                      "normal"
      datastore_id:                                         "datastore-56"
      default_ip_address:                                   <computed>
      disk.#:                                               "1"
      disk.0.attach:                                        "false"
      disk.0.datastore_id:                                  "<computed>"
      disk.0.device_address:                                <computed>
      disk.0.disk_mode:                                     "persistent"
      disk.0.disk_sharing:                                  "sharingNone"
      disk.0.eagerly_scrub:                                 "false"
      disk.0.io_limit:                                      "-1"
      disk.0.io_reservation:                                "0"
      disk.0.io_share_count:                                "0"
      disk.0.io_share_level:                                "normal"
      disk.0.keep_on_remove:                                "false"
      disk.0.key:                                           "0"
      disk.0.label:                                         "disk0"
      disk.0.path:                                          <computed>
      disk.0.size:                                          "20"
      disk.0.thin_provisioned:                              "true"
      disk.0.unit_number:                                   "0"
      disk.0.uuid:                                          <computed>
      disk.0.write_through:                                 "false"
      ept_rvi_mode:                                         "automatic"
      firmware:                                             "bios"
      force_power_off:                                      "true"
      guest_id:                                             "centos64Guest"
      guest_ip_addresses.#:                                 <computed>
      host_system_id:                                       <computed>
      hv_mode:                                              "hvAuto"
      imported:                                             <computed>
      latency_sensitivity:                                  "normal"
      memory:                                               "1024"
      memory_limit:                                         "-1"
      memory_share_count:                                   <computed>
      memory_share_level:                                   "normal"
      migrate_wait_timeout:                                 "30"
      moid:                                                 <computed>
      name:                                                 "testing-module-vm-1"
      network_interface.#:                                  "1"
      network_interface.0.adapter_type:                     "vmxnet3"
      network_interface.0.bandwidth_limit:                  "-1"
      network_interface.0.bandwidth_reservation:            "0"
      network_interface.0.bandwidth_share_count:            <computed>
      network_interface.0.bandwidth_share_level:            "normal"
      network_interface.0.device_address:                   <computed>
      network_interface.0.key:                              <computed>
      network_interface.0.mac_address:                      <computed>
      network_interface.0.network_id:                       "dvportgroup-868"
      num_cores_per_socket:                                 "1"
      num_cpus:                                             "2"
      reboot_required:                                      <computed>
      resource_pool_id:                                     "resgroup-36"
      run_tools_scripts_after_power_on:                     "true"
      run_tools_scripts_after_resume:                       "true"
      run_tools_scripts_before_guest_shutdown:              "true"
      run_tools_scripts_before_guest_standby:               "true"
      scsi_bus_sharing:                                     "noSharing"
      scsi_controller_count:                                "1"
      scsi_type:                                            "pvscsi"
      shutdown_wait_timeout:                                "3"
      swap_placement_policy:                                "inherit"
      uuid:                                                 <computed>
      vapp_transport.#:                                     <computed>
      vmware_tools_status:                                  <computed>
      vmx_path:                                             <computed>
      wait_for_guest_net_routable:                          "true"
      wait_for_guest_net_timeout:                           "-1"


Plan: 2 to add, 0 to change, 0 to destroy.

------------------------------------------------------------------------

Crash Output

crash.log

Expected Behavior

Deploy 2 VMs. With names testing-module-vm-0 and testing-module-vm-1.

Actual Behavior

Terraform crash.

Steps to Reproduce

  1. terraform init
  2. terraform plan
  3. terraform apply

Could you please help me out?

@Koleon
Copy link

Koleon commented Jan 10, 2019

This bug was fixed in today's release of terraform-provider-vsphere version 1.9.1. Please see pull request #666
Thank you

@bill-rich
Copy link
Contributor

@Koleon Great new! Glad the new release resolved your issue.

@ghost ghost locked and limited conversation to collaborators Apr 18, 2020
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants