Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2018
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.29 KB | None | 0 0
  1.  
  2. my base.tf
  3. # this will build a vm
  4.  
  5. provider "vsphere" {
  6. user = "REDACTED"
  7. password = "REDACTED"
  8. vsphere_server = "REDACTED"
  9. # allow self sign cert
  10. allow_unverified_ssl = true
  11.  
  12. }
  13.  
  14.  
  15. data "vsphere_datacenter" "dc" {
  16. name = "Datacenter"
  17. }
  18. data "vsphere_host" "host" {
  19. name = "46.4.38.138"
  20. datacenter_id = "${data.vsphere_datacenter.dc.id}"
  21. }
  22. data "vsphere_datastore" "datastore" {
  23. name = "SLOWMO"
  24. datacenter_id = "${data.vsphere_datacenter.dc.id}"
  25. }
  26. resource "vsphere_folder" "Terraformtesting" {
  27. datacenter_id = "${data.vsphere_datacenter.dc.id}"
  28. path = "Terraform Testing"
  29. type = "vm"
  30. }
  31. data "vsphere_virtual_machine" "template" {
  32. name = "Ubuntu 1804 server"
  33. datacenter_id = "${data.vsphere_datacenter.dc.id}"
  34. }
  35. data "vsphere_compute_cluster" "cluster" {
  36. name = "Cluster1"
  37. datacenter_id = "${data.vsphere_datacenter.dc.id}"
  38. }
  39.  
  40. data "vsphere_network" "net" {
  41. name = "internalnet"
  42. datacenter_id = "${data.vsphere_datacenter.dc.id}"
  43. }
  44. resource "vsphere_virtual_machine" "vm" {
  45. name = "terraform-test"
  46. resource_pool_id = "${data.vsphere_compute_cluster.cluster.resource_pool_id}"
  47. datastore_id = "${data.vsphere_datastore.datastore.id}"
  48.  
  49. num_cpus = 2
  50. memory = 4096
  51. guest_id = "${data.vsphere_virtual_machine.template.guest_id}"
  52.  
  53. scsi_type = "${data.vsphere_virtual_machine.template.scsi_type}"
  54.  
  55. network_interface {
  56. network_id = "${data.vsphere_network.net.id}"
  57. adapter_type = "${data.vsphere_virtual_machine.template.network_interface_types[0]}"
  58.  
  59. }
  60.  
  61. disk {
  62. label = "disk0"
  63. size = "${data.vsphere_virtual_machine.template.disks.0.size}"
  64. eagerly_scrub = "${data.vsphere_virtual_machine.template.disks.0.eagerly_scrub}"
  65. thin_provisioned = "${data.vsphere_virtual_machine.template.disks.0.thin_provisioned}"
  66. }
  67.  
  68. clone {
  69. template_uuid = "${data.vsphere_virtual_machine.template.id}"
  70.  
  71. customize {
  72. linux_options {
  73. host_name = "terraform-test"
  74. domain = "blacklab.corp"
  75. }
  76.  
  77. network_interface {
  78. ipv4_address = "192.168.2.33"
  79. ipv4_netmask = 24
  80. }
  81.  
  82. ipv4_gateway = "192.168.2.1"
  83. dns_server_list = ["192.168.2.2"]
  84. dns_suffix_list = ["blacklab.corp"]
  85.  
  86. }
  87. }
  88.  
  89.  
  90. #resource "null_resource" "vm_post_deploy" {
  91. # connection {
  92. # host = "${vsphere_virtual_machine.rtr.default_ip_address}"
  93. #}
  94. #}
  95.  
  96. provisioner "local-exec" {
  97. command = "echo ${self.private_ip} > file.txt"
  98. command = "dpkg-reconfigure openssh-server"
  99. }
  100. }
  101.  
  102.  
  103.  
  104. Terraform apply output :
  105.  
  106.  
  107. data.vsphere_datacenter.dc: Refreshing state...
  108. data.vsphere_network.net: Refreshing state...
  109. data.vsphere_virtual_machine.template: Refreshing state...
  110. data.vsphere_datastore.datastore: Refreshing state...
  111. data.vsphere_host.host: Refreshing state...
  112. data.vsphere_compute_cluster.cluster: Refreshing state...
  113.  
  114. An execution plan has been generated and is shown below.
  115. Resource actions are indicated with the following symbols:
  116. + create
  117.  
  118. Terraform will perform the following actions:
  119.  
  120. + vsphere_folder.Terraformtesting
  121. id: <computed>
  122. datacenter_id: "datacenter-2"
  123. path: "Terraform Testing"
  124. type: "vm"
  125.  
  126. + vsphere_virtual_machine.vm
  127. id: <computed>
  128. boot_retry_delay: "10000"
  129. change_version: <computed>
  130. clone.#: "1"
  131. clone.0.customize.#: "1"
  132. clone.0.customize.0.dns_server_list.#: "1"
  133. clone.0.customize.0.dns_server_list.0: "192.168.2.2"
  134. clone.0.customize.0.dns_suffix_list.#: "1"
  135. clone.0.customize.0.dns_suffix_list.0: "blacklab.corp"
  136. clone.0.customize.0.ipv4_gateway: "192.168.2.1"
  137. clone.0.customize.0.linux_options.#: "1"
  138. clone.0.customize.0.linux_options.0.domain: "blacklab.corp"
  139. clone.0.customize.0.linux_options.0.host_name: "terraform-test"
  140. clone.0.customize.0.linux_options.0.hw_clock_utc: "true"
  141. clone.0.customize.0.network_interface.#: "1"
  142. clone.0.customize.0.network_interface.0.ipv4_address: "192.168.2.33"
  143. clone.0.customize.0.network_interface.0.ipv4_netmask: "24"
  144. clone.0.customize.0.timeout: "10"
  145. clone.0.template_uuid: "4212376d-d47c-9179-4d97-3f769a9e24ce"
  146. clone.0.timeout: "30"
  147. cpu_limit: "-1"
  148. cpu_share_count: <computed>
  149. cpu_share_level: "normal"
  150. datastore_id: "datastore-81"
  151. default_ip_address: <computed>
  152. disk.#: "1"
  153. disk.0.attach: "false"
  154. disk.0.datastore_id: "<computed>"
  155. disk.0.device_address: <computed>
  156. disk.0.disk_mode: "persistent"
  157. disk.0.disk_sharing: "sharingNone"
  158. disk.0.eagerly_scrub: "false"
  159. disk.0.io_limit: "-1"
  160. disk.0.io_reservation: "0"
  161. disk.0.io_share_count: "0"
  162. disk.0.io_share_level: "normal"
  163. disk.0.keep_on_remove: "false"
  164. disk.0.key: "0"
  165. disk.0.label: "disk0"
  166. disk.0.path: <computed>
  167. disk.0.size: "25"
  168. disk.0.thin_provisioned: "false"
  169. disk.0.unit_number: "0"
  170. disk.0.uuid: <computed>
  171. disk.0.write_through: "false"
  172. ept_rvi_mode: "automatic"
  173. firmware: "bios"
  174. force_power_off: "true"
  175. guest_id: "ubuntu64Guest"
  176. guest_ip_addresses.#: <computed>
  177. host_system_id: <computed>
  178. hv_mode: "hvAuto"
  179. imported: <computed>
  180. latency_sensitivity: "normal"
  181. memory: "4096"
  182. memory_limit: "-1"
  183. memory_share_count: <computed>
  184. memory_share_level: "normal"
  185. migrate_wait_timeout: "30"
  186. moid: <computed>
  187. name: "terraform-test"
  188. network_interface.#: "1"
  189. network_interface.0.adapter_type: "vmxnet3"
  190. network_interface.0.bandwidth_limit: "-1"
  191. network_interface.0.bandwidth_reservation: "0"
  192. network_interface.0.bandwidth_share_count: <computed>
  193. network_interface.0.bandwidth_share_level: "normal"
  194. network_interface.0.device_address: <computed>
  195. network_interface.0.key: <computed>
  196. network_interface.0.mac_address: <computed>
  197. network_interface.0.network_id: "network-12"
  198. num_cores_per_socket: "1"
  199. num_cpus: "2"
  200. reboot_required: <computed>
  201. resource_pool_id: "resgroup-184"
  202. run_tools_scripts_after_power_on: "true"
  203. run_tools_scripts_after_resume: "true"
  204. run_tools_scripts_before_guest_shutdown: "true"
  205. run_tools_scripts_before_guest_standby: "true"
  206. scsi_bus_sharing: "noSharing"
  207. scsi_controller_count: "1"
  208. scsi_type: "lsilogic"
  209. shutdown_wait_timeout: "3"
  210. swap_placement_policy: "inherit"
  211. uuid: <computed>
  212. vapp_transport.#: <computed>
  213. vmware_tools_status: <computed>
  214. vmx_path: <computed>
  215. wait_for_guest_net_routable: "true"
  216. wait_for_guest_net_timeout: "5"
  217.  
  218.  
  219. Plan: 2 to add, 0 to change, 0 to destroy.
  220.  
  221. Do you want to perform these actions?
  222. Terraform will perform the actions described above.
  223. Only 'yes' will be accepted to approve.
  224.  
  225. Enter a value: yes
  226.  
  227. vsphere_folder.Terraformtesting: Creating...
  228. datacenter_id: "" => "datacenter-2"
  229. path: "" => "Terraform Testing"
  230. type: "" => "vm"
  231. vsphere_folder.Terraformtesting: Creation complete after 0s (ID: group-v207)
  232. vsphere_virtual_machine.vm: Creating...
  233. boot_retry_delay: "" => "10000"
  234. change_version: "" => "<computed>"
  235. clone.#: "" => "1"
  236. clone.0.customize.#: "" => "1"
  237. clone.0.customize.0.dns_server_list.#: "" => "1"
  238. clone.0.customize.0.dns_server_list.0: "" => "192.168.2.2"
  239. clone.0.customize.0.dns_suffix_list.#: "" => "1"
  240. clone.0.customize.0.dns_suffix_list.0: "" => "blacklab.corp"
  241. clone.0.customize.0.ipv4_gateway: "" => "192.168.2.1"
  242. clone.0.customize.0.linux_options.#: "" => "1"
  243. clone.0.customize.0.linux_options.0.domain: "" => "blacklab.corp"
  244. clone.0.customize.0.linux_options.0.host_name: "" => "terraform-test"
  245. clone.0.customize.0.linux_options.0.hw_clock_utc: "" => "true"
  246. clone.0.customize.0.network_interface.#: "" => "1"
  247. clone.0.customize.0.network_interface.0.ipv4_address: "" => "192.168.2.33"
  248. clone.0.customize.0.network_interface.0.ipv4_netmask: "" => "24"
  249. clone.0.customize.0.timeout: "" => "10"
  250. clone.0.template_uuid: "" => "4212376d-d47c-9179-4d97-3f769a9e24ce"
  251. clone.0.timeout: "" => "30"
  252. cpu_limit: "" => "-1"
  253. cpu_share_count: "" => "<computed>"
  254. cpu_share_level: "" => "normal"
  255. datastore_id: "" => "datastore-81"
  256. default_ip_address: "" => "<computed>"
  257. disk.#: "" => "1"
  258. disk.0.attach: "" => "false"
  259. disk.0.datastore_id: "" => "<computed>"
  260. disk.0.device_address: "" => "<computed>"
  261. disk.0.disk_mode: "" => "persistent"
  262. disk.0.disk_sharing: "" => "sharingNone"
  263. disk.0.eagerly_scrub: "" => "false"
  264. disk.0.io_limit: "" => "-1"
  265. disk.0.io_reservation: "" => "0"
  266. disk.0.io_share_count: "" => "0"
  267. disk.0.io_share_level: "" => "normal"
  268. disk.0.keep_on_remove: "" => "false"
  269. disk.0.key: "" => "0"
  270. disk.0.label: "" => "disk0"
  271. disk.0.path: "" => "<computed>"
  272. disk.0.size: "" => "25"
  273. disk.0.thin_provisioned: "" => "false"
  274. disk.0.unit_number: "" => "0"
  275. disk.0.uuid: "" => "<computed>"
  276. disk.0.write_through: "" => "false"
  277. ept_rvi_mode: "" => "automatic"
  278. firmware: "" => "bios"
  279. force_power_off: "" => "true"
  280. guest_id: "" => "ubuntu64Guest"
  281. guest_ip_addresses.#: "" => "<computed>"
  282. host_system_id: "" => "<computed>"
  283. hv_mode: "" => "hvAuto"
  284. imported: "" => "<computed>"
  285. latency_sensitivity: "" => "normal"
  286. memory: "" => "4096"
  287. memory_limit: "" => "-1"
  288. memory_share_count: "" => "<computed>"
  289. memory_share_level: "" => "normal"
  290. migrate_wait_timeout: "" => "30"
  291. moid: "" => "<computed>"
  292. name: "" => "terraform-test"
  293. network_interface.#: "" => "1"
  294. network_interface.0.adapter_type: "" => "vmxnet3"
  295. network_interface.0.bandwidth_limit: "" => "-1"
  296. network_interface.0.bandwidth_reservation: "" => "0"
  297. network_interface.0.bandwidth_share_count: "" => "<computed>"
  298. network_interface.0.bandwidth_share_level: "" => "normal"
  299. network_interface.0.device_address: "" => "<computed>"
  300. network_interface.0.key: "" => "<computed>"
  301. network_interface.0.mac_address: "" => "<computed>"
  302. network_interface.0.network_id: "" => "network-12"
  303. num_cores_per_socket: "" => "1"
  304. num_cpus: "" => "2"
  305. reboot_required: "" => "<computed>"
  306. resource_pool_id: "" => "resgroup-184"
  307. run_tools_scripts_after_power_on: "" => "true"
  308. run_tools_scripts_after_resume: "" => "true"
  309. run_tools_scripts_before_guest_shutdown: "" => "true"
  310. run_tools_scripts_before_guest_standby: "" => "true"
  311. scsi_bus_sharing: "" => "noSharing"
  312. scsi_controller_count: "" => "1"
  313. scsi_type: "" => "lsilogic"
  314. shutdown_wait_timeout: "" => "3"
  315. swap_placement_policy: "" => "inherit"
  316. uuid: "" => "<computed>"
  317. vapp_transport.#: "" => "<computed>"
  318. vmware_tools_status: "" => "<computed>"
  319. vmx_path: "" => "<computed>"
  320. wait_for_guest_net_routable: "" => "true"
  321. wait_for_guest_net_timeout: "" => "5"
  322. vsphere_virtual_machine.vm: Still creating... (10s elapsed)
  323. vsphere_virtual_machine.vm: Still creating... (20s elapsed)
  324. vsphere_virtual_machine.vm: Still creating... (30s elapsed)
  325. vsphere_virtual_machine.vm: Still creating... (40s elapsed)
  326. vsphere_virtual_machine.vm: Still creating... (50s elapsed)
  327. vsphere_virtual_machine.vm: Still creating... (1m0s elapsed)
  328. vsphere_virtual_machine.vm: Still creating... (1m10s elapsed)
  329. vsphere_virtual_machine.vm: Still creating... (1m20s elapsed)
  330. vsphere_virtual_machine.vm: Still creating... (1m30s elapsed)
  331. vsphere_virtual_machine.vm: Still creating... (1m40s elapsed)
  332. vsphere_virtual_machine.vm: Still creating... (1m50s elapsed)
  333. vsphere_virtual_machine.vm: Still creating... (2m0s elapsed)
  334. vsphere_virtual_machine.vm: Still creating... (2m10s elapsed)
  335. vsphere_virtual_machine.vm: Still creating... (2m20s elapsed)
  336. vsphere_virtual_machine.vm: Still creating... (2m30s elapsed)
  337. vsphere_virtual_machine.vm: Still creating... (2m40s elapsed)
  338. vsphere_virtual_machine.vm: Still creating... (2m50s elapsed)
  339. vsphere_virtual_machine.vm: Still creating... (3m0s elapsed)
  340. vsphere_virtual_machine.vm: Still creating... (3m10s elapsed)
  341. vsphere_virtual_machine.vm: Still creating... (3m20s elapsed)
  342. vsphere_virtual_machine.vm: Still creating... (3m30s elapsed)
  343. vsphere_virtual_machine.vm: Still creating... (3m40s elapsed)
  344. vsphere_virtual_machine.vm: Still creating... (3m50s elapsed)
  345. vsphere_virtual_machine.vm: Still creating... (4m0s elapsed)
  346. vsphere_virtual_machine.vm: Still creating... (4m10s elapsed)
  347. vsphere_virtual_machine.vm: Still creating... (4m20s elapsed)
  348. vsphere_virtual_machine.vm: Still creating... (4m30s elapsed)
  349. vsphere_virtual_machine.vm: Still creating... (4m40s elapsed)
  350. vsphere_virtual_machine.vm: Still creating... (4m50s elapsed)
  351. vsphere_virtual_machine.vm: Still creating... (5m0s elapsed)
  352. vsphere_virtual_machine.vm: Still creating... (5m10s elapsed)
  353. vsphere_virtual_machine.vm: Still creating... (5m20s elapsed)
  354. vsphere_virtual_machine.vm: Still creating... (5m30s elapsed)
  355. vsphere_virtual_machine.vm: Still creating... (5m40s elapsed)
  356. vsphere_virtual_machine.vm: Still creating... (5m50s elapsed)
  357. vsphere_virtual_machine.vm: Still creating... (6m0s elapsed)
  358. vsphere_virtual_machine.vm: Still creating... (6m10s elapsed)
  359. vsphere_virtual_machine.vm: Still creating... (6m20s elapsed)
  360. vsphere_virtual_machine.vm: Still creating... (6m30s elapsed)
  361.  
  362. Error: Error applying plan:
  363.  
  364. 1 error(s) occurred:
  365.  
  366. * vsphere_virtual_machine.vm: 1 error(s) occurred:
  367.  
  368. * vsphere_virtual_machine.vm: timeout waiting for an available IP address
  369.  
  370. Terraform does not automatically rollback in the face of errors.
  371. Instead, your Terraform state file has been partially updated with
  372. any resources that successfully completed. Please address the error
  373. above and apply again to incrementally change your infrastructure.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement