Hi Folks, I am new to Pulumi, I am trying to under...
# getting-started
i
Hi Folks, I am new to Pulumi, I am trying to understand how to extract actual value out of a Pulumi Output<>. this is my usecase :
Copy code
const repository = new aws.ecr.Repository(".......");

const serviceImage = pulumi.output(aws.ecr.getImage({
  imageTag: "latest",
  repositoryName: ... NEED TO SPECIFY THE ACTUAL STRING REPO NAME...,
}));
repository.name
is of the form :
pulumi.Output<String>
which is why I cannot use it as is.
b
You are probably looking for pulumi.apply() https://www.pulumi.com/docs/intro/concepts/inputs-outputs/#apply
šŸ‘ 1
ā˜ļø 1
b
what Kat said, you can't "extract" the value of an output, you have to wait for it to resolve. this explains it in other words: https://www.leebriggs.co.uk/blog/2021/05/09/pulumi-apply.html
šŸ™ 1
you need to do the
getImage
call inside the
apply()
However in your case, why are you running
getImage
? have you pushed an image to the repo?
i
yes, I wanted to write the logic to see if an image exist under the repo and if not, error out... if it does then take certain action...
IIUC, this would be the correct way to deal with this :
Copy code
repository.name.apply(repoName => {
  const serviceImage = pulumi.output(aws.ecr.getImage({
    imageTag: "...",
    repositoryName: repoName,
  }));

  serviceImage.id.apply(id => console.log(`image ID : ${id}`))
})
b
@incalculable-thailand-44404 yes, that'd work, but really that's not the way Pulumi is really designed to operate
Pulumi drives towards a desired state, so if you declare the image in your code, it'll get created.
getImage
is designed to retrieve images that might be created outside pulumi. you should really define your image in your code and let Pulumi handle it
i
yea, currently I am using a docker client to push the image to ECR, out of band from Pulumi. IIUC, you are recommending I let pulumi create the docker image and push it ECR.
b
well, if you're creating the image out of band from Pulumi, but creating the repository from Pulumi, you're joining two actions, one of which is imperative. It'll cause you issues down the line, I feel. unless you seperate the image creation project from the one retrieving the project
šŸ‘ 1
i
I have been following this : https://www.pulumi.com/docs/guides/crosswalk/aws/ecr/#building-and-publishing-container-images. What I intend to do is create the repo if it's not present. If its present check if the image is present. If its present and the tag is what I expect, then move forward with pulling that into eks...
b
those are all imperative actions, the logic should really be: ā€¢ define the code to create the repo ā€¢ define the code to create the docker image ā€¢ let Pulumi's desired state configuration handle the checling if something is present or not
i
you mean if the docker image is not present Pulumi will fail the eks deployment and it should be the right thing to do. sorry for dumb questions, still ramping up
b
yes, basically. you should use the desired state mechanism wherever possible and define the image in code, your life will be easier
i
got it
Do we need to have the dockerfile/project in Pulumi repo, always? I have a bazel project that has a docker file. This is separate from Pulumi repo.. I have been trying to create the docker image but its erroring out.
b
The Dockerfile needs to be accessible programmatically. Can you show me the error you're seeing and what your code to attempt to access the Dockerfile looks like?
i
hey sorry, for the delay reply @bland-continent-32037, I was able to provide the local path to the docker file to Pulumi and it was able to build and deploy the docker image to ECR.
b
Nice! Glad you got it working!