Hey folks. Running into a problem updating an Imag...
# aws
w
Hey folks. Running into a problem updating an ImageBuilder Recipe. I want to change which components a recipe is built with and update the version number. This can be accomplished through the console, but pulumi reports the following error:
Duplicate resource URN 'urn:pulumi:amis::amis::aws:imagebuilder/imageRecipe:ImageRecipe::asdf'; try giving it a unique name
. Any recommendations?
p
Are you creating the recipes in some sort of loop?
Duplicate resource URN
makes me think you’re doing something like
new aws.imagebuilder.Recipe('asdf', {...});
multiple times in your code somehow.
l
It's also a problem with the AWS SDK, because recipes are versioned but without a separate version object. It can be tricky to figure it out. I gave up and replaced previous versions with subsequent versions.. there's no permanent record.
Because the recipe ID does not account for the version and there's a separate recipe object for each version of the same recipe, it might not be possible to solve this with just Pulumi code. You might need to break out to using the SDK if you want to maintain old versions the way AWS seems to thing you should.
w
I think I came up with a solution that works. The name of the pulumi object != the name of the aws resource, so I did this:
Copy code
function Recipe({ name, version, components }: RecipeArgs): ImageRecipe {
  return new ImageRecipe(name + version, { name, components, ...otherStuff });
}
Kind of obvious, in retrospect, but I'm still learning pulumi.
then, it seems like you can maintain both like so: ``````
Copy code
const recipe1 = Recipe({
  name: "asdf",
  version: "0.0.1",
  components: []
});

const recipe2 = Recipe({
  name: "asdf",
  version: "0.0.2",
  components: [ SomeComponent ]
});
For my situation, I actually don't want to maintain both as a default, so simply bumping the version and add components works for me.
l
When you view this in AWS console, to you have 1 image with 2 versions?
That would be good.. I'd change my code to follow this pattern. The important bit is to provide the name field (which I never do, except in cases like this where it enables an important feature).
Though we would need to add more and more code, else Pulumi will remove the old versions, right? If you bump the version, then you're creating a new Pulumi resource and deleting the old one (since the resource with that Pulumi name (= "name"+"version")) is no longer in code.
w
I'll check and get back to you
I get two images with different versions under the same name. I did this by running the pipeline with recipe 0.0.1, then updating the pipeline with recipe 0.0.2 and running it again.
If you wanted to construct the images in pulumi, then you would probably need to keep the image instances for previous versions around until you wanted to delete them.