security_groups
Creates, updates, deletes or gets a security_group resource or lists security_groups in a region
Overview
| Name | security_groups |
| Type | Resource |
| Description | Resource Type definition for AWS::EC2::SecurityGroup |
| Id | awscc.ec2.security_groups |
Fields
- get (all properties)
- list (identifiers only)
| Name | Datatype | Description |
|---|---|---|
group_description | string | A description for the security group. |
group_name | string | The name of the security group. |
vpc_id | string | The ID of the VPC for the security group. |
id | string | The group name or group ID depending on whether the SG is created in default or specific VPC |
security_group_ingress | array | The inbound rules associated with the security group. There is a short interruption during which you cannot connect to the security group. |
security_group_egress | array | [VPC only] The outbound rules associated with the security group. There is a short interruption during which you cannot connect to the security group. |
tags | array | Any tags assigned to the security group. |
group_id | string | The group ID of the specified security group. |
region | string | AWS region. |
| Name | Datatype | Description |
|---|---|---|
id | string | The group name or group ID depending on whether the SG is created in default or specific VPC |
region | string | AWS region. |
For more information, see AWS::EC2::SecurityGroup.
Methods
| Name | Resource | Accessible by | Required Params |
|---|---|---|---|
create_resource | security_groups | INSERT | GroupDescription, region |
delete_resource | security_groups | DELETE | Identifier, region |
update_resource | security_groups | UPDATE | Identifier, PatchDocument, region |
list_resources | security_groups_list_only | SELECT | region |
get_resource | security_groups | SELECT | Identifier, region |
SELECT examples
- get (all properties)
- list (identifiers only)
Gets all properties from an individual security_group.
SELECT
region,
group_description,
group_name,
vpc_id,
id,
security_group_ingress,
security_group_egress,
tags,
group_id
FROM awscc.ec2.security_groups
WHERE
region = '{{ region }}' AND
Identifier = '{{ id }}';
Lists all security_groups in a region.
SELECT
region,
id
FROM awscc.ec2.security_groups_list_only
WHERE
region = '{{ region }}';
INSERT example
Use the following StackQL query and manifest file to create a new security_group resource, using stack-deploy.
- Required Properties
- All Properties
- Manifest
/*+ create */
INSERT INTO awscc.ec2.security_groups (
GroupDescription,
region
)
SELECT
'{{ group_description }}',
'{{ region }}'
RETURNING
ErrorCode,
EventTime,
Identifier,
Operation,
OperationStatus,
RequestToken,
ResourceModel,
RetryAfter,
StatusMessage,
TypeName
;
/*+ create */
INSERT INTO awscc.ec2.security_groups (
GroupDescription,
GroupName,
VpcId,
SecurityGroupIngress,
SecurityGroupEgress,
Tags,
region
)
SELECT
'{{ group_description }}',
'{{ group_name }}',
'{{ vpc_id }}',
'{{ security_group_ingress }}',
'{{ security_group_egress }}',
'{{ tags }}',
'{{ region }}'
RETURNING
ErrorCode,
EventTime,
Identifier,
Operation,
OperationStatus,
RequestToken,
ResourceModel,
RetryAfter,
StatusMessage,
TypeName
;
version: 1
name: stack name
description: stack description
providers:
- aws
globals:
- name: region
value: '{{ vars.AWS_REGION }}'
resources:
- name: security_group
props:
- name: group_description
value: '{{ group_description }}'
- name: group_name
value: '{{ group_name }}'
- name: vpc_id
value: '{{ vpc_id }}'
- name: security_group_ingress
value:
- cidr_ip: '{{ cidr_ip }}'
cidr_ipv6: '{{ cidr_ipv6 }}'
description: '{{ description }}'
from_port: '{{ from_port }}'
source_security_group_name: '{{ source_security_group_name }}'
to_port: '{{ to_port }}'
source_security_group_owner_id: '{{ source_security_group_owner_id }}'
ip_protocol: '{{ ip_protocol }}'
source_security_group_id: '{{ source_security_group_id }}'
source_prefix_list_id: '{{ source_prefix_list_id }}'
- name: security_group_egress
value:
- cidr_ip: '{{ cidr_ip }}'
cidr_ipv6: '{{ cidr_ipv6 }}'
description: '{{ description }}'
from_port: '{{ from_port }}'
to_port: '{{ to_port }}'
ip_protocol: '{{ ip_protocol }}'
destination_security_group_id: '{{ destination_security_group_id }}'
destination_prefix_list_id: '{{ destination_prefix_list_id }}'
- name: tags
value:
- key: '{{ key }}'
value: '{{ value }}'
UPDATE example
Use the following StackQL query and manifest file to update a security_group resource, using stack-deploy.
/*+ update */
UPDATE awscc.ec2.security_groups
SET PatchDocument = string('{{ {
"SecurityGroupIngress": security_group_ingress,
"SecurityGroupEgress": security_group_egress,
"Tags": tags
} | generate_patch_document }}')
WHERE
region = '{{ region }}' AND
Identifier = '{{ id }}'
RETURNING
ErrorCode,
EventTime,
Identifier,
Operation,
OperationStatus,
RequestToken,
ResourceModel,
RetryAfter,
StatusMessage,
TypeName
;
DELETE example
/*+ delete */
DELETE FROM awscc.ec2.security_groups
WHERE
Identifier = '{{ id }}' AND
region = '{{ region }}'
RETURNING
ErrorCode,
EventTime,
Identifier,
Operation,
OperationStatus,
RequestToken,
ResourceModel,
RetryAfter,
StatusMessage,
TypeName
;
Additional Parameters
Mutable resources in the Cloud Control provider support additional optional parameters which can be supplied with INSERT, UPDATE, or DELETE operations. These include:
| Parameter | Description |
|---|---|
ClientToken | A unique identifier to ensure the idempotency of the resource request.This allows the provider to accurately distinguish between retries and new requests.A client token is valid for 36 hours once used. After that, a resource request with the same client token is treated as a new request. If you do not specify a client token, one is generated for inclusion in the request. |
RoleArn | The ARN of the IAM role used to perform this resource operation.The role specified must have the permissions required for this operation.If you do not specify a role, a temporary session is created using your AWS user credentials. |
TypeVersionId | For private resource types, the type version to use in this resource operation.If you do not specify a resource version, the default version is used. |
Permissions
To operate on the security_groups resource, the following permissions are required:
- Read
- Create
- Update
- List
- Delete
ec2:DescribeSecurityGroups
ec2:CreateSecurityGroup,
ec2:DescribeSecurityGroups,
ec2:RevokeSecurityGroupEgress,
ec2:AuthorizeSecurityGroupEgress,
ec2:AuthorizeSecurityGroupIngress,
ec2:CreateTags
ec2:RevokeSecurityGroupEgress,
ec2:RevokeSecurityGroupIngress,
ec2:DescribeSecurityGroups,
ec2:AuthorizeSecurityGroupEgress,
ec2:AuthorizeSecurityGroupIngress,
ec2:UpdateSecurityGroupRuleDescriptionsIngress,
ec2:UpdateSecurityGroupRuleDescriptionsEgress,
ec2:CreateTags,
ec2:DeleteTags
ec2:DescribeSecurityGroups
ec2:DescribeSecurityGroups,
ec2:DeleteSecurityGroup,
ec2:DescribeInstances