Hi, I need a help in updating the service discover...
# general
b
Hi, I need a help in updating the service discovery instance's custom attribute. I have created a service discovery in aws via pulumi let it be service A, and it holds only one instance, in that I have added a custom attribute. Now I'm creating a new service B when creating the service B I need to update the service A's custom attribute with the value got from service B. Any help would be greatly appreciated.
e
Oh circular updates are hard! We had a blog post about this a while ago which discussed some hacks you can do now, and also some proposals for how we could support this properly (tracked at https://github.com/pulumi/pulumi/issues/3021)
b
@echoing-dinner-19531 I don't have circular dependency issue, When I try to update the existing service it returns error "service with same name exists". If I delete that my problem will be solved. But I don't want to delete a service for just updating the custom attribute, Is there any way to update the attribute without deleting the existing service?
e
You create A, then create B, then update A. That's a circular dependency?
b
A was created 5 days ago, now I'm creating B while creating B the urn I got from B has to be updated in A this is my case now
not creating both at the same time
e
A and B are both being managed by the same pulumi program?
b
no A will be created in a separate one and B will be created in separate one
e
So you have program 1 created A. Program 2 has now created B. Now you want to update program 1 with a new attribute that references a value from B but that's triggering an error "service with same name exists"?
b
Yes
e
What does "pulumi preview" show for the change in program 1?
b
I'm now updating the service A from service B from program 2
e
ah right you can't do that
resources can only be managed by one program, trying to have separate stacks manage the same resource can be done but is a source of much error and confusion
b
deleting and recreating is the only way then?
e
no, you can import the existing resource into the state for program 2, and then update it. But the two stacks need to be manually synchronised. If you run program 1 again without having updated the attribute list for it then it will just overwrite the resource with it's attribute list.
b
Can you tell me how to do this "you can import the existing resource into the state for program 2, and then update it"?
any reference links for this
e
We've got some guides for this at https://www.pulumi.com/docs/guides/adopting/import/
You can either use the
pulumi import
command, or use the
import
resource option.
importing will add the existing resource to the stack so that pulumi understands it's current state and can do an update rather than a create.
b
Thanks a lot.
@echoing-dinner-19531 One more thing, I have imported the resource to my stack 2 and now I'm able to update it, when I try to get the existing resource from stack 1 and try to update the first stack with the value got from get() it results awsservicediscoveryInstance Service_Instance replace [diff: -attributes,instanceId,serviceId] and failed with "*panic: fatal: An assertion has failed*" If I remove, getting instance and updating the value which was updated by stack 2 I'm getting result but the updated value is removed. Got confused what happening now
In stack 1 instead of updating why it is trying to replace ? The stack already has this service instance, then it must update it right?
e
If instanceId or serviceId change the Instance needs to be replaced. So you need to ensure both programs are setting the same values for those. Also make sure you run
pulumi refresh
on the first stack after making changes in the second stack so that pulumi's state tracking can be updated with what's changed.
b
This helped 🙂 Thanks a lott @echoing-dinner-19531