I need to use some pulumi outputs in an ECS task d...
# aws
c
I need to use some pulumi outputs in an ECS task definition. If I reference them directly in the JSON I get the usual error about calling toJSON on an Output. I have fixed it by doing this but it seems really unwieldy, especially if you need more than one Output. Is there some simple solution I am missing?
Copy code
const ecsTaskDefinition = new aws.ecs.TaskDefinition(`${cfg.name}-msk-streams-task`, {
  family: `${cfg.name}-msk-streams-task`,
  cpu: "2048",
  memory: "4096",
  networkMode: "awsvpc",
  requiresCompatibilities: ["FARGATE"],
  executionRoleArn: ecsTaskExecutionRole.arn, // These are fine
  taskRoleArn: taskRole.arn, // These are fine
  // This doesn't recognize that pulumi needs to pass in the mskCluster.bootstrapBrokersSaslIam because it's buried in the JSON.stringify
  // instead of being a direct input to the new.
  // This works but is not ideal. Two nested applies makes it unappealing to say the least
  containerDefinitions: mskCluster.bootstrapBrokersSaslIam.apply(bootstrapServers => {
    return mskStreamsImage.ref.apply(mskStreamsImageRef => {
      return JSON.stringify([{
        name: ecsContainerName,
        image: mskStreamsImageRef,
        essential: true,
        portMappings: [
            { containerPort: 8080, hostPort: 8080, protocol: "tcp" },
            { containerPort: 9098, hostPort: 9098, protocol: "tcp" },
            { containerPort: 9092, hostPort: 9092, protocol: "tcp" },
        ],
        environment: [
            { name: "KAFKA_BOOTSTRAP_SERVERS", value: bootstrapServers },
        ],
        logConfiguration: {
            logDriver: "awslogs",
            options: {
                "awslogs-group": logGroupName,
                "awslogs-region": "eu-west-1",
                "awslogs-stream-prefix": "ecs",
            },
        },
      }])
    })
  }
),
}, { dependsOn: [mskCluster] });
q
You could use
pulumi.jsonStringify({})
, this is essentially a version of
JSON.stringify
that can handle outputs
c
ahhhh ok
q
c
thanks
l
You can also wait for multiple vars to resolve with
pulumi.all()
, eg
Copy code
containerDefinitions: pulumi.all([mskCluster.bootstrapBrokersSaslIam, mskStreamsImage.ref]).apply(([bootstrapBrokersSaslIam, mskStreamsImageRef]) => {
  return ...
})
c
thanks