Thread
#getting-started
    i

    incalculable-thailand-44404

    5 months ago
    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 :
    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

    5 months ago
    b

    billowy-army-68599

    5 months ago
    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
    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

    5 months ago
    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 :
    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

    5 months ago
    @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

    5 months ago
    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

    5 months ago
    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
    i

    incalculable-thailand-44404

    5 months ago
    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

    5 months ago
    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

    5 months ago
    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

    5 months ago
    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

    5 months ago
    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

    5 months ago
    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

    5 months ago
    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

    5 months ago
    Nice! Glad you got it working!