https://pulumi.com logo
c

cold-piano-21918

03/01/2019, 10:26 PM
Possibly a stupid question, but how to I get the
repositoryUrl
of a ECR repo as a string so I can update my task definition (which takes
containerDefinitions
as a string)?
I tried using
.get()
but it throws an error
Cannot call '.get' during update or preview
w

white-balloon-205

03/01/2019, 10:33 PM
You need to use
apply
for this - as in:
Copy code
containerDefintiions: x.repositoryUrl.apply(repositoryUrl => JSON.stringify({ ... repositoryUrl ... }))
See https://pulumi.io/reference/programming-model.html#apply for some more notes related to this.
c

cold-piano-21918

03/01/2019, 10:33 PM
I saw that but
.apply
returns another output object
I just want the value as a string
w

white-balloon-205

03/01/2019, 10:34 PM
Right - but you can pass an
Output
as an
Input
to any resource - in particular as the
containerDefinitions
.
c

cold-piano-21918

03/01/2019, 10:34 PM
yes but i'm loading containerDefinitions from a json file
and I have to stringify it
code
Copy code
let content = fs.readFileSync("task-definition.json");
const repo = new aws.ecr.Repository('flexkeygen', {});
const taskDefinition = new aws.ecs.TaskDefinition('flexkeygen_test', {
    containerDefinitions: JSON.stringify(taskDefinitionJson.taskDefinition.containerDefinitions),
    ...
w

white-balloon-205

03/01/2019, 10:36 PM
I might have to see more of your code to make a concrete suggestion. As noted in the docs, you can't turn an
Output<string>
into a
string
- but you can do all the work needed to transofmr that output into the value that you need as n input inside an
apply
.
c

cold-piano-21918

03/01/2019, 10:36 PM
From the docs,
containerDefinitions
is a string
So I have my taskdefinition stored as a json file- i'd like to set the
image
registry URL with the ECR registryUrl, is that not possible to do?
w

white-balloon-205

03/01/2019, 10:39 PM
Which means you can pass a
string
or an
Output<string>
.
c

cold-piano-21918

03/01/2019, 10:40 PM
so theres no way to template it from a JSON file, I have to build the object?
w

white-balloon-205

03/01/2019, 10:41 PM
How were you going to template it from a file? You should be able to do all the same things - you just have to do them inside of an
apply
?
c

cold-piano-21918

03/01/2019, 10:42 PM
I exported the JSON definition with the
aws ecs describe-task-definition --task-definition flexkeygen_webapp:6 > task-definition.json
I want to reuse it for all accountIDs by replacing the registryUrl which changes based on AWS account ID
w

white-balloon-205

03/01/2019, 10:45 PM
Copy code
let taskDefinitionJson = JSON.parse(fs.readFileSync("task-definition.json").toString());
const repo = new aws.ecr.Repository('flexkeygen', {});
const taskDefinition = new aws.ecs.TaskDefinition('flexkeygen_test', {
    containerDefinitions: repo.rpositoryUrl.apply(repositoryUrl => {
        taskDefinitionJson.taskDefinition.containerDefinitions.something = repositoryUrl;
        return JSON.stringify(taskDefinitionJson.taskDefinition.containerDefinitions);
    }),
});
c

cold-piano-21918

03/01/2019, 10:47 PM
oh i see, that makes sense
thanks! i guess will have to deal with not being able to get values as strings - thanks for the clarification
3 Views