paul
paul

Reputation: 13471

Cloudformation security group set group name

Using cloudformation SecurityGroup is possible set the GroupName or has to be provide by cloudformation?.

The final name format it´s pretty long and does not look nice, also is not a good match to use it for find it by command line.

I know I can use tags, but still don't understand why AWS don't allow us to add it, I guess because they´re lazy and they don't want to implement a validation.

Regards.

Upvotes: 6

Views: 4324

Answers (3)

Raul Perez
Raul Perez

Reputation: 45

The name of most resources is simply a type of special Tags with the Key Name, To edit this fields just add the tag to the template

  mySecurityGroup:
    Type: 'AWS::EC2::SecurityGroup'
    Properties:
      VpcId: !Ref myVPC
      GroupDescription: Security Group 
      SecurityGroupIngress:
        - IpProtocol: tcp
          FromPort: 22
          ToPort: 22
          CidrIp: 0.0.0.0/0
      Tags:
        - Key: Name
          Value: mySecurityGroup

Upvotes: 0

wjordan
wjordan

Reputation: 20390

[Updated Jun 26 2017] As of Apr 28 2017, it is now possible to specify a custom name for an EC2 Security Group using CloudFormation, using the GroupName property on the AWS::EC2::SecurityGroup resource.

Thanks surenyonjan for the comment on this update.


[Original answer Dec. 23 2016] - No, it is not currently possible to provide a custom name for an EC2 Security Group using CloudFormation.

According to the AWS::EC2::SecurityGroup resource documentation, there is no Name or GroupName property available. You can provide tags using the Tags property as an alternative, as you pointed out.

Recently, some CloudFormation resources have started supporting custom names via a Name property. A full list of supported resources is in the Name Type section of the documentation.

AWS::EC2::SecurityGroup is not one of the resources supporting custom names. As for why, presumably this is because this CloudFormation resource is an earlier implementation, created before custom names were supported by the service.

It's possible that AWS will eventually go back and update all of its existing CloudFormation resources with custom name support at some point, if enough users ask them to do so. If this is an important/critical feature for your use case, I'd recommend contacting their product/support teams with a feature request to help them make it higher priority.

Upvotes: 3

Markus Herzog
Markus Herzog

Reputation: 384

You can set the name for a SecurityGroup by adding a Tag with the key "Name", like this:

"MySecurityGroup": {
  "Type": "AWS::EC2::SecurityGroup",
  "Properties": {
    "GroupDescription": "Allow http",
    "SecurityGroupIngress": [
      {"IpProtocol": "tcp", "FromPort": "80", "ToPort": "80", "CidrIp": "0.0.0.0/0"}
    ],
    "Tags": [
      {"Key": "Name", "Value": "MySecurityGroup"},
    ]
  }
},

Upvotes: 6

Related Questions