Possibly a stupid question, but how to I get the `...
# general
c
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
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
I saw that but
.apply
returns another output object
I just want the value as a string
w
Right - but you can pass an
Output
as an
Input
to any resource - in particular as the
containerDefinitions
.
c
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
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
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
Which means you can pass a
string
or an
Output<string>
.
c
so theres no way to template it from a JSON file, I have to build the object?
w
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
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
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
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