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

ambitious-article-39970

07/05/2021, 11:58 AM
hey guys qq trying to deploy ECS fargate and pass it a secret in container definitions
Copy code
```task_definition = aws.ecs.TaskDefinition('pulumi-app-task',
    family='fargate-task-definition',
    cpu='256',
    memory='512',
    network_mode='awsvpc',
   tags = global_tags,
    requires_compatibilities=['FARGATE'],
    execution_role_arn=role.arn,
    container_definitions=json.dumps([{
      'secrets' : json.dumps([{'db_password': f"{db_password.id}"}]),
      'name': 'pulumi-test-app',
      'image': 'nginx',
      'portMappings': [{
         'containerPort': 80,
         'hostPort': 80,
         'protocol': 'tcp'
      }]
   }])
)
having issues with this line  'secrets' : json.dumps([{'db_password': f"{db_password.id}"}]),
I assume this is because its returning an aws ARN im getting an unmarshelled string error converting to json. is this the case?
rror: aws:ecs/taskDefinition:TaskDefinition resource 'pulumi-app-task' has a problem: ECS Task Definition container_definitions is invalid: Error decoding JSON: json: cannot unmarshal string into Go struct field ContainerDefinition.Secrets of type []*ecs.Secret. Examine values at 'TaskDefinition.ContainerDefinitions'.
im new to pulumi and havent quite figured out how to use a debugger with it yet so havning to guess alot at what values which come back look like. (I know the second json dumps isnt needed but there for debugging)
b

billowy-army-68599

07/05/2021, 3:22 PM
@ambitious-article-39970 you can't pass an output (ie the result of provisioning another resource) into a container definition because container definitions only take strings I would first read this: https://www.leebriggs.co.uk/blog/2021/05/09/pulumi-apply.html Then update your code to look like this: https://github.com/pulumi/examples/blob/258d3bad0a00020704743e37911c51be63c06bb4/aws-py-voting-app/__main__.py#L162
a

ambitious-article-39970

07/05/2021, 3:32 PM
thanks I still seem to have issues when using apply to pull the string out of the output though
g

great-sunset-355

07/08/2021, 5:25 AM
another soul bitten by Outputs. I'm doing fargate as well - you can find a lot of my discussions above. The solution to construct more complex JSON objects is use
Output.all
for each level of the structure that contains outputs + you cannot use
json.dumps(json.dumps())
the inner JSON will produce escaped json string which is what you do not want
I will try to produce a good example in few days, when I'm back
@ambitious-article-39970 look at my post above I found a very simple solution
2 Views