Package com.pulumi.aws.ec2
Class SecurityGroupRule
- java.lang.Object
-
- com.pulumi.resources.Resource
-
- com.pulumi.resources.CustomResource
-
- com.pulumi.aws.ec2.SecurityGroupRule
-
public class SecurityGroupRule extends com.pulumi.resources.CustomResource
Provides a security group rule resource. Represents a single `ingress` or `egress` group rule, which can be added to external Security Groups. > **NOTE:** Avoid using the `aws.ec2.SecurityGroupRule` resource, as it struggles with managing multiple CIDR blocks, and, due to the historical lack of unique IDs, tags and descriptions. To avoid these problems, use the current best practice of the `aws.vpc.SecurityGroupEgressRule` and `aws.vpc.SecurityGroupIngressRule` resources with one CIDR block per rule. !> **WARNING:** You should not use the `aws.ec2.SecurityGroupRule` resource in conjunction with `aws.vpc.SecurityGroupEgressRule` and `aws.vpc.SecurityGroupIngressRule` resources or with an `aws.ec2.SecurityGroup` resource that has in-line rules. Doing so may cause rule conflicts, perpetual differences, and result in rules being 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](https://docs.aws.amazon.com/vpc/latest/peering/vpc-peering-security-groups.html). ## Example Usage Basic usage <!--Start PulumiCodeChooser -->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(exampleAwsVpc.cidrBlock()) .ipv6CidrBlocks(exampleAwsVpc.ipv6CidrBlock()) .securityGroupId("sg-123456") .build()); } }
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()); } }
package generated_program; import com.pulumi.Context; import com.pulumi.Pulumi; import com.pulumi.core.Output; import com.pulumi.aws.AwsFunctions; import com.pulumi.aws.inputs.GetRegionArgs; import com.pulumi.aws.ec2.Ec2Functions; import com.pulumi.aws.ec2.inputs.GetPrefixListArgs; 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) { final var current = AwsFunctions.getRegion(); final var s3 = Ec2Functions.getPrefixList(GetPrefixListArgs.builder() .name(String.format("com.amazonaws.%s.s3", current.applyValue(getRegionResult -> getRegionResult.name()))) .build()); var s3GatewayEgress = new SecurityGroupRule("s3GatewayEgress", SecurityGroupRuleArgs.builder() .description("S3 Gateway Egress") .type("egress") .securityGroupId("sg-123456") .fromPort(443) .toPort(443) .protocol("tcp") .prefixListIds(s3.applyValue(getPrefixListResult -> getPrefixListResult.id())) .build()); } }
-
-
Constructor Summary
Constructors Constructor Description SecurityGroupRule(java.lang.String name)
SecurityGroupRule(java.lang.String name, SecurityGroupRuleArgs args)
SecurityGroupRule(java.lang.String name, SecurityGroupRuleArgs args, com.pulumi.resources.CustomResourceOptions options)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description com.pulumi.core.Output<java.util.Optional<java.util.List<java.lang.String>>>
cidrBlocks()
com.pulumi.core.Output<java.util.Optional<java.lang.String>>
description()
com.pulumi.core.Output<java.lang.Integer>
fromPort()
static SecurityGroupRule
get(java.lang.String name, com.pulumi.core.Output<java.lang.String> id, SecurityGroupRuleState state, com.pulumi.resources.CustomResourceOptions options)
Get an existing Host resource's state with the given name, ID, and optional extra properties used to qualify the lookup.com.pulumi.core.Output<java.util.Optional<java.util.List<java.lang.String>>>
ipv6CidrBlocks()
com.pulumi.core.Output<java.util.Optional<java.util.List<java.lang.String>>>
prefixListIds()
com.pulumi.core.Output<java.lang.String>
protocol()
com.pulumi.core.Output<java.lang.String>
securityGroupId()
com.pulumi.core.Output<java.lang.String>
securityGroupRuleId()
com.pulumi.core.Output<java.util.Optional<java.lang.Boolean>>
self()
com.pulumi.core.Output<java.lang.String>
sourceSecurityGroupId()
com.pulumi.core.Output<java.lang.Integer>
toPort()
com.pulumi.core.Output<java.lang.String>
type()
-
-
-
Constructor Detail
-
SecurityGroupRule
public SecurityGroupRule(java.lang.String name)
- Parameters:
name
- The _unique_ name of the resulting resource.
-
SecurityGroupRule
public SecurityGroupRule(java.lang.String name, SecurityGroupRuleArgs args)
- Parameters:
name
- The _unique_ name of the resulting resource.args
- The arguments to use to populate this resource's properties.
-
SecurityGroupRule
public SecurityGroupRule(java.lang.String name, SecurityGroupRuleArgs args, @Nullable com.pulumi.resources.CustomResourceOptions options)
- Parameters:
name
- The _unique_ name of the resulting resource.args
- The arguments to use to populate this resource's properties.options
- A bag of options that control this resource's behavior.
-
-
Method Detail
-
cidrBlocks
public com.pulumi.core.Output<java.util.Optional<java.util.List<java.lang.String>>> cidrBlocks()
- Returns:
- List of CIDR blocks. Cannot be specified with `source_security_group_id` or `self`.
-
description
public com.pulumi.core.Output<java.util.Optional<java.lang.String>> description()
- Returns:
- Description of the rule.
-
fromPort
public com.pulumi.core.Output<java.lang.Integer> fromPort()
- Returns:
- Start port (or ICMP type number if protocol is "icmp" or "icmpv6").
-
ipv6CidrBlocks
public com.pulumi.core.Output<java.util.Optional<java.util.List<java.lang.String>>> ipv6CidrBlocks()
- Returns:
- List of IPv6 CIDR blocks. Cannot be specified with `source_security_group_id` or `self`.
-
prefixListIds
public com.pulumi.core.Output<java.util.Optional<java.util.List<java.lang.String>>> prefixListIds()
- Returns:
- List of Prefix List IDs.
-
protocol
public com.pulumi.core.Output<java.lang.String> protocol()
- Returns:
- Protocol. If not icmp, icmpv6, tcp, udp, or all use the [protocol number](https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml)
-
securityGroupId
public com.pulumi.core.Output<java.lang.String> securityGroupId()
- Returns:
- Security group to apply this rule to.
-
securityGroupRuleId
public com.pulumi.core.Output<java.lang.String> securityGroupRuleId()
- Returns:
- If the `aws.ec2.SecurityGroupRule` resource has a single source or destination then this is the AWS Security Group Rule resource ID. Otherwise it is empty.
-
self
public com.pulumi.core.Output<java.util.Optional<java.lang.Boolean>> self()
- Returns:
- 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`.
-
sourceSecurityGroupId
public com.pulumi.core.Output<java.lang.String> sourceSecurityGroupId()
- Returns:
- Security group id to allow access to/from, depending on the `type`. Cannot be specified with `cidr_blocks`, `ipv6_cidr_blocks`, or `self`.
-
toPort
public com.pulumi.core.Output<java.lang.Integer> toPort()
- Returns:
- End port (or ICMP code if protocol is "icmp").
-
type
public com.pulumi.core.Output<java.lang.String> type()
- Returns:
- Type of rule being created. Valid options are `ingress` (inbound) or `egress` (outbound). The following arguments are optional: > **Note** Although `cidr_blocks`, `ipv6_cidr_blocks`, `prefix_list_ids`, and `source_security_group_id` are all marked as optional, you _must_ provide one of them in order to configure the source of the traffic.
-
get
public static SecurityGroupRule get(java.lang.String name, com.pulumi.core.Output<java.lang.String> id, @Nullable SecurityGroupRuleState state, @Nullable com.pulumi.resources.CustomResourceOptions options)
Get an existing Host resource's state with the given name, ID, and optional extra properties used to qualify the lookup.- Parameters:
name
- The _unique_ name of the resulting resource.id
- The _unique_ provider ID of the resource to lookup.state
-options
- Optional settings to control the behavior of the CustomResource.
-
-