https://pulumi.com logo
#aws
Title
# aws
a

average-school-38756

02/04/2021, 6:54 PM
Somehow i accidentally removed route table associations from my infrastructure. Was able to re-associate the subnets with the route tables in the AWS console, but now
pulumi refresh
wants to delete them from my state, while
pulumi preview
shows that state matches the code (including import IDs), and isn't trying to create any new ones. Any ideas what's going on here?
l

little-cartoon-10569

02/04/2021, 7:43 PM
Sounds expected. AWS differs from state, so refresh wants to fix that. Code doesn't differ from state, so preview reports no differences.
Your options are 1) to fix AWS first; that will stop refresh from noticing the difference; 2) to not fix AWS at all, run refresh then up, so that Pulumi fixes AWS for you.
The refresh+up option is great when it works, but I find that it often changes values that aren't in your code (that is, puts AWS defaults into state), so now code and state are different. When you run up, changes will happen that effectively do nothing (essentially removing defaults from state). Usually this is fine, but sometimes this causes unwanted updates or delete-replaces. Which can be very bad if it's in RDS, Aurora, Directory Services, etc. So be attentive to the preview before running up!
a

average-school-38756

02/04/2021, 8:26 PM
thank you- what i'm baffled by is that i made the route table associations in AWS console but pulumi isn't recognizing their existence with
pulumi refresh
l

little-cartoon-10569

02/04/2021, 8:29 PM
That's because you haven't imported them yet.
refresh
maps something-in-AWS-with-ID-X to something-in-state-with-ID-X.
But you've got something-in-state-with-ID-X and something-in-AWS-with-ID-Y
You need to use the
import
opt to tell Pulumi that AWS ID Y is the same as Pulumi ID X.
(Whoops, typo back a few lines, fixed it, would have mislead you if you read it before)
a

average-school-38756

02/04/2021, 8:32 PM
this may be the bit i was missing- i'll check into that. thanks!
👍 1
ok since i had the resource IDs defined as options in the code, this is how i fixed it: 1.
pulumi refresh
(and allow the resources to be removed from the state) 2.
pulumi up
which caused the imports to succeed They do indeed have new IDs now.
l

little-cartoon-10569

02/04/2021, 8:44 PM
Yes, that's always the best way, so long as you don't get an unintended update, as described above. Glad it worked!
a

average-school-38756

02/04/2021, 8:46 PM
thanks for your help