you can just wrap the declaration in a normal Go `...
# golang
i
you can just wrap the declaration in a normal Go
if
condition - if the resource is declared, Pulumi will ensure it exists.. if it isn’t declared but the condition evaluated to false, then Pulumi will remove it if it already exists in the same way it would if you deleted the resource from your program normally
c
To make my question more specific, I've created 2 vms and both has specific time stamps. vm1: 100 vm2: 200 I want to delete only vm2 because the time stamp is more than 150. Is there any way to programatically do that ?
not the logical part, but select the vm, and deletion part
l
Can you explain more about the system you're trying to design and it's goals? I feel like there's a way to express this that takes advantage of the desired state nature of pulumi. How are the VMs created, why do you want to delete them?
c
Hi @lemon-agent-27707 I want to create a pulumi program, which creates vms with specific lifespan. Means a developer can create a VM for 5days. After 5th day Pulumi have to delete the vm. We'll run the pulumi program as a cron every night to check the lifespan. Pulumi.dev.yaml
Copy code
config:
  azure:location: centralindia
  vm:instance_spec:
  # Cassandra Cluster
  - count: 1
    data_disk_size: 50
    name: cassandra
    resource_group: pu_demo
    type: Standard_A8_v2
    user_name: deployer
    life_span: 5 # Lifespan in days, after this time, this machine will get autodelted
    image_id: cassandra # From which image the machine should be created from
    password:
      secure: XXXXXX
life_span
field in yaml will create a tag called
lifeSpan
in machine, along with the
creationTime
in epoch. every night, we'll run this pulumi program, which will check
today - creationTime > lifespan
then take a snapshot and delete the VM
@lemon-agent-27707 Any direction will be very helpful, as this will allow devs to create disposible vms. in a very cost effective manner
l
I think this would be a good use case for automation api. You would create a stack per VM, and then output the VM creation time as a stack output. Then the automation API lists all stacks, iterates through each one looking for stacks that have old timestamp outputs, and destroys them.
How will developers create the VMs? Will they run pulumi directly?
Or will it be through some sort of API or ticketing system
c
Nope. 1. They'll raise a PR after updating the pulumi.dev.yaml in git, 2. will get approved and merged, 3. which in turn trigger a jenkins ci
l
What cloud do you use
c
azure
@lemon-agent-27707 any pointers ? I think This can be a great value add for many out there, who want a ready made solution for throwaway infra, or quick infra for testing
l
I can prototype something to get you started.
🎉 1
c
woohooo... awesome. That'll be a huuuge help to get things started. Once this is done, We'll contribute back to pulumi example, as I told I searched a lot for a ready made solution.
l
I have an example for you, but let's continue the discussion in #automation-api https://pulumi-community.slack.com/archives/C019YSXN04B/p1599262963014300