Home > OS >  How to create and use security groups in cloudformation mappings
How to create and use security groups in cloudformation mappings

Time:07-06

I have created a cloudformation template with a security group mappings but I am getting an error Value of property SecurityGroupIds must be of type List of String

Below is the template

Mappings:
  --- Other maps --- 
  EC2SecurityGroupMap:
    dev:
      defaultsg: "sg-00582b317ae244d8d"
    prd:
      defaultsg: "sg-04666940afe8d91ff"
Resources:
  CreateEC2Instance:  
    Type: "AWS::EC2::Instance"
    Properties:
      ImageId: !FindInMap
        - ImageIdMap
        - !Ref EnvironmentName
        - defaultAMI
      InstanceType: !FindInMap
        - InstanceTypeMap
        - !Ref EnvironmentName
        - defaultInstanceType
      KeyName: !Ref EC2KeyName
      SubnetId: !Ref EC2Subnet
      SecurityGroupIds: !FindInMap [ EC2SecurityGroupMap,!Ref EnvironmentName, defaultsg ]

CodePudding user response:

SecurityGroupIds must be list:

SecurityGroupIds: 
  - !FindInMap [ EC2SecurityGroupMap,!Ref EnvironmentName, defaultsg ]
  • Related