SecurityGroupRule
Provides a security group rule resource. Represents a single ingress or
egress group rule, which can be added to external Security Groups.
NOTE on Security Groups and Security Group Rules: This provider currently provides both a standalone Security Group Rule resource (a single
ingressoregressrule), and a Security Group resource withingressandegressrules defined in-line. At this time you cannot use a Security Group with in-line rules in conjunction with any Security Group Rule resources. Doing so will cause a conflict of rule settings and will overwrite rules.NOTE: Setting
protocol = "all"orprotocol = -1withfrom_portandto_portwill result in the EC2 API creating a security group rule with all ports open. This API behavior cannot be controlled by this provider and may generate warnings in the future.NOTE: Referencing Security Groups across VPC peering has certain restrictions. More information is available in the VPC Peering User Guide.
Usage with prefix list IDs
Prefix list IDs are manged by AWS internally. Prefix list IDs are associated with a prefix list name, or service name, that is linked to a specific region. Prefix list IDs are exported on VPC Endpoints, so you can use this format:
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
// ...
const myEndpoint = new aws.ec2.VpcEndpoint("my_endpoint", {});
const allowAll = new aws.ec2.SecurityGroupRule("allow_all", {
fromPort: 0,
prefixListIds: [myEndpoint.prefixListId],
protocol: "-1",
securityGroupId: "sg-123456",
toPort: 0,
type: "egress",
});import pulumi
import pulumi_aws as aws
# ...
my_endpoint = aws.ec2.VpcEndpoint("myEndpoint")
allow_all = aws.ec2.SecurityGroupRule("allowAll",
from_port=0,
prefix_list_ids=[my_endpoint.prefix_list_id],
protocol="-1",
security_group_id="sg-123456",
to_port=0,
type="egress")using Pulumi;
using Aws = Pulumi.Aws;
class MyStack : Stack
{
public MyStack()
{
// ...
var myEndpoint = new Aws.Ec2.VpcEndpoint("myEndpoint", new Aws.Ec2.VpcEndpointArgs
{
});
var allowAll = new Aws.Ec2.SecurityGroupRule("allowAll", new Aws.Ec2.SecurityGroupRuleArgs
{
FromPort = 0,
PrefixListIds =
{
myEndpoint.PrefixListId,
},
Protocol = "-1",
SecurityGroupId = "sg-123456",
ToPort = 0,
Type = "egress",
});
}
}
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws/ec2"
"github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
myEndpoint, err := ec2.NewVpcEndpoint(ctx, "myEndpoint", nil)
if err != nil {
return err
}
_, err = ec2.NewSecurityGroupRule(ctx, "allowAll", &ec2.SecurityGroupRuleArgs{
FromPort: pulumi.Int(0),
PrefixListIds: pulumi.StringArray{
myEndpoint.PrefixListId,
},
Protocol: pulumi.String("-1"),
SecurityGroupId: pulumi.String("sg-123456"),
ToPort: pulumi.Int(0),
Type: pulumi.String("egress"),
})
if err != nil {
return err
}
return nil
})
}Example Usage
using Pulumi;
using Aws = Pulumi.Aws;
class MyStack : Stack
{
public MyStack()
{
var example = new Aws.Ec2.SecurityGroupRule("example", new Aws.Ec2.SecurityGroupRuleArgs
{
Type = "ingress",
FromPort = 0,
ToPort = 65535,
Protocol = "tcp",
CidrBlocks = aws_vpc.Example.Cidr_block,
SecurityGroupId = "sg-123456",
});
}
}
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws/ec2"
"github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := ec2.NewSecurityGroupRule(ctx, "example", &ec2.SecurityGroupRuleArgs{
Type: pulumi.String("ingress"),
FromPort: pulumi.Int(0),
ToPort: pulumi.Int(65535),
Protocol: pulumi.String("tcp"),
CidrBlocks: aws_vpc.Example.Cidr_block,
SecurityGroupId: pulumi.String("sg-123456"),
})
if err != nil {
return err
}
return nil
})
}import pulumi
import pulumi_aws as aws
example = aws.ec2.SecurityGroupRule("example",
type="ingress",
from_port=0,
to_port=65535,
protocol="tcp",
cidr_blocks=aws_vpc["example"]["cidr_block"],
security_group_id="sg-123456")import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const example = new aws.ec2.SecurityGroupRule("example", {
type: "ingress",
fromPort: 0,
toPort: 65535,
protocol: "tcp",
cidrBlocks: aws_vpc.example.cidr_block,
securityGroupId: "sg-123456",
});Create a SecurityGroupRule Resource
new SecurityGroupRule(name: string, args: SecurityGroupRuleArgs, opts?: CustomResourceOptions);def SecurityGroupRule(resource_name, opts=None, cidr_blocks=None, description=None, from_port=None, ipv6_cidr_blocks=None, prefix_list_ids=None, protocol=None, security_group_id=None, self=None, source_security_group_id=None, to_port=None, type=None, __props__=None);func NewSecurityGroupRule(ctx *Context, name string, args SecurityGroupRuleArgs, opts ...ResourceOption) (*SecurityGroupRule, error)public SecurityGroupRule(string name, SecurityGroupRuleArgs args, CustomResourceOptions? opts = null)- name string
- The unique name of the resource.
- args SecurityGroupRuleArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- resource_name str
- The unique name of the resource.
- opts ResourceOptions
- A bag of options that control this resource's behavior.
- ctx Context
- Context object for the current deployment.
- name string
- The unique name of the resource.
- args SecurityGroupRuleArgs
- The arguments to resource properties.
- opts ResourceOption
- Bag of options to control resource's behavior.
- name string
- The unique name of the resource.
- args SecurityGroupRuleArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
SecurityGroupRule Resource Properties
To learn more about resource properties and how to use them, see Inputs and Outputs in the Programming Model docs.
Inputs
The SecurityGroupRule resource accepts the following input properties:
- From
Port int The start port (or ICMP type number if protocol is “icmp” or “icmpv6”).
- Protocol string
The protocol. If not icmp, icmpv6, tcp, udp, or all use the protocol number
- Security
Group stringId The security group to apply this rule to.
- To
Port int The end port (or ICMP code if protocol is “icmp”).
- Type string
The type of rule being created. Valid options are
ingress(inbound) oregress(outbound).- Cidr
Blocks List<string> List of CIDR blocks. Cannot be specified with
source_security_group_id.- Description string
Description of the rule.
- Ipv6Cidr
Blocks List<string> List of IPv6 CIDR blocks.
- Prefix
List List<string>Ids List of prefix list IDs (for allowing access to VPC endpoints). Only valid with
egress.- Self bool
If true, the security group itself will be added as a source to this ingress rule. Cannot be specified with
source_security_group_id.- Source
Security stringGroup Id The security group id to allow access to/from, depending on the
type. Cannot be specified withcidr_blocksandself.
- From
Port int The start port (or ICMP type number if protocol is “icmp” or “icmpv6”).
- Protocol string
The protocol. If not icmp, icmpv6, tcp, udp, or all use the protocol number
- Security
Group stringId The security group to apply this rule to.
- To
Port int The end port (or ICMP code if protocol is “icmp”).
- Type string
The type of rule being created. Valid options are
ingress(inbound) oregress(outbound).- Cidr
Blocks []string List of CIDR blocks. Cannot be specified with
source_security_group_id.- Description string
Description of the rule.
- Ipv6Cidr
Blocks []string List of IPv6 CIDR blocks.
- Prefix
List []stringIds List of prefix list IDs (for allowing access to VPC endpoints). Only valid with
egress.- Self bool
If true, the security group itself will be added as a source to this ingress rule. Cannot be specified with
source_security_group_id.- Source
Security stringGroup Id The security group id to allow access to/from, depending on the
type. Cannot be specified withcidr_blocksandself.
- from
Port number The start port (or ICMP type number if protocol is “icmp” or “icmpv6”).
- protocol string
The protocol. If not icmp, icmpv6, tcp, udp, or all use the protocol number
- security
Group stringId The security group to apply this rule to.
- to
Port number The end port (or ICMP code if protocol is “icmp”).
- type string
The type of rule being created. Valid options are
ingress(inbound) oregress(outbound).- cidr
Blocks string[] List of CIDR blocks. Cannot be specified with
source_security_group_id.- description string
Description of the rule.
- ipv6Cidr
Blocks string[] List of IPv6 CIDR blocks.
- prefix
List string[]Ids List of prefix list IDs (for allowing access to VPC endpoints). Only valid with
egress.- self boolean
If true, the security group itself will be added as a source to this ingress rule. Cannot be specified with
source_security_group_id.- source
Security stringGroup Id The security group id to allow access to/from, depending on the
type. Cannot be specified withcidr_blocksandself.
- from_
port float The start port (or ICMP type number if protocol is “icmp” or “icmpv6”).
- protocol str
The protocol. If not icmp, icmpv6, tcp, udp, or all use the protocol number
- security_
group_ strid The security group to apply this rule to.
- to_
port float The end port (or ICMP code if protocol is “icmp”).
- type str
The type of rule being created. Valid options are
ingress(inbound) oregress(outbound).- cidr_
blocks List[str] List of CIDR blocks. Cannot be specified with
source_security_group_id.- description str
Description of the rule.
- ipv6_
cidr_ List[str]blocks List of IPv6 CIDR blocks.
- prefix_
list_ List[str]ids List of prefix list IDs (for allowing access to VPC endpoints). Only valid with
egress.- self bool
If true, the security group itself will be added as a source to this ingress rule. Cannot be specified with
source_security_group_id.- source_
security_ strgroup_ id The security group id to allow access to/from, depending on the
type. Cannot be specified withcidr_blocksandself.
Outputs
All input properties are implicitly available as output properties. Additionally, the SecurityGroupRule resource produces the following output properties:
Look up an Existing SecurityGroupRule Resource
Get an existing SecurityGroupRule resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.
public static get(name: string, id: Input<ID>, state?: SecurityGroupRuleState, opts?: CustomResourceOptions): SecurityGroupRulestatic get(resource_name, id, opts=None, cidr_blocks=None, description=None, from_port=None, ipv6_cidr_blocks=None, prefix_list_ids=None, protocol=None, security_group_id=None, self=None, source_security_group_id=None, to_port=None, type=None, __props__=None);func GetSecurityGroupRule(ctx *Context, name string, id IDInput, state *SecurityGroupRuleState, opts ...ResourceOption) (*SecurityGroupRule, error)public static SecurityGroupRule Get(string name, Input<string> id, SecurityGroupRuleState? state, CustomResourceOptions? opts = null)- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- resource_name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
The following state arguments are supported:
- Cidr
Blocks List<string> List of CIDR blocks. Cannot be specified with
source_security_group_id.- Description string
Description of the rule.
- From
Port int The start port (or ICMP type number if protocol is “icmp” or “icmpv6”).
- Ipv6Cidr
Blocks List<string> List of IPv6 CIDR blocks.
- Prefix
List List<string>Ids List of prefix list IDs (for allowing access to VPC endpoints). Only valid with
egress.- Protocol string
The protocol. If not icmp, icmpv6, tcp, udp, or all use the protocol number
- Security
Group stringId The security group to apply this rule to.
- Self bool
If true, the security group itself will be added as a source to this ingress rule. Cannot be specified with
source_security_group_id.- Source
Security stringGroup Id The security group id to allow access to/from, depending on the
type. Cannot be specified withcidr_blocksandself.- To
Port int The end port (or ICMP code if protocol is “icmp”).
- Type string
The type of rule being created. Valid options are
ingress(inbound) oregress(outbound).
- Cidr
Blocks []string List of CIDR blocks. Cannot be specified with
source_security_group_id.- Description string
Description of the rule.
- From
Port int The start port (or ICMP type number if protocol is “icmp” or “icmpv6”).
- Ipv6Cidr
Blocks []string List of IPv6 CIDR blocks.
- Prefix
List []stringIds List of prefix list IDs (for allowing access to VPC endpoints). Only valid with
egress.- Protocol string
The protocol. If not icmp, icmpv6, tcp, udp, or all use the protocol number
- Security
Group stringId The security group to apply this rule to.
- Self bool
If true, the security group itself will be added as a source to this ingress rule. Cannot be specified with
source_security_group_id.- Source
Security stringGroup Id The security group id to allow access to/from, depending on the
type. Cannot be specified withcidr_blocksandself.- To
Port int The end port (or ICMP code if protocol is “icmp”).
- Type string
The type of rule being created. Valid options are
ingress(inbound) oregress(outbound).
- cidr
Blocks string[] List of CIDR blocks. Cannot be specified with
source_security_group_id.- description string
Description of the rule.
- from
Port number The start port (or ICMP type number if protocol is “icmp” or “icmpv6”).
- ipv6Cidr
Blocks string[] List of IPv6 CIDR blocks.
- prefix
List string[]Ids List of prefix list IDs (for allowing access to VPC endpoints). Only valid with
egress.- protocol string
The protocol. If not icmp, icmpv6, tcp, udp, or all use the protocol number
- security
Group stringId The security group to apply this rule to.
- self boolean
If true, the security group itself will be added as a source to this ingress rule. Cannot be specified with
source_security_group_id.- source
Security stringGroup Id The security group id to allow access to/from, depending on the
type. Cannot be specified withcidr_blocksandself.- to
Port number The end port (or ICMP code if protocol is “icmp”).
- type string
The type of rule being created. Valid options are
ingress(inbound) oregress(outbound).
- cidr_
blocks List[str] List of CIDR blocks. Cannot be specified with
source_security_group_id.- description str
Description of the rule.
- from_
port float The start port (or ICMP type number if protocol is “icmp” or “icmpv6”).
- ipv6_
cidr_ List[str]blocks List of IPv6 CIDR blocks.
- prefix_
list_ List[str]ids List of prefix list IDs (for allowing access to VPC endpoints). Only valid with
egress.- protocol str
The protocol. If not icmp, icmpv6, tcp, udp, or all use the protocol number
- security_
group_ strid The security group to apply this rule to.
- self bool
If true, the security group itself will be added as a source to this ingress rule. Cannot be specified with
source_security_group_id.- source_
security_ strgroup_ id The security group id to allow access to/from, depending on the
type. Cannot be specified withcidr_blocksandself.- to_
port float The end port (or ICMP code if protocol is “icmp”).
- type str
The type of rule being created. Valid options are
ingress(inbound) oregress(outbound).
Package Details
- Repository
- https://github.com/pulumi/pulumi-aws
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
awsTerraform Provider.