Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks
kazkansouh opened this issue Jan 11, 2022 · 0 comments
Open
2 tasks

Comments

@kazkansouh
Copy link

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
Projects
None yet
Development

No branches or pull requests

1 participant