https://pulumi.com logo
#python
Title
# python
s

square-dress-80180

03/24/2021, 10:19 PM
Hi - would really appreciate some insight into the following:
Copy code
db_user = os.environ['DB_USER']

# Create Output[Mapping] for use with args[Input[Mapping[str,str]]]
gatheredDBOutput = pulumi.Output.all(
    db_host_address, 
    db_host_port, 
    db_name
)

def createBuildArgs(host_address, host_port, name, user):
    return json.dumps({
        "db_host_address": host_address,
        "db_host_port": host_port,
        "db_name": name,
        "db_user": user,
    })

buildArgs = gatheredDBOutput.apply(lambda args: 
    createBuildArgs(args[0], args[1], args[2], db_user)
)

flask_image = docker.Image("flask-dockerimage",
    image_name=app_ecr_repo_repository_url,
    build=docker.DockerBuild(
        context="./frontend",
        args=buildArgs
    ),
    skip_push=False,
    registry=app_registry
)
r

red-match-15116

03/24/2021, 11:53 PM
Hey! You should just be able to pass in a dict to
args
Have you tried this?
Copy code
flask_image = docker.Image("flask-dockerimage",
    image_name=app_ecr_repo_repository_url,
    build=docker.DockerBuild(
        context="./frontend",
        args={
            "db_host_address": db_host_address,
            "db_host_port": db_host_port,
            "db_name": db_name,
            "db_user": db_user,
        }
    ),
    skip_push=False,
    registry=app_registry
)
s

square-dress-80180

03/25/2021, 2:27 AM
Hi @red-match-15116 - thanks for your help! It turned out I had to do the work of creating the docker.Image within the
apply
statement in order to get things to work. It wasn’t accepting the Outputs within the dict directly.
r

red-match-15116

03/25/2021, 2:43 AM
It’s not recommended to create resources within an
apply
- because of the unexpected behavior related to
preview
and the resource graph not being calculated correctly. There’s generally a way to refactor the code so that creating the resource within an apply is not necessary.