SecurityGroupRuleArgs

data class SecurityGroupRuleArgs(val cidrBlocks: Output<List<String>>? = null, val description: Output<String>? = null, val fromPort: Output<Int>? = null, val ipv6CidrBlocks: Output<List<String>>? = null, val prefixListIds: Output<List<String>>? = null, val protocol: Output<Either<String, ProtocolType>>? = null, val securityGroupId: Output<String>? = null, val self: Output<Boolean>? = null, val sourceSecurityGroupId: Output<String>? = null, val toPort: Output<Int>? = null, val type: Output<String>? = null) : ConvertibleToJava<SecurityGroupRuleArgs>

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 a Security Group resource with ingress and egress rules defined in-line and a Security Group Rule resource which manages one or more ingress or egress rules. Both of these resource were added before AWS assigned a security group rule unique ID, and they do not work well in all scenarios using thedescription and tags attributes, which rely on the unique ID. The aws_vpc_security_group_egress_rule and aws_vpc_security_group_ingress_rule resources have been added to address these limitations and should be used for all new security group rules. You should not use the aws_vpc_security_group_egress_rule and aws_vpc_security_group_ingress_rule resources in conjunction with an aws.ec2.SecurityGroup resource with in-line rules or with aws.ec2.SecurityGroupRule resources defined for the same Security Group, as rule conflicts may occur and rules will be overwritten. NOTE: Setting protocol = "all" or protocol = -1 with from_port and to_port will 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.

Example Usage

Basic usage

package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.ec2.SecurityGroupRule;
import com.pulumi.aws.ec2.SecurityGroupRuleArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var example = new SecurityGroupRule("example", SecurityGroupRuleArgs.builder()
.type("ingress")
.fromPort(0)
.toPort(65535)
.protocol("tcp")
.cidrBlocks(aws_vpc.example().cidr_block())
.ipv6CidrBlocks(aws_vpc.example().ipv6_cidr_block())
.securityGroupId("sg-123456")
.build());
}
}

Usage With Prefix List IDs

Prefix Lists are either managed by AWS internally, or created by the customer using a Managed Prefix List resource. Prefix Lists provided by AWS 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:

package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.ec2.VpcEndpoint;
import com.pulumi.aws.ec2.SecurityGroupRule;
import com.pulumi.aws.ec2.SecurityGroupRuleArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var myEndpoint = new VpcEndpoint("myEndpoint");
var allowAll = new SecurityGroupRule("allowAll", SecurityGroupRuleArgs.builder()
.type("egress")
.toPort(0)
.protocol("-1")
.prefixListIds(myEndpoint.prefixListId())
.fromPort(0)
.securityGroupId("sg-123456")
.build());
}
}

Import

Security Group Rules can be imported using the security_group_id, type, protocol, from_port, to_port, and source(s)/destination(s) (e.g., cidr_block) separated by underscores (_). All parts are required. Not all rule permissions (e.g., not all of a rule's CIDR blocks) need to be imported for this provider to manage rule permissions. However, importing some of a rule's permissions but not others, and then making changes to the rule will result in the creation of an additional rule to capture the updated permissions. Rule permissions that were not imported are left intact in the original rule. Import an ingress rule in security group sg-6e616f6d69 for TCP port 8000 with an IPv4 destination CIDR of 10.0.3.0/24console

$ pulumi import aws:ec2/securityGroupRule:SecurityGroupRule ingress sg-6e616f6d69_ingress_tcp_8000_8000_10.0.3.0/24

Import a rule with various IPv4 and IPv6 source CIDR blocksconsole

$ pulumi import aws:ec2/securityGroupRule:SecurityGroupRule ingress sg-4973616163_ingress_tcp_100_121_10.1.0.0/16_2001:db8::/48_10.2.0.0/16_2002:db8::/48

Import a rule, applicable to all ports, with a protocol other than TCP/UDP/ICMP/ICMPV6/ALL, e.g., Multicast Transport Protocol (MTP), using the IANA protocol number, e.g., 92. console

$ pulumi import aws:ec2/securityGroupRule:SecurityGroupRule ingress sg-6777656e646f6c796e_ingress_92_0_65536_10.0.3.0/24_10.0.4.0/24

Import a default any/any egress rule to 0.0.0.0/0console

$ pulumi import aws:ec2/securityGroupRule:SecurityGroupRule default_egress sg-6777656e646f6c796e_egress_all_0_0_0.0.0.0/0

Import an egress rule with a prefix list ID destinationconsole

$ pulumi import aws:ec2/securityGroupRule:SecurityGroupRule egress sg-62726f6479_egress_tcp_8000_8000_pl-6469726b

Import a rule applicable to all protocols and ports with a security group sourceconsole

$ pulumi import aws:ec2/securityGroupRule:SecurityGroupRule ingress_rule sg-7472697374616e_ingress_all_0_65536_sg-6176657279

Import a rule that has itself and an IPv6 CIDR block as sourcesconsole

$ pulumi import aws:ec2/securityGroupRule:SecurityGroupRule rule_name sg-656c65616e6f72_ingress_tcp_80_80_self_2001:db8::/48

Constructors

Link copied to clipboard
constructor(cidrBlocks: Output<List<String>>? = null, description: Output<String>? = null, fromPort: Output<Int>? = null, ipv6CidrBlocks: Output<List<String>>? = null, prefixListIds: Output<List<String>>? = null, protocol: Output<Either<String, ProtocolType>>? = null, securityGroupId: Output<String>? = null, self: Output<Boolean>? = null, sourceSecurityGroupId: Output<String>? = null, toPort: Output<Int>? = null, type: Output<String>? = null)

Properties

Link copied to clipboard
val cidrBlocks: Output<List<String>>? = null

List of CIDR blocks. Cannot be specified with source_security_group_id or self.

Link copied to clipboard
val description: Output<String>? = null

Description of the rule.

Link copied to clipboard
val fromPort: Output<Int>? = null

Start port (or ICMP type number if protocol is "icmp" or "icmpv6").

Link copied to clipboard
val ipv6CidrBlocks: Output<List<String>>? = null

List of IPv6 CIDR blocks. Cannot be specified with source_security_group_id or self.

Link copied to clipboard
val prefixListIds: Output<List<String>>? = null

List of Prefix List IDs.

Link copied to clipboard
val protocol: Output<Either<String, ProtocolType>>? = null

Protocol. If not icmp, icmpv6, tcp, udp, or all use the protocol number

Link copied to clipboard
val securityGroupId: Output<String>? = null

Security group to apply this rule to.

Link copied to clipboard
val self: Output<Boolean>? = null

Whether the security group itself will be added as a source to this ingress rule. Cannot be specified with cidr_blocks, ipv6_cidr_blocks, or source_security_group_id.

Link copied to clipboard
val sourceSecurityGroupId: Output<String>? = null

Security group id to allow access to/from, depending on the type. Cannot be specified with cidr_blocks, ipv6_cidr_blocks, or self.

Link copied to clipboard
val toPort: Output<Int>? = null

End port (or ICMP code if protocol is "icmp").

Link copied to clipboard
val type: Output<String>? = null

Type of rule being created. Valid options are ingress (inbound) or egress (outbound). The following arguments are optional:

Functions

Link copied to clipboard
open override fun toJava(): SecurityGroupRuleArgs