AWS Cloudformation: how to refer multiple security groups in AWS elastic beanstalk configuration

1.1k views Asked by At

I am new to AWS Cloudformation world. I am trying to create an elasticbeanstalk configuration template. For it's one of the setting, I need to use two security groups. So, I have given it as following

  MyConfigurationTemplate:
  Type: AWS::ElasticBeanstalk::ConfigurationTemplate
  Properties:
  Properties:
  ApplicationName:  MyApplication
  Description: A default Application
  SolutionStackName: SolutionStack
  OptionSettings:
  ....
  ....
  - Namespace: aws:autoscaling:launchconfiguration
    OptionName: SecurityGroups
    Value:
      !If
        - ConditionIsTrue
        - [!Ref FirstGroup, !ImportValue SecondGroup]
        - !Ref FirstGroup
  ....
  ....

I read from AWS docs here, that SecurityGroups is a list and we can provide comma seprated list. But it is not working for me. AWS throws following error

Value of property Value must be of type String

I tried giving value of security groups in following ways but none of them worked.

1) "!Ref FirstGroup, !ImportValue SecondGroup"

2) !Ref FirstGroup, !ImportValue SecondGroup

Any idea how this list of security groups should be provided?

1

There are 1 answers

0
Pankaj Kolhe On BEST ANSWER

I got it myself with some trial and error. As it accepts comma separated list. We need to use !join as follows.

MyConfigurationTemplate:
Type: AWS::ElasticBeanstalk::ConfigurationTemplate
Properties:
  ApplicationName:  MyApplication
  Description: A default Application
  SolutionStackName: SolutionStack
  OptionSettings:
  ....
  ....
  - Namespace: aws:autoscaling:launchconfiguration
    OptionName: SecurityGroups
    Value:
    !If
      - ConditionIsTrue
      - !Join [',', [!Ref FirstGroup, !ImportValue SecondGroup]]
      - !Ref FirstGroup
  ....
  ....