brash-nightfall-51586
01/11/2024, 4:16 PMimport pulumi
import pulumi_vsphere as vsphere
# Names of your resources in vSphere
datastore_name = 'roels-bart'
network_name = 'VM Network'
resource_pool_name = 'test'
datacenter_name = 'StudentDC'
template_name = 'CleanUbuntu'
# Lookup the Datacenter by name
datacenter = vsphere.get_datacenter(name=datacenter_name)
# Lookup the Datastore by name
datastore = vsphere.get_datastore(name="roels-bart", datacenter_id=datacenter.id)
# Lookup network by name
network = vsphere.get_network(name="VM Network", datacenter_id=datacenter.id)
# Default parent resource pool
pool = vsphere.get_resource_pool(name="Resources", datacenter_id=datacenter.id)
# Lookup template by name
template = vsphere.get_virtual_machine(name="CleanUbuntu", datacenter_id=datacenter.id)
# Create a when this script is runned
virtual_machine = vsphere.VirtualMachine("pulumi-vm",
name='pulumi-vm',
datastore_id=datastore.id,
resource_pool_id=pool.id,
num_cpus=1,
memory=1024,
guest_id='ubuntu64Guest',
scsi_type='pvscsi',
network_interfaces=[{
'network_id': network.id,
'adapter_type': 'vmxnet3',
}],
clone={
'template_uuid': template.id,
},
# Assing disk
disks=[
{
'label': 'disk0',
'size': 20,
'eagerly_scrub': False,
'thin_provisioned': True,
},
],
# Customise the VM's configuration
)
# Export the virtual machine's properties
pulumi.export('vm_name', virtual_machine.name)
pulumi.export('vm_id', virtual_machine.id)
Can someone help me modify this script to ensure that a new VM is created with every 'pulumi up' run, rather than updating the existing one?
Also, I'm curious if there's a recommended way to run Pulumi scripts from another location, like a Flask application. I'm thinking of a scenario where users can input parameters through a web interface to customize the VM creation process. Any suggestions or best practices for achieving this would be greatly appreciated.
Thanks in advance!dry-keyboard-94795
01/11/2024, 4:24 PMdry-keyboard-94795
01/11/2024, 4:24 PMbrash-nightfall-51586
01/12/2024, 9:22 AMlimited-rainbow-51650
01/12/2024, 2:01 PMpulumi
CLI. The Automation API that @dry-keyboard-94795 refers to allows you to wrap a full Pulumi project and run the CLI commands via an API.
In the simplest setup, you can refer to a local program, meaning it is a local folder containing a workable infrastructure program. In such case there is no need to run install_plugin
as this will be done automatically.
A step up is if you combine your infrastructure as code program with the automation API code in a single program. From the automation API code you then use an "inline program". You then have to use "install_plugin" to install the plugin binaries. For VSphere, you indeed use stack.workspace.install_plugin("vsphere", "4.9.1")
. The version should point to an existing version for the VSphere package (see Pulumi Registry) and should match the version of the Pulumi Python package for VSphere you have in your requirements.txt
.
Hope this clarifies a bit.limited-rainbow-51650
01/12/2024, 2:04 PMroels-bart
is your name, that sounds very Flemish to me. If you are from the vicinity, I want to inform you that a few of us from the Pulumi team will be at CfgMgmtCamp in Ghent from 5 to 7 Februari. On Wednesday 7 February, we have an open devroom. Feel free to come over with all of your questions, but don't forget to register on the CfgMgmtCamp website.
https://cfgmgmtcamp.eu/ghent2024/brash-nightfall-51586
01/12/2024, 2:22 PMgreen-alligator-4238
01/13/2024, 5:31 PMdry-keyboard-94795
01/13/2024, 5:46 PMpulumi output
to load it into other toolinggreen-alligator-4238
01/13/2024, 7:01 PM