https://pulumi.com logo
#getting-started
Title
# getting-started
i

incalculable-thailand-44404

04/12/2022, 5:56 PM
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

bland-continent-32037

04/12/2022, 6:06 PM
You are probably looking for pulumi.apply() https://www.pulumi.com/docs/intro/concepts/inputs-outputs/#apply
šŸ‘ 1
ā˜ļø 1
b

billowy-army-68599

04/12/2022, 6:08 PM
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

incalculable-thailand-44404

04/12/2022, 6:13 PM
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

billowy-army-68599

04/12/2022, 6:37 PM
@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

incalculable-thailand-44404

04/12/2022, 6:42 PM
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

billowy-army-68599

04/12/2022, 6:44 PM
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

incalculable-thailand-44404

04/12/2022, 6:46 PM
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

billowy-army-68599

04/12/2022, 6:51 PM
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

incalculable-thailand-44404

04/12/2022, 6:56 PM
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

billowy-army-68599

04/12/2022, 7:01 PM
yes, basically. you should use the desired state mechanism wherever possible and define the image in code, your life will be easier
i

incalculable-thailand-44404

04/12/2022, 7:05 PM
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

bland-continent-32037

04/14/2022, 7:16 PM
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

incalculable-thailand-44404

04/25/2022, 12:50 AM
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

bland-continent-32037

04/25/2022, 12:51 AM
Nice! Glad you got it working!
5 Views