Hi All I'm having issues with my pulumi. I'm work...
# python
a
Hi All I'm having issues with my pulumi. I'm working on setting up a webserver on ecs with access to rds database but I'm getting the
error: awsx:ecs:FargateTaskDefinition resource 'server-test' has a problem: Cannot read properties of undefined (reading 'map')
This is my code
Copy code
def create_task_definition(
    self,
    task_execution_role: aws.iam.Role,
    repo: awsx.ecr.Repository,
    database: aws.rds.Instance,
):
    server_task_definition = awsx.ecs.FargateTaskDefinition(
        f"server-test",
        container=pulumi.Output.all(
            repo_url=repo.url,
            database_name=database.db_name,
            database_password=database.password,
            database_address=database.address,
            database_username=database.username,
            database_port=database.port,
        ).apply(
            lambda args: TaskDefinitionContainerDefinitionArgs(
                name=f"server-test",
                image=args["repo_url"] + ":latest",
                memory=SERVER_MEMORY,
                cpu=SERVER_CPU,
                environment=[
                    {"name": "RDS_DB_NAME", "value": args["database_name"]},
                    {"name": "RDS_PASSWORD", "value": args["database_password"]},
                    {"name": "RDS_HOSTNAME", "value": args["database_address"]},
                    {"name": "RDS_USERNAME", "value": args["database_username"]},
                    {"name": "RDS_PORT", "value": args["database_port"]},
                ],
            )
        ),
        task_role={"role_arn": task_execution_role.arn.apply(lambda x: x)},
    )

    pulumi.export("server_task_definition", server_task_definition)
    return server_task_definition
The error seems to be from the underlying javascript implementation but I haven't been able to tell what attributes are undefined Has anyone faced this issue before and suggest a solution?
m
I think you can greatly simplify your code, which should make it easier to debug:
Copy code
def create_task_definition(
    self,
    task_execution_role: aws.iam.Role,
    repo: awsx.ecr.Repository,
    database: aws.rds.Instance,
):
    server_task_definition = awsx.ecs.FargateTaskDefinition(
        "server-test",
        container=awsx.ecs.TaskDefinitionContainerDefinitionArgs(
                name="server-test",
                image=pulumi.Output.concat(repo.url, ":latest"),
                memory=SERVER_MEMORY,
                cpu=SERVER_CPU,
                environment=[
                    {"name": "RDS_DB_NAME", "value": database.db_name},
                    {"name": "RDS_PASSWORD", "value": database.password},
                    {"name": "RDS_HOSTNAME", "value": database.address},
                    {"name": "RDS_USERNAME", "value": database.username},
                    {"name": "RDS_PORT", "value": adatabase.port},
                ],
            ),
        task_role={"role_arn": task_execution_role.arn},
    )

    pulumi.export("server_task_definition", server_task_definition)
    return server_task_definition
This takes out potential issues with the `apply()`s and might lead to a more specific error message.
a
Thanks, the pulumi.output.all() was swallowing the error. Turns out it was the environment attribute needed to be of type TaskDefinitionKeyValuePairArgs to work. had to put pulumi.output.all() back in so it could get actual strings from the database instance. got it working though. thank very much for your help :)