Skip to content
This repository was archived by the owner on Nov 19, 2025. It is now read-only.
This repository was archived by the owner on Nov 19, 2025. It is now read-only.

Feat. Request: Allow environment variables to depend on CF intrinsic functions #1140

Open

Description

@kazkansouh

Context

When trying to reference items generated in the CloudForamtion script its often useful to pass the ARN to a docker container as an environment variable.

However, currently its not possible to directly use the CloudFormation intrinsic functions (e.g. !Ref) within the service definition. E.g.

services:
  server:
    image: someimage
    environment:
      TESTX:
        Fn::GetAtt: [ x, y ]

There are often times this could be useful, e.g. accessing the CloudMap object.

Alternatives

A workaround to this is really inconvenient as it relies on using the Resources block to overwrite the majority of the task definition. For example, consider the below excerpt of a simple task definition obtained with docker compose convert. I would need to completely overwrite the whole of the ContainerDefinitions list, just to modify the environment variable defined within it.

  ServerTaskDefinition:
    Properties:
      ContainerDefinitions:
      - Command:
        - eu-west-1.compute.internal
        - simple-server.local
        Essential: false
        Image: docker/ecs-searchdomain-sidecar:1.0
        LogConfiguration:
          LogDriver: awslogs
          Options:
            awslogs-group:
              Ref: LogGroup
            awslogs-region:
              Ref: AWS::Region
            awslogs-stream-prefix: simple-server
        Name: Server1_ResolvConf_InitContainer
      - DependsOn:
        - Condition: SUCCESS
          ContainerName: Server1_ResolvConf_InitContainer
        Environment:
        - Name: TESTX
          Value: testx
        Essential: true
        Image: someimage
        LinuxParameters: {}
        LogConfiguration:
          LogDriver: awslogs
          Options:
            awslogs-group:
              Ref: LogGroup
            awslogs-region:
              Ref: AWS::Region
            awslogs-stream-prefix: simple-server
        Name: server
        PortMappings:
        - ContainerPort: 80
          HostPort: 80
          Protocol: tcp
      Cpu: "256"
      ExecutionRoleArn:
        Ref: ServerTaskExecutionRole
      Family: simple-server-server
      Memory: "512"
      NetworkMode: awsvpc
      RequiresCompatibilities:
      - FARGATE
    Type: AWS::ECS::TaskDefinition

I assume allowing intrinsic functions in the service definition would be considered bad as it would prevent it being used outside of ECS. Perhaps the best is to support a way to merge changes into the ContainerDefinitions list. For example:

services:
  server:
    image: someimage
    environment:
      TESTX: testx

x-aws-cloudformation:
  Resources:
    ServerTaskDefinition:
      Properties:
        ContainerDefinitions:
          -
          - Environment:
              - Name: TESTX
                 Value: 
                   Fn::GetAtt: [ x, y ]

Currently, the above definition will be non-functional as the ContainerDefinitions will be corrupted.

Additional context

$ docker compose version
Docker Compose version 1.0.17
  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions