getPrefixList

aws.ec2.getPrefixList provides details about a specific prefix list (PL) in the current region.

This can be used both to validate a prefix list given in a variable and to obtain the CIDR blocks (IP address ranges) for the associated AWS service. The latter may be useful e.g. for adding network ACL rules.

Example Usage

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
    public MyStack()
    {
        var privateS3VpcEndpoint = new Aws.Ec2.VpcEndpoint("privateS3VpcEndpoint", new Aws.Ec2.VpcEndpointArgs
        {
            VpcId = aws_vpc.Foo.Id,
            ServiceName = "com.amazonaws.us-west-2.s3",
        });
        var privateS3PrefixList = privateS3VpcEndpoint.PrefixListId.Apply(prefixListId => Aws.Ec2.GetPrefixList.InvokeAsync(new Aws.Ec2.GetPrefixListArgs
        {
            PrefixListId = prefixListId,
        }));
        var bar = new Aws.Ec2.NetworkAcl("bar", new Aws.Ec2.NetworkAclArgs
        {
            VpcId = aws_vpc.Foo.Id,
        });
        var privateS3NetworkAclRule = new Aws.Ec2.NetworkAclRule("privateS3NetworkAclRule", new Aws.Ec2.NetworkAclRuleArgs
        {
            NetworkAclId = bar.Id,
            RuleNumber = 200,
            Egress = false,
            Protocol = "tcp",
            RuleAction = "allow",
            CidrBlock = privateS3PrefixList.Apply(privateS3PrefixList => privateS3PrefixList.CidrBlocks[0]),
            FromPort = 443,
            ToPort = 443,
        });
    }

}
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/ec2"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		privateS3VpcEndpoint, err := ec2.NewVpcEndpoint(ctx, "privateS3VpcEndpoint", &ec2.VpcEndpointArgs{
			VpcId:       pulumi.Any(aws_vpc.Foo.Id),
			ServiceName: pulumi.String("com.amazonaws.us-west-2.s3"),
		})
		if err != nil {
			return err
		}
		bar, err := ec2.NewNetworkAcl(ctx, "bar", &ec2.NetworkAclArgs{
			VpcId: pulumi.Any(aws_vpc.Foo.Id),
		})
		if err != nil {
			return err
		}
		_, err = ec2.NewNetworkAclRule(ctx, "privateS3NetworkAclRule", &ec2.NetworkAclRuleArgs{
			NetworkAclId: bar.ID(),
			RuleNumber:   pulumi.Int(200),
			Egress:       pulumi.Bool(false),
			Protocol:     pulumi.String("tcp"),
			RuleAction:   pulumi.String("allow"),
			CidrBlock: privateS3PrefixList.ApplyT(func(privateS3PrefixList ec2.GetPrefixListResult) (string, error) {
				return privateS3PrefixList.CidrBlocks[0], nil
			}).(pulumi.StringOutput),
			FromPort: pulumi.Int(443),
			ToPort:   pulumi.Int(443),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
import pulumi
import pulumi_aws as aws

private_s3_vpc_endpoint = aws.ec2.VpcEndpoint("privateS3VpcEndpoint",
    vpc_id=aws_vpc["foo"]["id"],
    service_name="com.amazonaws.us-west-2.s3")
private_s3_prefix_list = private_s3_vpc_endpoint.prefix_list_id.apply(lambda prefix_list_id: aws.ec2.get_prefix_list(prefix_list_id=prefix_list_id))
bar = aws.ec2.NetworkAcl("bar", vpc_id=aws_vpc["foo"]["id"])
private_s3_network_acl_rule = aws.ec2.NetworkAclRule("privateS3NetworkAclRule",
    network_acl_id=bar.id,
    rule_number=200,
    egress=False,
    protocol="tcp",
    rule_action="allow",
    cidr_block=private_s3_prefix_list.cidr_blocks[0],
    from_port=443,
    to_port=443)
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const privateS3VpcEndpoint = new aws.ec2.VpcEndpoint("privateS3VpcEndpoint", {
    vpcId: aws_vpc.foo.id,
    serviceName: "com.amazonaws.us-west-2.s3",
});
const privateS3PrefixList = privateS3VpcEndpoint.prefixListId.apply(prefixListId => aws.ec2.getPrefixList({
    prefixListId: prefixListId,
}));
const bar = new aws.ec2.NetworkAcl("bar", {vpcId: aws_vpc.foo.id});
const privateS3NetworkAclRule = new aws.ec2.NetworkAclRule("privateS3NetworkAclRule", {
    networkAclId: bar.id,
    ruleNumber: 200,
    egress: false,
    protocol: "tcp",
    ruleAction: "allow",
    cidrBlock: privateS3PrefixList.cidrBlocks[0],
    fromPort: 443,
    toPort: 443,
});

Filter

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
    public MyStack()
    {
        var test = Output.Create(Aws.Ec2.GetPrefixList.InvokeAsync(new Aws.Ec2.GetPrefixListArgs
        {
            Filters = 
            {
                new Aws.Ec2.Inputs.GetPrefixListFilterArgs
                {
                    Name = "prefix-list-id",
                    Values = 
                    {
                        "pl-68a54001",
                    },
                },
            },
        }));
    }

}
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/ec2"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := ec2.GetPrefixList(ctx, &ec2.GetPrefixListArgs{
			Filters: []ec2.GetPrefixListFilter{
				ec2.GetPrefixListFilter{
					Name: "prefix-list-id",
					Values: []string{
						"pl-68a54001",
					},
				},
			},
		}, nil)
		if err != nil {
			return err
		}
		return nil
	})
}
import pulumi
import pulumi_aws as aws

test = aws.ec2.get_prefix_list(filters=[aws.ec2.GetPrefixListFilterArgs(
    name="prefix-list-id",
    values=["pl-68a54001"],
)])
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const test = pulumi.output(aws.ec2.getPrefixList({
    filters: [{
        name: "prefix-list-id",
        values: ["pl-68a54001"],
    }],
}, { async: true }));

Using getPrefixList

function getPrefixList(args: GetPrefixListArgs, opts?: InvokeOptions): Promise<GetPrefixListResult>
def get_prefix_list(filters: Optional[Sequence[GetPrefixListFilter]] = None,
                    name: Optional[str] = None,
                    prefix_list_id: Optional[str] = None,
                    opts: Optional[InvokeOptions] = None) -> GetPrefixListResult
func GetPrefixList(ctx *Context, args *GetPrefixListArgs, opts ...InvokeOption) (*GetPrefixListResult, error)

Note: This function is named GetPrefixList in the Go SDK.

public static class GetPrefixList {
    public static Task<GetPrefixListResult> InvokeAsync(GetPrefixListArgs args, InvokeOptions? opts = null)
}

The following arguments are supported:

Filters List<GetPrefixListFilter>
Configuration block(s) for filtering. Detailed below.
Name string
The name of the filter field. Valid values can be found in the EC2 DescribePrefixLists API Reference.
PrefixListId string
The ID of the prefix list to select.
Filters []GetPrefixListFilter
Configuration block(s) for filtering. Detailed below.
Name string
The name of the filter field. Valid values can be found in the EC2 DescribePrefixLists API Reference.
PrefixListId string
The ID of the prefix list to select.
filters GetPrefixListFilter[]
Configuration block(s) for filtering. Detailed below.
name string
The name of the filter field. Valid values can be found in the EC2 DescribePrefixLists API Reference.
prefixListId string
The ID of the prefix list to select.
filters Sequence[GetPrefixListFilter]
Configuration block(s) for filtering. Detailed below.
name str
The name of the filter field. Valid values can be found in the EC2 DescribePrefixLists API Reference.
prefix_list_id str
The ID of the prefix list to select.

getPrefixList Result

The following output properties are available:

CidrBlocks List<string>
The list of CIDR blocks for the AWS service associated with the prefix list.
Id string
The provider-assigned unique ID for this managed resource.
Name string
The name of the selected prefix list.
Filters List<GetPrefixListFilter>
PrefixListId string
CidrBlocks []string
The list of CIDR blocks for the AWS service associated with the prefix list.
Id string
The provider-assigned unique ID for this managed resource.
Name string
The name of the selected prefix list.
Filters []GetPrefixListFilter
PrefixListId string
cidrBlocks string[]
The list of CIDR blocks for the AWS service associated with the prefix list.
id string
The provider-assigned unique ID for this managed resource.
name string
The name of the selected prefix list.
filters GetPrefixListFilter[]
prefixListId string
cidr_blocks Sequence[str]
The list of CIDR blocks for the AWS service associated with the prefix list.
id str
The provider-assigned unique ID for this managed resource.
name str
The name of the selected prefix list.
filters Sequence[GetPrefixListFilter]
prefix_list_id str

Supporting Types

GetPrefixListFilter

Name string
The name of the filter field. Valid values can be found in the EC2 DescribePrefixLists API Reference.
Values List<string>
Set of values that are accepted for the given filter field. Results will be selected if any given value matches.
Name string
The name of the filter field. Valid values can be found in the EC2 DescribePrefixLists API Reference.
Values []string
Set of values that are accepted for the given filter field. Results will be selected if any given value matches.
name string
The name of the filter field. Valid values can be found in the EC2 DescribePrefixLists API Reference.
values string[]
Set of values that are accepted for the given filter field. Results will be selected if any given value matches.
name str
The name of the filter field. Valid values can be found in the EC2 DescribePrefixLists API Reference.
values Sequence[str]
Set of values that are accepted for the given filter field. Results will be selected if any given value matches.

Package Details

Repository
https://github.com/pulumi/pulumi-aws
License
Apache-2.0
Notes
This Pulumi package is based on the aws Terraform Provider.