Last active
October 28, 2021 16:59
-
-
Save nma/62ad47dec38fb9987366fd69a01da252 to your computer and use it in GitHub Desktop.
Vsphere Terraform VApp Example
This file contains hidden or 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
terraform { | |
required_providers { | |
vsphere = { | |
source = "hashicorp/vsphere" | |
version = "1.11" | |
} | |
} | |
} | |
provider "vsphere" { | |
user = "username" | |
password = "password" | |
vsphere_server = "localhost:8989" | |
allow_unverified_ssl = true | |
} | |
data "vsphere_datacenter" "dc" { | |
name = "DC0" | |
} | |
data "vsphere_datastore" "datastore" { | |
name = "datastore/LocalDS_0" | |
datacenter_id = data.vsphere_datacenter.dc.id | |
} | |
data "vsphere_resource_pool" "pool" { | |
name = "DC0_H0/Resources" | |
datacenter_id = data.vsphere_datacenter.dc.id | |
} | |
data "vsphere_network" "network" { | |
name = "network/VM Network" | |
datacenter_id = data.vsphere_datacenter.dc.id | |
} | |
data "vsphere_virtual_machine" "template" { | |
name = "DC0_H0_VM0" | |
datacenter_id = data.vsphere_datacenter.dc.id | |
} | |
data "template_file" "user_data" { | |
template = <<EOF | |
#cloud-config | |
disable_root: false | |
ntp: | |
enabled: true | |
servers: ["ntp.ubuntu.com"] | |
ntp_client: systemd-timesyncd | |
EOF | |
} | |
resource "vsphere_virtual_machine" "vm" { | |
name = "terraform-test" | |
resource_pool_id = data.vsphere_resource_pool.pool.id | |
datastore_id = data.vsphere_datastore.datastore.id | |
num_cpus = 2 | |
memory = 4096 | |
guest_id = data.vsphere_virtual_machine.template.guest_id | |
network_interface { | |
network_id = data.vsphere_network.network.id | |
adapter_type = data.vsphere_virtual_machine.template.network_interface_types[0] | |
} | |
disk { | |
label = "disk0" | |
size = 50 | |
} | |
clone { | |
template_uuid = data.vsphere_virtual_machine.template.id | |
} | |
/*vapp { | |
properties = { | |
hostname = "test" | |
public-keys = file("mock.pub") | |
user-data = base64encode(data.template_file.user_data.rendered) | |
} | |
}*/ | |
scsi_type = data.vsphere_virtual_machine.template.scsi_type | |
wait_for_guest_net_timeout = "-1" | |
} |
This file contains hidden or 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
-----BEGIN PUBLIC KEY----- | |
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC3Yyk6AyXlwv/LpH10aQYtBgbV | |
9Ll1t8yBZD+fFRBqiz/zAFECvuOv9cSc0QgNoSgfH5Tly51bMthMsDW/T7S95zCh | |
BkKQyVxE2TVeJv+RNUBv0RFFCcmZbFDjNb0IPn4rJvkPFE874Y7PZOF5DID5Wp+s | |
sXUm8BNztAQp0Vj35QIDAQAB | |
-----END PUBLIC KEY----- |
This file contains hidden or 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
{ | |
"ChangeVersion": "", | |
"Modified": "2021-10-28T16:30:38.461575341Z", | |
"Name": "DC0_H0_VM0", | |
"GuestFullName": "otherGuest", | |
"Version": "vmx-13", | |
"Uuid": "265104de-1472-547c-b873-6dc7883fb6cb", | |
"CreateDate": "2021-10-28T16:30:38.460894008Z", | |
"InstanceUuid": "b4689bed-97f0-5bcd-8a4c-07477cc8f06f", | |
"NpivNodeWorldWideName": null, | |
"NpivPortWorldWideName": null, | |
"NpivWorldWideNameType": "", | |
"NpivDesiredNodeWwns": 0, | |
"NpivDesiredPortWwns": 0, | |
"NpivTemporaryDisabled": null, | |
"NpivOnNonRdmDisks": null, | |
"LocationId": "", | |
"Template": false, | |
"GuestId": "otherGuest", | |
"AlternateGuestName": "", | |
"Annotation": "", | |
"Files": { | |
"VmPathName": "[LocalDS_0] DC0_H0_VM0/DC0_H0_VM0.vmx", | |
"SnapshotDirectory": "[LocalDS_0] DC0_H0_VM0", | |
"SuspendDirectory": "[LocalDS_0] DC0_H0_VM0", | |
"LogDirectory": "[LocalDS_0] DC0_H0_VM0", | |
"FtMetadataDirectory": "" | |
}, | |
"Tools": { | |
"ToolsVersion": 0, | |
"ToolsInstallType": "", | |
"AfterPowerOn": null, | |
"AfterResume": null, | |
"BeforeGuestStandby": null, | |
"BeforeGuestShutdown": null, | |
"BeforeGuestReboot": null, | |
"ToolsUpgradePolicy": "", | |
"PendingCustomization": "", | |
"CustomizationKeyId": null, | |
"SyncTimeWithHost": null, | |
"LastInstallInfo": null | |
}, | |
"Flags": { | |
"DisableAcceleration": null, | |
"EnableLogging": null, | |
"UseToe": null, | |
"RunWithDebugInfo": null, | |
"MonitorType": "", | |
"HtSharing": "", | |
"SnapshotDisabled": null, | |
"SnapshotLocked": null, | |
"DiskUuidEnabled": null, | |
"VirtualMmuUsage": "", | |
"VirtualExecUsage": "", | |
"SnapshotPowerOffBehavior": "", | |
"RecordReplayEnabled": null, | |
"FaultToleranceType": "", | |
"CbrcCacheEnabled": null, | |
"VvtdEnabled": null, | |
"VbsEnabled": null | |
}, | |
"ConsolePreferences": null, | |
"DefaultPowerOps": { | |
"PowerOffType": "", | |
"SuspendType": "", | |
"ResetType": "", | |
"DefaultPowerOffType": "", | |
"DefaultSuspendType": "", | |
"DefaultResetType": "", | |
"StandbyAction": "" | |
}, | |
"Hardware": { | |
"NumCPU": 1, | |
"NumCoresPerSocket": 1, | |
"MemoryMB": 32, | |
"VirtualICH7MPresent": null, | |
"VirtualSMCPresent": null, | |
"Device": [ | |
{ | |
"Key": 200, | |
"DeviceInfo": { | |
"Label": "IDE 0", | |
"Summary": "IDE 0" | |
}, | |
"Backing": null, | |
"Connectable": null, | |
"SlotInfo": null, | |
"ControllerKey": 0, | |
"UnitNumber": null, | |
"BusNumber": 0, | |
"Device": null | |
}, | |
{ | |
"Key": 201, | |
"DeviceInfo": { | |
"Label": "IDE 1", | |
"Summary": "IDE 1" | |
}, | |
"Backing": null, | |
"Connectable": null, | |
"SlotInfo": null, | |
"ControllerKey": 0, | |
"UnitNumber": null, | |
"BusNumber": 1, | |
"Device": null | |
}, | |
{ | |
"Key": 300, | |
"DeviceInfo": { | |
"Label": "PS2 controller 0", | |
"Summary": "PS2 controller 0" | |
}, | |
"Backing": null, | |
"Connectable": null, | |
"SlotInfo": null, | |
"ControllerKey": 0, | |
"UnitNumber": null, | |
"BusNumber": 0, | |
"Device": [ | |
600, | |
700 | |
] | |
}, | |
{ | |
"Key": 100, | |
"DeviceInfo": { | |
"Label": "PCI controller 0", | |
"Summary": "PCI controller 0" | |
}, | |
"Backing": null, | |
"Connectable": null, | |
"SlotInfo": null, | |
"ControllerKey": 0, | |
"UnitNumber": null, | |
"BusNumber": 0, | |
"Device": [ | |
500, | |
12000 | |
] | |
}, | |
{ | |
"Key": 400, | |
"DeviceInfo": { | |
"Label": "SIO controller 0", | |
"Summary": "SIO controller 0" | |
}, | |
"Backing": null, | |
"Connectable": null, | |
"SlotInfo": null, | |
"ControllerKey": 0, | |
"UnitNumber": null, | |
"BusNumber": 0, | |
"Device": null | |
}, | |
{ | |
"Key": 600, | |
"DeviceInfo": { | |
"Label": "Keyboard ", | |
"Summary": "Keyboard" | |
}, | |
"Backing": null, | |
"Connectable": null, | |
"SlotInfo": null, | |
"ControllerKey": 300, | |
"UnitNumber": 0 | |
}, | |
{ | |
"Key": 700, | |
"DeviceInfo": { | |
"Label": "Pointing device", | |
"Summary": "Pointing device; Device" | |
}, | |
"Backing": { | |
"DeviceName": "", | |
"UseAutoDetect": false, | |
"HostPointingDevice": "autodetect" | |
}, | |
"Connectable": null, | |
"SlotInfo": null, | |
"ControllerKey": 300, | |
"UnitNumber": 1 | |
}, | |
{ | |
"Key": 500, | |
"DeviceInfo": { | |
"Label": "Video card ", | |
"Summary": "Video card" | |
}, | |
"Backing": null, | |
"Connectable": null, | |
"SlotInfo": null, | |
"ControllerKey": 100, | |
"UnitNumber": 0, | |
"VideoRamSizeInKB": 4096, | |
"NumDisplays": 1, | |
"UseAutoDetect": false, | |
"Enable3DSupport": false, | |
"Use3dRenderer": "automatic", | |
"GraphicsMemorySizeInKB": 262144 | |
}, | |
{ | |
"Key": 12000, | |
"DeviceInfo": { | |
"Label": "VMCI device", | |
"Summary": "Device on the virtual machine PCI bus that provides support for the virtual machine communication interface" | |
}, | |
"Backing": null, | |
"Connectable": null, | |
"SlotInfo": null, | |
"ControllerKey": 100, | |
"UnitNumber": 17, | |
"Id": -1, | |
"AllowUnrestrictedCommunication": false, | |
"FilterEnable": true, | |
"FilterInfo": null | |
}, | |
{ | |
"Key": 202, | |
"DeviceInfo": { | |
"Label": "pvscsi-202", | |
"Summary": "pvscsi-202" | |
}, | |
"Backing": null, | |
"Connectable": null, | |
"SlotInfo": null, | |
"ControllerKey": 0, | |
"UnitNumber": null, | |
"BusNumber": 0, | |
"Device": null, | |
"HotAddRemove": null, | |
"SharedBus": "noSharing", | |
"ScsiCtlrUnitNumber": 7 | |
}, | |
{ | |
"Key": 1697971134, | |
"DeviceInfo": { | |
"Label": "cdrom-1697971134", | |
"Summary": "cdrom-1697971134" | |
}, | |
"Backing": { | |
"DeviceName": "cdrom--201-824639096096", | |
"UseAutoDetect": false | |
}, | |
"Connectable": { | |
"MigrateConnect": "", | |
"StartConnected": true, | |
"AllowGuestControl": true, | |
"Connected": true, | |
"Status": "" | |
}, | |
"SlotInfo": null, | |
"ControllerKey": 202, | |
"UnitNumber": 0 | |
}, | |
{ | |
"Key": 255511522, | |
"DeviceInfo": { | |
"Label": "disk-202-0", | |
"Summary": "10,485,760 KB" | |
}, | |
"Backing": { | |
"FileName": "[LocalDS_0] terraform-test/terraform-test.vmdk", | |
"Datastore": { | |
"Type": "Datastore", | |
"Value": "/tmp/govcsim-DC0-LocalDS_0-288111359@group-5" | |
}, | |
"BackingObjectId": "", | |
"DiskMode": "persistent", | |
"Split": false, | |
"WriteThrough": false, | |
"ThinProvisioned": true, | |
"EagerlyScrub": false, | |
"Uuid": "516a8674-a275-54e2-a91c-b181f6baf7ee", | |
"ContentId": "", | |
"ChangeId": "", | |
"Parent": null, | |
"DeltaDiskFormat": "", | |
"DigestEnabled": false, | |
"DeltaGrainSize": 0, | |
"DeltaDiskFormatVariant": "", | |
"Sharing": "", | |
"KeyId": null | |
}, | |
"Connectable": null, | |
"SlotInfo": null, | |
"ControllerKey": 202, | |
"UnitNumber": 0, | |
"CapacityInKB": 10485760, | |
"CapacityInBytes": 0, | |
"Shares": null, | |
"StorageIOAllocation": null, | |
"DiskObjectId": "", | |
"VFlashCacheConfigInfo": null, | |
"Iofilter": null, | |
"VDiskId": null, | |
"NativeUnmanagedLinkedClone": null | |
}, | |
{ | |
"Key": 4000, | |
"DeviceInfo": { | |
"Label": "ethernet-0", | |
"Summary": "DVSwitch: fea97929-4b2d-5972-b146-930c6d0b4014" | |
}, | |
"Backing": { | |
"Port": { | |
"SwitchUuid": "fea97929-4b2d-5972-b146-930c6d0b4014", | |
"PortgroupKey": "dvportgroup-13", | |
"PortKey": "", | |
"ConnectionCookie": 0 | |
} | |
}, | |
"Connectable": { | |
"MigrateConnect": "", | |
"StartConnected": true, | |
"AllowGuestControl": true, | |
"Connected": false, | |
"Status": "untried" | |
}, | |
"SlotInfo": { | |
"PciSlotNumber": 32 | |
}, | |
"ControllerKey": 100, | |
"UnitNumber": 7, | |
"AddressType": "generated", | |
"MacAddress": "00:0c:29:36:63:62", | |
"WakeOnLanEnabled": true, | |
"ResourceAllocation": null, | |
"ExternalId": "", | |
"UptCompatibilityEnabled": null | |
} | |
] | |
}, | |
"CpuAllocation": { | |
"Reservation": 0, | |
"ExpandableReservation": true, | |
"Limit": -1, | |
"Shares": { | |
"Shares": 0, | |
"Level": "normal" | |
}, | |
"OverheadLimit": null | |
}, | |
"MemoryAllocation": { | |
"Reservation": 0, | |
"ExpandableReservation": true, | |
"Limit": -1, | |
"Shares": { | |
"Shares": 0, | |
"Level": "normal" | |
}, | |
"OverheadLimit": null | |
}, | |
"LatencySensitivity": { | |
"Level": "normal", | |
"Sensitivity": 0 | |
}, | |
"MemoryHotAddEnabled": null, | |
"CpuHotAddEnabled": null, | |
"CpuHotRemoveEnabled": null, | |
"HotPlugMemoryLimit": 0, | |
"HotPlugMemoryIncrementSize": 0, | |
"CpuAffinity": null, | |
"MemoryAffinity": null, | |
"NetworkShaper": null, | |
"ExtraConfig": [ | |
{ | |
"Key": "govcsim", | |
"Value": "TRUE" | |
} | |
], | |
"CpuFeatureMask": null, | |
"DatastoreUrl": null, | |
"SwapPlacement": "", | |
"BootOptions": { | |
"BootDelay": 0, | |
"EnterBIOSSetup": null, | |
"EfiSecureBootEnabled": null, | |
"BootRetryEnabled": null, | |
"BootRetryDelay": 0, | |
"BootOrder": null, | |
"NetworkBootProtocol": "" | |
}, | |
"FtInfo": null, | |
"RepConfig": null, | |
"VAppConfig": null, | |
"VAssertsEnabled": null, | |
"ChangeTrackingEnabled": null, | |
"Firmware": "bios", | |
"MaxMksConnections": 0, | |
"GuestAutoLockEnabled": null, | |
"ManagedBy": null, | |
"MemoryReservationLockedToMax": null, | |
"InitialOverhead": null, | |
"NestedHVEnabled": null, | |
"VPMCEnabled": null, | |
"ScheduledHardwareUpgradeInfo": null, | |
"ForkConfigInfo": null, | |
"VFlashCacheReservation": 0, | |
"VmxConfigChecksum": null, | |
"MessageBusTunnelEnabled": null, | |
"VmStorageObjectId": "", | |
"SwapStorageObjectId": "", | |
"KeyId": null, | |
"GuestIntegrityInfo": null, | |
"MigrateEncryption": "" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment