sparse-intern-71089
06/30/2021, 4:37 PMred-match-15116
06/30/2021, 4:47 PMjson.dumps
should be within the apply
cfg = pulumi.Config()
ssm.Parameter(
f"{prefix}-app-dn-credentials",
name=f"/{prefix}",
value=cfg.require_secret('secret').apply(lambda x: json.dumps({"user": "user", "password": x}))
)
great-sunset-355
06/30/2021, 5:10 PMgreat-sunset-355
06/30/2021, 5:11 PMgreat-sunset-355
06/30/2021, 5:15 PManother_secret
great-sunset-355
06/30/2021, 5:19 PM{"user": "user", "password": x, "another": another_secret}
bored-activity-40468
06/30/2021, 5:21 PMbored-activity-40468
06/30/2021, 5:22 PMgreat-sunset-355
06/30/2021, 5:36 PMgreat-sunset-355
06/30/2021, 5:37 PMred-match-15116
06/30/2021, 5:46 PMmy_dict = {"user": "user", "password": x, "another": another_secret}
Output.all(**my_dict).apply(lambda args: json.dumps(args))
great-sunset-355
06/30/2021, 6:04 PMenough-leather-70274
07/01/2021, 12:59 AMgreat-sunset-355
07/01/2021, 10:53 AMgreat-sunset-355
07/01/2021, 10:53 AMgreat-sunset-355
07/01/2021, 11:27 AMambitious-father-68746
07/01/2021, 2:22 PMpulumi stack output
?ambitious-father-68746
07/01/2021, 2:26 PMambitious-father-68746
07/01/2021, 2:29 PMapply()
can be used as strings. That's it.great-sunset-355
07/01/2021, 2:51 PMgreat-sunset-355
07/01/2021, 2:52 PM.pulumi/bin/pulumi-language-python-exec", line 92, in <module>
I'm unable to debug the code at allbillowy-army-68599
great-sunset-355
07/01/2021, 3:38 PMol-infrastructure
but I could not find enough with outputs.
I'm trying to create a container_definitions
https://www.pulumi.com/docs/reference/pkg/aws/ecs/taskdefinition/#example-using-container_definitions-and-inference_accelerator
using json.dumps
app_env_vars = {
"EMAIL_HOST_USER": ses_user_access_key.id,
"EMAIL_HOST_PASSWORD": ses_user_access_key.ses_smtp_password_v4,
"a": "b",
}
# container_name = container_name
container_definition = {
"name": container_name, # is output Config.require
"image": image_name, # just str
"portMappings": [{"containerPort": 80, "hostPort": 80, "protocol": "tcp"}],
"environment": [{"name": k, "value": v} for k, v in app_env_vars.items()],
}
expected_result = container_definition.apply(json.dumps)
red-match-15116
07/01/2021, 3:47 PMapply
. So for your code, I think something like the following should work:
app_env_vars_dict = {
"EMAIL_HOST_USER": ses_user_access_key.id,
"EMAIL_HOST_PASSWORD": ses_user_access_key.ses_smtp_password_v4,
"a": "b",
}
app_env_vars = Output.all(**app_env_vars_dict).apply(args: [{"name": k, "value": v} for k, v in args.items()])
container_definition = {
"name": container_name,
"image": image_name,
"portMappings": [{"containerPort": 80, "hostPort": 80, "protocol": "tcp"}],
"environment": app_env_vars,
}
expected_result = Output.all(**container_definition).apply(json.dumps)
Note that you have multiple outputs that you are trying to convert to json. Output.all accepts keyword args, so when you do **container_definition
it spreads the keys/values as keyword args.red-match-15116
07/01/2021, 5:07 PMbillowy-army-68599
great-sunset-355
07/01/2021, 7:03 PMgreat-sunset-355
07/01/2021, 7:38 PMbillowy-army-68599
great-sunset-355
07/08/2021, 6:43 AMjson.dump
could handle the outputs?billowy-army-68599
great-sunset-355
07/09/2021, 8:00 AMbillowy-army-68599
red-match-15116
07/09/2021, 4:01 PMAre there any examples of creating a custom output so I could play with this without calling real resources?You can use
Output.from_input()
as described in https://www.pulumi.com/docs/intro/concepts/inputs-outputs/#convert-input-to-output-through-interpolationgreat-sunset-355
07/13/2021, 6:40 PMOutput.from_input()
I found out that it can also take the Output or anything else.
Also reviewing the ECS Task docs one more time.
It turned that ContainerDefinitions
is not a JSON object but JSON array of objects!
from there I made this code:
That yields into the desired structure!
container_definition = {
"name": config.container_name, # is output Config.require
"image": config.image_name, # just str
"portMappings": [{"containerPort": 80, "hostPort": 80, "protocol": "tcp"}],
"environment": [{"name": k, "value": v} for k, v in config.env_vars.items()], # config.env_vars is Dict[str,Any]
}
container_definitions = Output.from_input([container_definition]).apply(json.dumps) # List[Dict[str,str]]
Thank you so much for baring with me, in case you'd like to have this in docs or any examples, let me know and I can put something more informative together. Because I believe others will find this helpful.