Originally I posted the question in <#CDE799L1M|py...
# getting-started
b
Originally I posted the question in #python, but loop behaviour probably apply for any language. Hi there! Could you guys please help me to understand why apply from the Output does not work as expected inside a loop?
Copy code
def container_definition(image_name, service, env_variables):
    print("service:",service)
    print("env_vars:", env_variables)
    return json.dumps([{
        'name': 'server',
        'image': image_name,
        'networkMode': 'awsvpc',
        'readonlyRootFilesystem': False,
        'essential': True,
        'environment': env_variables,
        ..... Non relevant code continues
    }])

for service in config.common_config['services']:
    env_variables.append({'name': 'SERVICES', 'value': service})
    if service != 'frontend':
        env_variables.append({'name': 'TEMPORAL_CLI_ADDRESS',
            'value': f'{config.common_config["frontend"]["service_name"]}.{config.common_config["dns_namespace"]}'})
    task_definitions[service] = aws.ecs.TaskDefinition(config.common_config[service]['service_name'],
        family=config.common_config[service]['service_name'],
        cpu=config.common_config[service]['cpu'],
        memory=config.common_config[service]['memory'],
        network_mode='awsvpc',
        requires_compatibilities=['FARGATE'],
        execution_role_arn=ecs_task_role.arn,
        task_role_arn=ecs_task_role.arn,
        container_definitions=image.image_name.apply(
            lambda image_name: container_definition(image_name, service, env_variables)),
        tags={
            "Service": "temporal",
        },
        opts=ResourceOptions(depends_on=[log_group]))
When it is executed for the container_definitions in preview I am seeing env_variables with duplicates and 
service
 is set to the latest in the list of 
config.common_config['services']
 . I do believe it is somehow related to the nature of "Promised" Output, but not an expert in Python enough to catch and fix it. TIA! Everything worked properly in the loop until I needed to add image name for ECR 😄
b
a preview isn't guaranteed to be accurate with an output like this, are you sure it's creating incorrectly?
b
yes, the deployed resources contains wrong variables
nvm! typical python mistake with the list append in place 🤦‍♂️
actually no, partially solved.. no more duplicates but needed values are set to the latest list member