Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- my base.tf
- # this will build a vm
- provider "vsphere" {
- user = "REDACTED"
- password = "REDACTED"
- vsphere_server = "REDACTED"
- # allow self sign cert
- allow_unverified_ssl = true
- }
- data "vsphere_datacenter" "dc" {
- name = "Datacenter"
- }
- data "vsphere_host" "host" {
- name = "46.4.38.138"
- datacenter_id = "${data.vsphere_datacenter.dc.id}"
- }
- data "vsphere_datastore" "datastore" {
- name = "SLOWMO"
- datacenter_id = "${data.vsphere_datacenter.dc.id}"
- }
- resource "vsphere_folder" "Terraformtesting" {
- datacenter_id = "${data.vsphere_datacenter.dc.id}"
- path = "Terraform Testing"
- type = "vm"
- }
- data "vsphere_virtual_machine" "template" {
- name = "Ubuntu 1804 server"
- datacenter_id = "${data.vsphere_datacenter.dc.id}"
- }
- data "vsphere_compute_cluster" "cluster" {
- name = "Cluster1"
- datacenter_id = "${data.vsphere_datacenter.dc.id}"
- }
- data "vsphere_network" "net" {
- name = "internalnet"
- datacenter_id = "${data.vsphere_datacenter.dc.id}"
- }
- resource "vsphere_virtual_machine" "vm" {
- name = "terraform-test"
- resource_pool_id = "${data.vsphere_compute_cluster.cluster.resource_pool_id}"
- datastore_id = "${data.vsphere_datastore.datastore.id}"
- num_cpus = 2
- memory = 4096
- guest_id = "${data.vsphere_virtual_machine.template.guest_id}"
- scsi_type = "${data.vsphere_virtual_machine.template.scsi_type}"
- network_interface {
- network_id = "${data.vsphere_network.net.id}"
- adapter_type = "${data.vsphere_virtual_machine.template.network_interface_types[0]}"
- }
- disk {
- label = "disk0"
- size = "${data.vsphere_virtual_machine.template.disks.0.size}"
- eagerly_scrub = "${data.vsphere_virtual_machine.template.disks.0.eagerly_scrub}"
- thin_provisioned = "${data.vsphere_virtual_machine.template.disks.0.thin_provisioned}"
- }
- clone {
- template_uuid = "${data.vsphere_virtual_machine.template.id}"
- customize {
- linux_options {
- host_name = "terraform-test"
- domain = "blacklab.corp"
- }
- network_interface {
- ipv4_address = "192.168.2.33"
- ipv4_netmask = 24
- }
- ipv4_gateway = "192.168.2.1"
- dns_server_list = ["192.168.2.2"]
- dns_suffix_list = ["blacklab.corp"]
- }
- }
- #resource "null_resource" "vm_post_deploy" {
- # connection {
- # host = "${vsphere_virtual_machine.rtr.default_ip_address}"
- #}
- #}
- provisioner "local-exec" {
- command = "echo ${self.private_ip} > file.txt"
- command = "dpkg-reconfigure openssh-server"
- }
- }
- Terraform apply output :
- data.vsphere_datacenter.dc: Refreshing state...
- data.vsphere_network.net: Refreshing state...
- data.vsphere_virtual_machine.template: Refreshing state...
- data.vsphere_datastore.datastore: Refreshing state...
- data.vsphere_host.host: Refreshing state...
- data.vsphere_compute_cluster.cluster: Refreshing state...
- 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:
- + vsphere_folder.Terraformtesting
- id: <computed>
- datacenter_id: "datacenter-2"
- path: "Terraform Testing"
- type: "vm"
- + vsphere_virtual_machine.vm
- id: <computed>
- boot_retry_delay: "10000"
- change_version: <computed>
- clone.#: "1"
- clone.0.customize.#: "1"
- clone.0.customize.0.dns_server_list.#: "1"
- clone.0.customize.0.dns_server_list.0: "192.168.2.2"
- clone.0.customize.0.dns_suffix_list.#: "1"
- clone.0.customize.0.dns_suffix_list.0: "blacklab.corp"
- clone.0.customize.0.ipv4_gateway: "192.168.2.1"
- clone.0.customize.0.linux_options.#: "1"
- clone.0.customize.0.linux_options.0.domain: "blacklab.corp"
- clone.0.customize.0.linux_options.0.host_name: "terraform-test"
- clone.0.customize.0.linux_options.0.hw_clock_utc: "true"
- clone.0.customize.0.network_interface.#: "1"
- clone.0.customize.0.network_interface.0.ipv4_address: "192.168.2.33"
- clone.0.customize.0.network_interface.0.ipv4_netmask: "24"
- clone.0.customize.0.timeout: "10"
- clone.0.template_uuid: "4212376d-d47c-9179-4d97-3f769a9e24ce"
- clone.0.timeout: "30"
- cpu_limit: "-1"
- cpu_share_count: <computed>
- cpu_share_level: "normal"
- datastore_id: "datastore-81"
- 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: "25"
- disk.0.thin_provisioned: "false"
- 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: "ubuntu64Guest"
- guest_ip_addresses.#: <computed>
- host_system_id: <computed>
- hv_mode: "hvAuto"
- imported: <computed>
- latency_sensitivity: "normal"
- memory: "4096"
- memory_limit: "-1"
- memory_share_count: <computed>
- memory_share_level: "normal"
- migrate_wait_timeout: "30"
- moid: <computed>
- name: "terraform-test"
- 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: "network-12"
- num_cores_per_socket: "1"
- num_cpus: "2"
- reboot_required: <computed>
- resource_pool_id: "resgroup-184"
- 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: "lsilogic"
- 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: "5"
- Plan: 2 to add, 0 to change, 0 to destroy.
- Do you want to perform these actions?
- Terraform will perform the actions described above.
- Only 'yes' will be accepted to approve.
- Enter a value: yes
- vsphere_folder.Terraformtesting: Creating...
- datacenter_id: "" => "datacenter-2"
- path: "" => "Terraform Testing"
- type: "" => "vm"
- vsphere_folder.Terraformtesting: Creation complete after 0s (ID: group-v207)
- vsphere_virtual_machine.vm: Creating...
- boot_retry_delay: "" => "10000"
- change_version: "" => "<computed>"
- clone.#: "" => "1"
- clone.0.customize.#: "" => "1"
- clone.0.customize.0.dns_server_list.#: "" => "1"
- clone.0.customize.0.dns_server_list.0: "" => "192.168.2.2"
- clone.0.customize.0.dns_suffix_list.#: "" => "1"
- clone.0.customize.0.dns_suffix_list.0: "" => "blacklab.corp"
- clone.0.customize.0.ipv4_gateway: "" => "192.168.2.1"
- clone.0.customize.0.linux_options.#: "" => "1"
- clone.0.customize.0.linux_options.0.domain: "" => "blacklab.corp"
- clone.0.customize.0.linux_options.0.host_name: "" => "terraform-test"
- clone.0.customize.0.linux_options.0.hw_clock_utc: "" => "true"
- clone.0.customize.0.network_interface.#: "" => "1"
- clone.0.customize.0.network_interface.0.ipv4_address: "" => "192.168.2.33"
- clone.0.customize.0.network_interface.0.ipv4_netmask: "" => "24"
- clone.0.customize.0.timeout: "" => "10"
- clone.0.template_uuid: "" => "4212376d-d47c-9179-4d97-3f769a9e24ce"
- clone.0.timeout: "" => "30"
- cpu_limit: "" => "-1"
- cpu_share_count: "" => "<computed>"
- cpu_share_level: "" => "normal"
- datastore_id: "" => "datastore-81"
- 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: "" => "25"
- disk.0.thin_provisioned: "" => "false"
- 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: "" => "ubuntu64Guest"
- guest_ip_addresses.#: "" => "<computed>"
- host_system_id: "" => "<computed>"
- hv_mode: "" => "hvAuto"
- imported: "" => "<computed>"
- latency_sensitivity: "" => "normal"
- memory: "" => "4096"
- memory_limit: "" => "-1"
- memory_share_count: "" => "<computed>"
- memory_share_level: "" => "normal"
- migrate_wait_timeout: "" => "30"
- moid: "" => "<computed>"
- name: "" => "terraform-test"
- 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: "" => "network-12"
- num_cores_per_socket: "" => "1"
- num_cpus: "" => "2"
- reboot_required: "" => "<computed>"
- resource_pool_id: "" => "resgroup-184"
- 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: "" => "lsilogic"
- 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: "" => "5"
- vsphere_virtual_machine.vm: Still creating... (10s elapsed)
- vsphere_virtual_machine.vm: Still creating... (20s elapsed)
- vsphere_virtual_machine.vm: Still creating... (30s elapsed)
- vsphere_virtual_machine.vm: Still creating... (40s elapsed)
- vsphere_virtual_machine.vm: Still creating... (50s elapsed)
- vsphere_virtual_machine.vm: Still creating... (1m0s elapsed)
- vsphere_virtual_machine.vm: Still creating... (1m10s elapsed)
- vsphere_virtual_machine.vm: Still creating... (1m20s elapsed)
- vsphere_virtual_machine.vm: Still creating... (1m30s elapsed)
- vsphere_virtual_machine.vm: Still creating... (1m40s elapsed)
- vsphere_virtual_machine.vm: Still creating... (1m50s elapsed)
- vsphere_virtual_machine.vm: Still creating... (2m0s elapsed)
- vsphere_virtual_machine.vm: Still creating... (2m10s elapsed)
- vsphere_virtual_machine.vm: Still creating... (2m20s elapsed)
- vsphere_virtual_machine.vm: Still creating... (2m30s elapsed)
- vsphere_virtual_machine.vm: Still creating... (2m40s elapsed)
- vsphere_virtual_machine.vm: Still creating... (2m50s elapsed)
- vsphere_virtual_machine.vm: Still creating... (3m0s elapsed)
- vsphere_virtual_machine.vm: Still creating... (3m10s elapsed)
- vsphere_virtual_machine.vm: Still creating... (3m20s elapsed)
- vsphere_virtual_machine.vm: Still creating... (3m30s elapsed)
- vsphere_virtual_machine.vm: Still creating... (3m40s elapsed)
- vsphere_virtual_machine.vm: Still creating... (3m50s elapsed)
- vsphere_virtual_machine.vm: Still creating... (4m0s elapsed)
- vsphere_virtual_machine.vm: Still creating... (4m10s elapsed)
- vsphere_virtual_machine.vm: Still creating... (4m20s elapsed)
- vsphere_virtual_machine.vm: Still creating... (4m30s elapsed)
- vsphere_virtual_machine.vm: Still creating... (4m40s elapsed)
- vsphere_virtual_machine.vm: Still creating... (4m50s elapsed)
- vsphere_virtual_machine.vm: Still creating... (5m0s elapsed)
- vsphere_virtual_machine.vm: Still creating... (5m10s elapsed)
- vsphere_virtual_machine.vm: Still creating... (5m20s elapsed)
- vsphere_virtual_machine.vm: Still creating... (5m30s elapsed)
- vsphere_virtual_machine.vm: Still creating... (5m40s elapsed)
- vsphere_virtual_machine.vm: Still creating... (5m50s elapsed)
- vsphere_virtual_machine.vm: Still creating... (6m0s elapsed)
- vsphere_virtual_machine.vm: Still creating... (6m10s elapsed)
- vsphere_virtual_machine.vm: Still creating... (6m20s elapsed)
- vsphere_virtual_machine.vm: Still creating... (6m30s elapsed)
- Error: Error applying plan:
- 1 error(s) occurred:
- * vsphere_virtual_machine.vm: 1 error(s) occurred:
- * vsphere_virtual_machine.vm: timeout waiting for an available IP address
- Terraform does not automatically rollback in the face of errors.
- Instead, your Terraform state file has been partially updated with
- any resources that successfully completed. Please address the error
- above and apply again to incrementally change your infrastructure.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement