This message was deleted.
# automation-api
s
This message was deleted.
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)
    });