I’m using Pulumi with AWS and pulumi usually adds ...
# general
e
I’m using Pulumi with AWS and pulumi usually adds a suffix to resources it deploys, but in the case of
aws.batch.ComputeEnvironment
, I have to specify
computeEnvironmentName
and that exact name is used to deploy the resource. If I make any changes to the CE, I have to go in and change the name to avoid a conflict. Is there a way to get the suffix that Pulumi normally adds to resources so I don’t have to change the name every time I want to update an AWS Batch Compute Environment?
g
You can use the Random package to get a stable random string that you could use as a suffix. https://www.pulumi.com/docs/reference/pkg/nodejs/pulumi/random/#RandomString
e
thanks! I’ll try this out in the morning.
Whenever I declare
Copy code
const id = new random.RandomId("id", {byteLength: 8});
I always get
Copy code
error: Duplicate resource URN 'urn:pulumi:dev::folding-foundation::random:index/randomId:RandomId::id'; try giving it a unique name
if I rename it and try to deploy, I get the same error. I haven’t tried using the generated id in any of the resources yet.
it doesn’t seem to matter what the name is, and I’m only making this one call to the
random
package.
for instance
Copy code
const idasdf = new random.RandomId("id-asdf", {byteLength: 8});

    error: Duplicate resource URN 'urn:pulumi:dev::folding-foundation::random:index/randomId:RandomId::id-asdf'; try giving it a unique name
I figured it out. I forgot that I’m using multiple providers so the id was being used multiple times.
👍 1
doh! I hadn’t noticed
computeEnvironmentNamePrefix
. It’s unfortunate that you can’t set the length of the id to generate, but this does what I need.
g
You can set the length of
RandomString
, but
computeEnvironmentNamePrefix
is likely easier in the long run.
e
yep. Agreed