boto3_secgroup

Connection module for Amazon EC2 Security Groups using boto3.

Renamed from boto_secgroup to boto3_secgroup and rewritten to use the boto3 EC2 client API directly via saltext.boto3.utils.boto3mod. The legacy boto2 code path has been removed.

depends:
  • boto3 >= 1.28.0

  • botocore >= 1.31.0

configuration:

This module accepts explicit Security Group credentials but can also utilize IAM roles assigned to the instance through Instance Profiles. Dynamic credentials are then automatically obtained from AWS API and no further configuration is necessary. More Information available at:

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html

If IAM roles are not used you need to specify them either in the minion’s config file or as a profile. For example, to specify them in the minion’s config file:

secgroup.keyid: GKTADJGHEIQSXMKKRBJ08H
secgroup.key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs

A region may also be specified in the configuration:

secgroup.region: us-east-1

It’s also possible to specify key, keyid and region via a profile, either as a passed in dict, or as a string to pull from pillars or minion config:

myprofile:
    keyid: GKTADJGHEIQSXMKKRBJ08H
    key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs
    region: us-east-1

Added in version 1.0.0.

saltext.boto3.modules.boto3_secgroup.__virtual__()[source]

Only load if boto3 is available.

saltext.boto3.modules.boto3_secgroup.exists(name=None, region=None, key=None, keyid=None, profile=None, vpc_id=None, vpc_name=None, group_id=None)[source]

Check to see if a security group exists.

name (str):

The name of the security group to check for existence.

region (str, optional):

The AWS region to use.

key (str, optional):

The AWS access key to use.

keyid (str, optional):

The AWS secret key to use.

profile (str, optional):

The AWS profile to use.

vpc_id (str, optional):

The ID of the VPC the security group belongs to.

vpc_name (str, optional):

The name of the VPC the security group belongs to.

group_id (str, optional):

The ID of the security group.

CLI Example:

salt myminion boto3_secgroup.exists mysecgroup
saltext.boto3.modules.boto3_secgroup.get_all_security_groups(groupnames=None, group_ids=None, filters=None, region=None, key=None, keyid=None, profile=None)[source]

Return a list of all Security Groups matching the given criteria and filters.

groupnames (list, optional):

A list of security group names to filter by.

group_ids (list, optional):

A list of security group IDs to filter by.

filters (dict, optional):

A dictionary of filters to apply when retrieving security groups.

region (str, optional):

The AWS region to use.

key (str, optional):

The AWS access key to use.

keyid (str, optional):

The AWS secret key to use.

profile (str, optional):

The AWS profile to use.

CLI Example:

salt myminion boto3_secgroup.get_all_security_groups filters='{group-name: mygroup}'
saltext.boto3.modules.boto3_secgroup.get_group_id(name, vpc_id=None, vpc_name=None, region=None, key=None, keyid=None, profile=None)[source]

Get a Group ID given a Group Name or Group Name and VPC ID

name (str):

The name of the security group to retrieve the ID for.

vpc_id (str, optional):

The ID of the VPC the security group belongs to.

vpc_name (str, optional):

The name of the VPC the security group belongs to.

region (str, optional):

The AWS region to use.

key (str, optional):

The AWS access key to use.

keyid (str, optional):

The AWS secret key to use.

profile (str, optional):

The AWS profile to use.

CLI Example:

salt myminion boto3_secgroup.get_group_id mysecgroup
saltext.boto3.modules.boto3_secgroup.convert_to_group_ids(groups, vpc_id=None, vpc_name=None, region=None, key=None, keyid=None, profile=None)[source]

Given a list of security groups and a vpc_id, convert all entries to security group ids.

groups (list):

A list of security group names to convert to security group IDs.

vpc_id (str, optional):

The ID of the VPC the security groups belong to.

vpc_name (str, optional):

The name of the VPC the security groups belong to.

region (str, optional):

The AWS region to use.

key (str, optional):

The AWS access key to use.

keyid (str, optional):

The AWS secret key to use.

profile (str, optional):

The AWS profile to use.

CLI Example:

salt myminion boto3_secgroup.convert_to_group_ids mysecgroup vpc-89yhh7h
saltext.boto3.modules.boto3_secgroup.get_config(name=None, group_id=None, region=None, key=None, keyid=None, profile=None, vpc_id=None, vpc_name=None)[source]

Get the configuration for a security group.

name (str, optional):

The name of the security group to retrieve the configuration for.

group_id (str, optional):

The ID of the security group to retrieve the configuration for.

vpc_id (str, optional):

The ID of the VPC the security group belongs to.

vpc_name (str, optional):

The name of the VPC the security group belongs to.

region (str, optional):

The AWS region to use.

key (str, optional):

The AWS access key to use.

keyid (str, optional):

The AWS secret key to use.

profile (str, optional):

The AWS profile to use.

CLI Example:

salt myminion boto3_secgroup.get_config mysecgroup
saltext.boto3.modules.boto3_secgroup.create(name, description, vpc_id=None, vpc_name=None, region=None, key=None, keyid=None, profile=None)[source]

Create a security group.

name (str):

The name of the security group to create.

description (str):

The description of the security group.

vpc_id (str, optional):

The ID of the VPC the security group belongs to.

vpc_name (str, optional):

The name of the VPC the security group belongs to.

region (str, optional):

The AWS region to use.

key (str, optional):

The AWS access key to use.

keyid (str, optional):

The AWS secret key to use.

profile (str, optional):

The AWS profile to use.

CLI Example:

salt myminion boto3_secgroup.create mysecgroup 'My Security Group'
saltext.boto3.modules.boto3_secgroup.delete(name=None, group_id=None, region=None, key=None, keyid=None, profile=None, vpc_id=None, vpc_name=None)[source]

Delete a security group.

name (str, optional):

The name of the security group to delete.

group_id (str, optional):

The ID of the security group to delete.

vpc_id (str, optional):

The ID of the VPC the security group belongs to.

vpc_name (str, optional):

The name of the VPC the security group belongs to.

region (str, optional):

The AWS region to use.

key (str, optional):

The AWS access key to use.

keyid (str, optional):

The AWS secret key to use.

profile (str, optional):

The AWS profile to use.

CLI Example:

salt myminion boto3_secgroup.delete mysecgroup
saltext.boto3.modules.boto3_secgroup.authorize(name=None, source_group_name=None, source_group_owner_id=None, ip_protocol=None, from_port=None, to_port=None, cidr_ip=None, group_id=None, source_group_group_id=None, region=None, key=None, keyid=None, profile=None, vpc_id=None, vpc_name=None, egress=False)[source]

Add a new rule to an existing security group.

name (str, optional):

The name of the security group to add the rule to.

source_group_name (str, optional):

The name of the source security group for the rule.

source_group_owner_id (str, optional):

The AWS account ID of the owner of the source security group.

ip_protocol (str, optional):

The IP protocol for the rule (e.g., “tcp”, “udp”, “icmp”).

from_port (int, optional):

The starting port for the rule.

to_port (int, optional):

The ending port for the rule.

cidr_ip (str, optional):

The CIDR IP range for the rule.

group_id (str, optional):

The ID of the security group to add the rule to.

source_group_group_id (str, optional):

The ID of the source security group for the rule.

region (str, optional):

The AWS region to use.

key (str, optional):

The AWS access key to use.

keyid (str, optional):

The AWS secret key to use.

profile (str, optional):

The AWS profile to use.

vpc_id (str, optional):

The ID of the VPC the security group belongs to.

vpc_name (str, optional):

The name of the VPC the security group belongs to.

egress (bool, optional):

Whether the rule is an egress rule. Defaults to False.

CLI Example:

salt myminion boto3_secgroup.authorize mysecgroup ip_protocol=tcp from_port=80 to_port=80 cidr_ip='10.0.0.0/8'
saltext.boto3.modules.boto3_secgroup.revoke(name=None, source_group_name=None, source_group_owner_id=None, ip_protocol=None, from_port=None, to_port=None, cidr_ip=None, group_id=None, source_group_group_id=None, region=None, key=None, keyid=None, profile=None, vpc_id=None, vpc_name=None, egress=False)[source]

Remove a rule from an existing security group.

name (str, optional):

The name of the security group to remove the rule from.

source_group_name (str, optional):

The name of the source security group for the rule.

source_group_owner_id (str, optional):

The AWS account ID of the owner of the source security group.

ip_protocol (str, optional):

The IP protocol for the rule (e.g., “tcp”, “udp”, “icmp”).

from_port (int, optional):

The starting port for the rule.

to_port (int, optional):

The ending port for the rule.

cidr_ip (str, optional):

The CIDR IP range for the rule.

group_id (str, optional):

The ID of the security group to remove the rule from.

source_group_group_id (str, optional):

The ID of the source security group for the rule.

region (str, optional):

The AWS region to use.

key (str, optional):

The AWS access key to use.

keyid (str, optional):

The AWS secret key to use.

profile (str, optional):

The AWS profile to use.

vpc_id (str, optional):

The ID of the VPC the security group belongs to.

vpc_name (str, optional):

The name of the VPC the security group belongs to.

egress (bool, optional):

Whether the rule is an egress rule. Defaults to False.

CLI Example:

salt myminion boto3_secgroup.revoke mysecgroup ip_protocol=tcp from_port=80 to_port=80 cidr_ip='10.0.0.0/8'
saltext.boto3.modules.boto3_secgroup.set_tags(tags, name=None, group_id=None, vpc_name=None, vpc_id=None, region=None, key=None, keyid=None, profile=None)[source]

Sets tags on a security group.

tags (dict):

A dictionary of tags to set on the security group.

name (str, optional):

The name of the security group to set tags on.

group_id (str, optional):

The ID of the security group to set tags on.

vpc_name (str, optional):

The name of the VPC the security group belongs to.

vpc_id (str, optional):

The ID of the VPC the security group belongs to.

region (str, optional):

The AWS region to use.

key (str, optional):

The AWS access key to use.

keyid (str, optional):

The AWS secret key to use.

profile (str, optional):

The AWS profile to use.

CLI Example:

salt myminion boto3_secgroup.set_tags "{'TAG1': 'Value1'}" security_group_name vpc_id=vpc-13435
saltext.boto3.modules.boto3_secgroup.delete_tags(tags, name=None, group_id=None, vpc_name=None, vpc_id=None, region=None, key=None, keyid=None, profile=None)[source]

Deletes tags from a security group.

tags (list):

A list of tag names to delete from the security group.

name (str, optional):

The name of the security group to delete tags from.

group_id (str, optional):

The ID of the security group to delete tags from.

vpc_name (str, optional):

The name of the VPC the security group belongs to.

vpc_id (str, optional):

The ID of the VPC the security group belongs to.

region (str, optional):

The AWS region to use.

key (str, optional):

The AWS access key to use.

keyid (str, optional):

The AWS secret key to use.

profile (str, optional):

The AWS profile to use.

CLI Example:

salt myminion boto3_secgroup.delete_tags ['TAG1','TAG2'] security_group_name vpc_id=vpc-13435