Search code examples
amazon-web-servicesaws-cloudformationaws-security-group

I have a problem in cloud formation. Error when using Fn::Join with a parameter


I am trying to create one Security Group and calling other security group from parameters using cloudformation. I used this as a resource however I get the following error message from cloudfromation

Template validation error: Template error: every Fn::Join object requires two parameters, (1) a string delimiter and (2) a list of strings to be joined or a function that returns a list of strings (such as Fn::GetAZs) to be joined.

AWSTemplateFormatVersion : 2010-09-09
Description: "simple web layer"
Parameters:
Securitygroupid:
Description: enter sc
Type: List<AWS::EC2::SecurityGroup::Id>
NoEcho: false
Default: sg-05323df39f12d8034

Resources:
   Lpsecurity:
Type: AWS::EC2::SecurityGroup
Properties:
Securitygroupid:
Description: enter sc
Type: List<AWS::EC2::SecurityGroup::Id
NoEcho: false
Default: sg-05323df39f12d8034
      VpcId: !Ref Vpc
      GroupDescription: Sample target security group
      SecurityGroupIngress:        
      - IpProtocol: tcp
        FromPort: 80
        ToPort: 80
        CidrIp: !Ref Securitycab
      - IpProtocol: tcp
        FromPort: 443
        ToPort: 443
        CidrIp: !Ref Securitycab 
   MyEC2Instance1:
     Type: 'AWS::EC2::Instance'
     Properties:
       ImageId: !Ref ImageId
       InstanceType: t2.micro
       SubnetId: !Select [ 0, !Ref Subnets ]
       SecurityGroupIds: !Join [ ",", [ !Ref Securitygroupid, !Ref Lpsecurity ]]

What am I doing wrong here?


Solution

  • I found solution.

    SecurityGroupIds:  !Split
        - ","
        - !Sub
          - "${idList},${Lpsecurity}"
          - idList: !Join [",",!Ref "SecurityGroup"]