I created ec2 instance with cloudformation. When I try to update the securitygroup of the instance in the same template , cloudformation recreates the instance instead of modifying the same (Like in terraform). How to update the SecurityGroup of instance without recreating it ?
 For example the below template -
Resources:
  Ec2Instance:
    Type: 'AWS::EC2::Instance'
    Properties:
      InstanceType: t2.micro
      ImageId: ami-0ed9277fb7eb570c9
      SecurityGroupIds:
        - sg-09d68774a93ec40df
Now If I try to add another SecurityGroupIds it recreates the ec2 -
Resources:
  Ec2Instance:
    Type: 'AWS::EC2::Instance'
    Properties:
      InstanceType: t2.micro
      ImageId: ami-0ed9277fb7eb570c9
      SecurityGroupIds:
        - sg-09d68774a93ec40df
        - sg-05555951931eeaca7