SecurityGroupIngressRule class
Manages an inbound (ingress) rule for a security group.
When specifying an inbound rule for your security group in a VPC, the configuration must include a source for the traffic.
> NOTE: Using aws.vpc.SecurityGroupEgressRule and aws.vpc.SecurityGroupIngressRule resources is the current best practice. Avoid using the aws.ec2.SecurityGroupRule resource and the ingress and egress arguments of the aws.ec2.SecurityGroup resource for configuring in-line rules, as they struggle with managing multiple CIDR blocks, and tags and descriptions due to the historical lack of unique IDs.
> WARNING: You should not use the aws.vpc.SecurityGroupEgressRule and aws.vpc.SecurityGroupIngressRule resources in conjunction with the aws.ec2.SecurityGroup resource with in-line rules (using the ingress and egress arguments of aws.ec2.SecurityGroup) or the aws.ec2.SecurityGroupRule resource. Doing so may cause rule conflicts, perpetual differences, and result in rules being overwritten.
Example Usage
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const example = new aws.ec2.SecurityGroup("example", {
name: "example",
description: "example",
vpcId: main.id,
tags: {
Name: "example",
},
});
const exampleSecurityGroupIngressRule = new aws.vpc.SecurityGroupIngressRule("example", {
securityGroupId: example.id,
cidrIpv4: "10.0.0.0/8",
fromPort: 80,
ipProtocol: "tcp",
toPort: 80,
});
import pulumi
import pulumi_aws as aws
example = aws.ec2.SecurityGroup("example",
name="example",
description="example",
vpc_id=main["id"],
tags={
"Name": "example",
})
example_security_group_ingress_rule = aws.vpc.SecurityGroupIngressRule("example",
security_group_id=example.id,
cidr_ipv4="10.0.0.0/8",
from_port=80,
ip_protocol="tcp",
to_port=80)
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var example = new Aws.Ec2.SecurityGroup("example", new()
{
Name = "example",
Description = "example",
VpcId = main.Id,
Tags =
{
{ "Name", "example" },
},
});
var exampleSecurityGroupIngressRule = new Aws.Vpc.SecurityGroupIngressRule("example", new()
{
SecurityGroupId = example.Id,
CidrIpv4 = "10.0.0.0/8",
FromPort = 80,
IpProtocol = "tcp",
ToPort = 80,
});
});
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/ec2"
"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/vpc"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
example, err := ec2.NewSecurityGroup(ctx, "example", &ec2.SecurityGroupArgs{
Name: pulumi.String("example"),
Description: pulumi.String("example"),
VpcId: pulumi.Any(main.Id),
Tags: pulumi.StringMap{
"Name": pulumi.String("example"),
},
})
if err != nil {
return err
}
_, err = vpc.NewSecurityGroupIngressRule(ctx, "example", &vpc.SecurityGroupIngressRuleArgs{
SecurityGroupId: example.ID().ToIDOutput().ToStringOutput(),
CidrIpv4: pulumi.String("10.0.0.0/8"),
FromPort: pulumi.Int(80),
IpProtocol: pulumi.String("tcp"),
ToPort: pulumi.Int(80),
})
if err != nil {
return err
}
return nil
})
}
pulumi {
required_providers {
aws = {
source = "pulumi/aws"
}
}
}
resource "aws_ec2_securitygroup" "example" {
name = "example"
description = "example"
vpc_id = main.id
tags = {
"Name" = "example"
}
}
resource "aws_vpc_securitygroupingressrule" "example" {
security_group_id = aws_ec2_securitygroup.example.id
cidr_ipv4 = "10.0.0.0/8"
from_port = 80
ip_protocol = "tcp"
to_port = 80
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.ec2.SecurityGroup;
import com.pulumi.aws.ec2.SecurityGroupArgs;
import com.pulumi.aws.vpc.SecurityGroupIngressRule;
import com.pulumi.aws.vpc.SecurityGroupIngressRuleArgs;
import java.util.ArrayList;
import java.util.Arrays;
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 SecurityGroup("example", SecurityGroupArgs.builder()
.name("example")
.description("example")
.vpcId(main.id())
.tags(Map.of("Name", "example"))
.build());
var exampleSecurityGroupIngressRule = new SecurityGroupIngressRule("exampleSecurityGroupIngressRule", SecurityGroupIngressRuleArgs.builder()
.securityGroupId(example.id())
.cidrIpv4("10.0.0.0/8")
.fromPort(80)
.ipProtocol("tcp")
.toPort(80)
.build());
}
}
resources:
example:
type: aws:ec2:SecurityGroup
properties:
name: example
description: example
vpcId: ${main.id}
tags:
Name: example
exampleSecurityGroupIngressRule:
type: aws:vpc:SecurityGroupIngressRule
name: example
properties:
securityGroupId: ${example.id}
cidrIpv4: 10.0.0.0/8
fromPort: 80
ipProtocol: tcp
toPort: 80
Import
Identity Schema
Required
id- (String) ID of the security group rule.
Optional
accountId(String) AWS Account where this resource is managed.region(String) Region where this resource is managed.
Using pulumi import, import security group ingress rules using the securityGroupRuleId. For example:
$ pulumi import aws:vpc/securityGroupIngressRule:SecurityGroupIngressRule example sgr-02108b27edd666983
Constructors
- SecurityGroupIngressRule(String name, {SecurityGroupIngressRuleArgs? args, CustomResourceOptions? options})
-
Creates a new SecurityGroupIngressRule.
nameThe Pulumi resource name.argsArguments used to configure this SecurityGroupIngressRule. The set of arguments for SecurityGroupIngressRule.optionsResource options controlling this resource's behavior. - SecurityGroupIngressRule.reference(String urn)
- Creates a typed reference to an existing SecurityGroupIngressRule resource.
Properties
-
arn
↔ Output<
String> -
ARN of the security group rule.
latefinal
-
childResources
→ Set<
Resource> -
finalinherited
-
cidrIpv4
↔ Output<
String?> -
The source IPv4 CIDR range.
latefinal
-
cidrIpv6
↔ Output<
String?> -
The source IPv6 CIDR range.
latefinal
-
completionSources
↔ Map<
String, IOutputCompletionSource> -
latefinalinherited
-
description
↔ Output<
String?> -
The security group rule description.
latefinal
-
fromPort
↔ Output<
int?> -
The start of port range for the TCP and UDP protocols, or an ICMP/ICMPv6 type.
latefinal
- hashCode → int
-
The hash code for this object.
no setterinherited
-
id
↔ Output<
String> -
getter/setter pairinherited
-
ipProtocol
↔ Output<
String> -
The IP protocol name or number. Use
-1to specify all protocols. Note that ifipProtocolis set to-1, it translates to all protocols, all port ranges, andfromPortandtoPortvalues should not be defined.latefinal - isCustom → bool
-
Returns whether this resource is provider-managed.
no setterinherited
- isProtected → bool
-
Returns whether this resource is protected from deletion.
no setterinherited
- isRemote → bool
-
Whether this resource is registered as remote.
no setterinherited
- isResourceReference → bool
-
Whether this instance represents a resource value returned over RPC.
finalinherited
-
prefixListId
↔ Output<
String?> -
The ID of the source prefix list.
latefinal
-
referencedSecurityGroupId
↔ Output<
String?> -
The source security group that is referenced in the rule.
latefinal
-
region
↔ Output<
String> -
Region where this resource will be managed. Defaults to the Region set in the provider configuration.
latefinal
-
resourceTransforms
→ List<
ResourceTransform> -
Inherited/explicit async transforms.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
securityGroupId
↔ Output<
String> -
The ID of the security group.
latefinal
-
securityGroupRuleId
↔ Output<
String> -
The ID of the security group rule.
latefinal
-
A map of tags to assign to the resource. If configured with a provider
defaultTagsconfiguration block present, tags with matching keys will overwrite those defined at the provider-level.latefinal -
A map of tags assigned to the resource, including those inherited from the provider
defaultTagsconfiguration block.latefinal -
toPort
↔ Output<
int?> -
The end of port range for the TCP and UDP protocols, or an ICMP/ICMPv6 code.
latefinal
-
transformations
→ List<
ResourceTransformation> -
Inherited/explicit legacy transformations.
no setterinherited
-
urn
↔ Output<
String> -
latefinalinherited
Methods
-
failId(
Object error) → void -
Completes this resource ID with an error when registration fails.
inherited
-
failOutputs(
Object error) → void -
Completes all output properties with
error.inherited -
failUrn(
Object error) → void -
Completes this resource URN with an error when registration fails.
inherited
-
getProvider(
String moduleMember) → ProviderResource? -
Returns provider for
moduleMember's package, if configured.inherited -
getResourceName(
) → String -
Returns this resource's logical name.
inherited
-
getResourceType(
) → String -
Returns this resource's Pulumi type token.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
registerOutput<
T> (String propertyName, {Object? decoder(Object?)?, bool isSecret = false}) → Output< T> -
Registers a dynamic output property for this resource.
inherited
-
resolveId(
String? value, {required bool isKnown}) → void -
Resolves the provider-assigned ID for this resource.
inherited
-
resolveOutputs(
Struct outputs) → void -
Resolves all output properties from a monitor response payload.
inherited
-
resolveUrn(
String value) → void -
Resolves this resource's URN once assigned by the engine.
inherited
-
serializeProperties(
Map< String, dynamic> properties) → Future<Struct> -
Serializes resource properties for RPC transmission.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
get(
String name, Input< String> id, {SecurityGroupIngressRuleState? state, CustomResourceOptions? options}) → SecurityGroupIngressRule -
Gets an existing SecurityGroupIngressRule resource's state with the given
nameandid.