https://pulumi.com logo
Title
r

rhythmic-rainbow-38499

03/20/2023, 1:22 AM
Hi All 👋 , I'm working on a problem where I am trying to conditionally control the AMI ID that is used to create an EC2 instance in my Pulumi program (typescript). If the stack already contains an EC2 instance with a name, then I want to just use the AMI ID that is already used by that instance, but if this program is running for the fist time I want to lookup and use the latest AMI ID from AWS. I've been googling around and experimenting with StackReference, but I can't seem to figure out how this should work. Ultimately this approach is in order to prevent the EC2 instance from being recreated because a new AMI is available other than the one that was originally used. Are there concepts/approaches I should know more about to make this work? Thanks
l

little-cartoon-10569

03/20/2023, 3:33 AM
I would look up the AMI ID by hand and put it in your config. It can of course be solved in code, but this lookup-once-deploy-many-times problem is easiest solved by hand.
Also, this way, you can decide (in the form of raising a PR and doing a code review) when you want to update the machine to the latest image.
c

cuddly-magician-97620

03/20/2023, 12:27 PM
In Terraform it is easily solved with:
lifecycle {
    ignore_changes = [ ami ]
  }
I suppose, Pulumi does not have an equivalent? 🤔
r

rhythmic-rainbow-38499

03/20/2023, 3:26 PM
I would look up the AMI ID by hand and put it in your config
This is what I ended up doing ultimately, but I'm still kind of interested how I could have accomplished what I was trying to do orginally
I suppose, Pulumi does not have an equivalent?
Yeah, unless I missed it from what I could tell there were flags/behaviors I could set to cause when a resource would be force deleted but not when a specific property change should be ignored.
b

billowy-army-68599

03/20/2023, 4:25 PM
@cuddly-magician-97620 it does have the equivalent
c

cuddly-magician-97620

03/20/2023, 4:31 PM
Great, then that's probably the right solution. 🙂
r

rhythmic-rainbow-38499

03/20/2023, 4:32 PM
@billowy-army-68599 Do you have a reference on how that works?
r

rhythmic-rainbow-38499

03/20/2023, 4:51 PM
Excellent, thanks!