Hi, :wave: I'm fairly new to Pulumi and I would li...
# automation-api
w
Hi, 👋 I'm fairly new to Pulumi and I would like to receive guidance about the Automation API used inside a Typescript-based REST API. I would like to give my users the ability to create an empty Buckey in Google Cloud simply by sending a POST request. The desired bucket would be stored inside a stack named after the user's name. The issue I'm facing comes only once the user asks for another bucket in the same stack create beforehand. In this scenario, the first bucket would simply be deleted and the second one would replace the first one. This behavior is probably caused by Pulumi not being able to locate the code related to the first bucket during the second bucket creation request. I've based my work on the Automation REST API example, but they don't exactly fit my scenario, unfortunately. Is there anything I can do to avoid the destruction of the previously requested resource while deploying with the UP method? Thank you for your concern. 🙂
b
It sounds like you’re not storing the state somewhere that it can be retrieved on subsequent http requests. What Pulumi backend are you using?
w
I'm storing my backend in a local folder for testing using the Pulumi login file:// command. I've also called the LocalWorkspace.createOrSelectStack method to retrieve it.
b
How are you setting the backend in automation API? environment variable? project settings?
w
My backend is stored in a local file in a dedicated folder, and my users are making requests to access a stack name after them. Each time I receive an API call, I ask Pulumi to create or select a stack depending if there is one prior to the request.
b
Yes I get that much - but how are you telling the automation api where that backend is located?
w
I tried using the PULUMI_BACKEND_URL environment variable to specify the path to my local backend directory. Every time I do so, I receive an error message asking me to set the PULUMI_ACCESS_TOKEN even if I'm using a local backend.
b
yea the only way I have gotten it to work is by setting the backend url in the project settings file. https://www.pulumi.com/docs/reference/pulumi-yaml/ look at the
backend
option
w
Thank you, this option did the trick to fix the backend, but I'm still facing the same issue with my API unfortunately.
b
meaning everytime it is destroying and recreating the bucket?
w
Yes ... I found a dirt workaround by setting the protected value each time a new resource is created. The drawback of this technique is that I need to remove it before proceeding to any deletion. I didn't found any information about the possibility to unset this value programmatically, however.
b
If it is recreating the bucket everytime than there are a couple possibilities - either the state isn't working and it is not recognizing that the stack/bucket already exists, or the
s3.Bucket
is being given a different name each time your pulumi program executes
can you share any code from your pulumi program?
w
Sure! Here's the simplest example of the code I'm trying to run: https://codesandbox.io/s/musing-butterfly-1cq86?file=/src/index.ts
b
gotcha. so the issue is the second scenario I mentioned. You are potentially giving the Bucket a different name everytime that end point is hit. With this line:
Copy code
const bucket = new gcp.storage.Bucket(content);
look here: https://www.pulumi.com/docs/reference/pkg/gcp/storage/bucket/#create The first argument to create any pulumi resource is the pulumi name. This name is how pulumi tracks resources between calls to
pulumi up
. If you want pulumi to track and update a resource, than the name must be the same on every call to
pulumi up
otherwise pulumi will see it as a different resource and destroy/create
Well pause, sorry. I guess you might be sending the username as
content
? So you're making a request with the same
stackName
and
bucketName
everytime and still seeing create/destroy? If that's the case than scrap what I just said. I will say that I don't see you setting the
backend
property in the sample code as we discussed, that could definitely be an issue. It should be set somewhere in here:
Copy code
const stack = await LocalWorkspace.createOrSelectStack({
      stackName,
      projectName,
      program: createPulumiProgram(content)
    });