ebextensions conditional statement in .config file for Elastic Beanstalk deployment

170 views Asked by At

Elastic Beanstalk deployment with .ebextensions.

I am switching from Classical Load Balancer to an Application Load Balancer

I want to use the same code in nonProd and prod for AWS ElasticBeanstalk deployment.

This works and does what I want it to do for nonProd only since the sg-nonPRODXXX is hardcoded:

option_settings:
   aws:elbv2:listener:443:
    ListenerEnabled: 'true'
    Protocol: HTTPS
    SSLCertificateArns:  arn:aws:acm:us-east-1:xxxx
    SSLPolicy: ELBSecurityPolicy-TLS-1-2-Ext-2018-06
  aws:elbv2:loadbalancer:
    ManagedSecurityGroup: "sg-nonPRODXXX"
    SecurityGroups: "sg-nonPRODXXX"

Conceptually I want this

 option_settings:
  aws:elasticbeanstalk:application:environment:
    ENV_NAME: '`{ "Ref" : "AWSEBEnvironmentName" }`'  
    if ENV_NAME = 'PROD_namexxxx"
      SG_NAME = 'sg_Prodxxx"
    else
      SG_NAME = "sg-nonPRODXXX"
    end if
  aws:elbv2:listener:443:
    ListenerEnabled: 'true'
    Protocol: HTTPS
    SSLCertificateArns:  arn:aws:acm:us-east-1:xxxx
    SSLPolicy: ELBSecurityPolicy-TLS-1-2-Ext-2018-06
  aws:elbv2:loadbalancer:
    ManagedSecurityGroup: $SG_NAME
    SecurityGroups:  $SG_NAME

I can't find scenario on my searches. I see container_commands has conditional statements, but I am not sure how I would do what I want in a container_command.

1

There are 1 answers

1
Marcin On

As you noticed this is not supported. There are many other ways to achieve that. One basic example is to create a text file using container_commands which is going to be populated by text PROD, NON-PROD, and your app will read that file instead of env variabile.