https://pulumi.com logo
Title
g

green-intern-27665

07/08/2021, 8:38 PM
Hi!!! A newbie over here!! I have an issue with outputs in python. I have all my env vars in a common stack so from any service I can query my common vars which is nice. I want to use those variables in a ECS task but... To define them I have to "unwrap" all my outputs (envars) chaining
apply
calls any idea how to solve this? My goal is to have a key/value array of strings with all my vars
b

billowy-army-68599

07/08/2021, 8:49 PM
you're trying to get outputs into the ecs task string right?
g

green-intern-27665

07/08/2021, 8:54 PM
Yep!!! The json_dunp that explodes when you try to serialise an Output 😅 🤣
b

billowy-army-68599

07/08/2021, 8:57 PM
what have you tried?
g

green-intern-27665

07/08/2021, 8:58 PM
I think that I can solve the problem in that way
The only issue that I see is that I don't have the
enviroment
property like in the example with a fixed structure I have a variable array I need to find a way to unwrap all the outputs inside that array but I guess that I can use another Output.all to construct that array
Let me try!
Thanks!!!!
hey!! your suggestion worked like a charm! now each service picks the neccesary outputs from the common stack an prepare the
env_var
array in this way:
env_vars = Output.all(env_var1, env_var2).apply(
  lambda args: [
      {
        'name': 'TEST_VAR1',
        'value':args[0]
      },
      {
        'name': 'TEST_VAR2',
        'value':args[1]
      }
    ]
)
and this output is passed to the client that generates the ECS task where the env vars are injected in this way:
return Output.all(image=image.image_name, envVars=envVars).apply(
      lambda args: json.dumps([{
        'name': name,
        'image': args['image'],
        'portMappings': [{
          'containerPort': 8080,
          'hostPort': 8080,
          'protocol': 'tcp'
        }],
        'environment': args['envVars']
      }])
    )
Again Thanks for your help!!
b

billowy-army-68599

07/09/2021, 1:03 PM
my pleasure!