HI, I have an issue with an update to an Azure vir...
# azure
c
HI, I have an issue with an update to an Azure virtual machine that I am hoping someone can help me with. 1. Create a new stack with the following new resources: a) Network Security Group b) Security Rule c) Public IP d) Route Table e) Network Interfaces f) Virtual Machine 2. Update the stack created in #1: a) Add new network interface b) Attach to the VM we encountering a challenge: In the compute package ("github.com/pulumi/pulumi-azure-native/sdk/go/azure/compute"), we cannot find a method to update an existing VM to attach a new interface. While there is "compute.NewVirtualMachine" to create a new VM, there is no "compute.UpdateVirtualMachine" to update an existing VM. Suggestions Needed: I'm looking for ways to update the existing VM that is part of the stack without deleting and recreating it.
m
I'm not sure I understand the question correctly but it seems that the Azure intro tutorial shows you how to do that: https://www.pulumi.com/docs/iac/get-started/azure/modify-program/ In short, you modify your existing program so that it includes the new network interface and attachment, and then deploy the stack again. Pulumi will figure out the difference between what's in your program (your desired state) and what's currently deployed on Azure (the current state), and make the necessary changes. According to the documentation, changes to NetworkInterfaces do not require resource recreation but can be handled as an update. Apologies if I misunderstood your question. In that case, it would be helpful to show a small code snippet so others can understand what exactly the problem is you're running into.
a
Pulumi is declarative so you make changes to the configurations of a current resource and run an update. Creation and update operations are not separate. Unfortunately VMs need to be stopped while attaching a new NIC but you should be able to just add your additional NICs to the
VirtualMachine.network_profile.network_interface_configurations
property while the VM is stopped.
m
If you find what Olafur and I just wrote a bit confusing, I recommend having a look at https://www.pulumi.com/docs/iac/concepts/how-pulumi-works/ There's an example using an AWS S3 bucket further down on the that covers a simplified version of your scenario. The page explains in great detail how and why this works, and the time it takes to study the page will pay off quickly.
c
Thanks for your reply @adventurous-butcher-54166, could you please help me, how we can stop Azure VM using pulumi. is it any way.
a
You could potentially use the azapi provider's ResourceAction to do that if you have the need to apply this on a large scale but I have no clue if you'd have to programmatically figure out whether an update requires a stop/start. If you're only handling a few VMs stopping/starting manually would probably be my advise.
Copy code
ResourceAction(
  resource_id=your_vm.id,
  action="stop",
  when="apply",
)
Another option would be to use pulumi-command's local.Command with
az
cli and configure your NIC configurations as a trigger on that so it only happens when those need to be changed.