Created
July 27, 2018 22:23
-
-
Save fl64/76f996648686b35239bbf7a5344b725b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Basic configuration withour variables | |
# Define authentification configuration | |
provider "vsphere" { | |
# If you use a domain set your login like this "MyDomain\\MyUser" | |
user = "example.com\\username" | |
password = "P@ssw0rd" | |
vsphere_server = "10.0.0.10" | |
# if you have a self-signed cert | |
allow_unverified_ssl = true | |
} | |
#### RETRIEVE DATA INFORMATION ON VCENTER #### | |
data "vsphere_datacenter" "dc" { | |
name = "example.dc" | |
} | |
data "vsphere_resource_pool" "pool" { | |
# If you haven't resource pool, put "Resources" after cluster name | |
name = "10.0.0.20/Resources" | |
datacenter_id = "${data.vsphere_datacenter.dc.id}" | |
} | |
data "vsphere_host" "host" { | |
name = "10.0.0.20" | |
datacenter_id = "${data.vsphere_datacenter.dc.id}" | |
} | |
# Retrieve datastore information on vsphere | |
data "vsphere_datastore" "datastore" { | |
name = "Lun0Datastore02" | |
datacenter_id = "${data.vsphere_datacenter.dc.id}" | |
} | |
# Retrieve network information on vsphere | |
data "vsphere_network" "network" { | |
name = "VM_Network" | |
datacenter_id = "${data.vsphere_datacenter.dc.id}" | |
} | |
# Retrieve template information on vsphere | |
data "vsphere_virtual_machine" "template" { | |
name = "win-tmp-64" | |
datacenter_id = "${data.vsphere_datacenter.dc.id}" | |
} | |
#### VM CREATION #### | |
# Set vm parameters | |
resource "vsphere_virtual_machine" "vm-one" { | |
name = "vm-one" | |
num_cpus = 2 | |
memory = 4096 | |
datastore_id = "${data.vsphere_datastore.datastore.id}" | |
host_system_id = "${data.vsphere_host.host.id}" | |
resource_pool_id = "${data.vsphere_resource_pool.pool.id}" | |
guest_id = "${data.vsphere_virtual_machine.template.guest_id}" | |
scsi_type = "${data.vsphere_virtual_machine.template.scsi_type}" | |
#wait_for_guest_net = false | |
# Set network parameters | |
network_interface { | |
network_id = "${data.vsphere_network.network.id}" | |
} | |
# Use a predefined vmware template has main disk | |
disk { | |
name = "vm-one.vmdk" | |
size = "40" | |
thin_provisioned = true | |
} | |
clone { | |
template_uuid = "${data.vsphere_virtual_machine.template.id}" | |
linked_clone = true | |
customize { | |
timeout = 20 | |
windows_options { | |
computer_name = "Win-PS" | |
admin_password = "P@ssw0rd" | |
auto_logon = true | |
auto_logon_count = 1 | |
full_name = "Administrator" | |
run_once_command_list = [ | |
#"winrm quickconfig -force", | |
#"winrm set winrm/config @{MaxEnvelopeSizekb=\"100000\"}", | |
#"winrm set winrm/config/Service @{AllowUnencrypted=\"true\"}", | |
#"winrm set winrm/config/Service/Auth @{Basic=\"true\"}", | |
#"netsh advfirewall set allprofiles state off", | |
#"echo XXX > c:\\Windows\\temp\\111.txt" | |
"powershell -command \"& {Set-ExecutionPolicy Unrestricted}", | |
#"powershell -command \"& {Invoke-Expression ((New-Object System.Net.Webclient).DownloadString(\"https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1\"))}\"" | |
"powershell -Command \"Invoke-WebRequest -Uri https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1 -OutFile ConfigureRemotingForAnsible.ps1\"", | |
"powershell -Command \"powershell ConfigureRemotingForAnsible.ps1\"" | |
] | |
} | |
network_interface { | |
#ipv4_address = "192.168.124.28" | |
#ipv4_netmask = 22 | |
dns_server_list = [ | |
"8.8.8.8", | |
"8.8.4.4"] | |
} | |
#ipv4_gateway = "192.168.124.4" | |
} | |
} | |
# provisioner "remote-exec" { | |
# inline = "Get-Date > c:\\Windows\\temp\\completed.txt" | |
# interpreter = ["PowerShell", "-Command"] | |
provisioner "file" { | |
source = "main.tf" | |
destination = "C:\\Windows\\Temp\\file.tf" | |
connection { | |
type = "winrm" | |
user = "Administrator" | |
password = "P@ssw0rd" | |
port = 5986 | |
https = true | |
insecure = true | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment