AWS Amazon EC2 Managed Prefix List

This page shows how to write Terraform and CloudFormation for Amazon EC2 Managed Prefix List and write them securely.

aws_ec2_managed_prefix_list (Terraform)

The Managed Prefix List in Amazon EC2 can be configured in Terraform with the resource name aws_ec2_managed_prefix_list. The following sections describe 4 examples of how to use the resource and its parameters.

Example Usage from GitHub

pref-lists-create.tf#L4
resource "aws_ec2_managed_prefix_list" "prod_euw2_euw1" {
  provider = aws.eu-west-2

  name           = "pfx-euw1-prod"
  address_family = "IPv4"
  max_entries    = 5
prefix-lists.tf#L1
resource "aws_ec2_managed_prefix_list" "ipv4" {
  for_each = {
    for prefix_list in local.config.prefix_lists.ipv4 :
    prefix_list.name => prefix_list
  }

main.tf#L1
resource "aws_ec2_managed_prefix_list" "home-ip-prefix-list" {
  name           = "Home IP address (created and updated with terraform)"
  address_family = "IPv4"
  max_entries    = 1

  entry {
route-tables.tf#L2
resource "aws_ec2_managed_prefix_list" "internal_networks" {
  name           = "Internal Networks"
  address_family = "IPv4"
  max_entries    = length(var.internal_networks)

  dynamic "entry" {

Review your Terraform file for AWS best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

Explanation in Terraform Registry

Provides a managed prefix list resource.

NOTE on Managed Prefix Lists and Managed Prefix List Entries: Terraform currently provides both a standalone Managed Prefix List Entry resource (a single entry), and a Managed Prefix List resource with entries defined in-line. At this time you cannot use a Managed Prefix List with in-line rules in conjunction with any Managed Prefix List Entry resources. Doing so will cause a conflict of entries and will overwrite entries. NOTE on max_entries: When you reference a Prefix List in a resource, the maximum number of entries for the prefix lists counts as the same number of rules or entries for the resource. For example, if you create a prefix list with a maximum of 20 entries and you reference that prefix list in a security group rule, this counts as 20 rules for the security group.

Tips: Best Practices for The Other AWS Amazon EC2 Resources

In addition to the aws_default_vpc, AWS Amazon EC2 has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.

risk-label

aws_default_vpc

Ensure to avoid using default VPC

It is better to define the own VPC and use it.

risk-label

aws_network_acl_rule

Ensure your network ACL rule blocks unwanted inbound traffic

It is better to block unwanted inbound traffic.

risk-label

aws_ebs_volume

Ensure to use a customer-managed key for EBS volume encryption

It is better to use a customer-managed key for EBS volume encryption. It can be gain more control over the encryption by using customer-managed keys (CMK).

risk-label

aws_instance

Ensure to avoid storing AWS access keys in user data

It is better to avoid storing AWS access keys in user data. `aws_iam_instance_profile` could be used instead.

risk-label

aws_security_group

Ensure your security group blocks unwanted inbound traffic

It is better to block unwanted inbound traffic.

Review your AWS Amazon EC2 settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

AWS::EC2::PrefixList (CloudFormation)

The PrefixList in EC2 can be configured in CloudFormation with the resource name AWS::EC2::PrefixList. The following sections describe 9 examples of how to use the resource and its parameters.

Example Usage from GitHub

1-VPC.yml#L549
    Type: AWS::EC2::PrefixList
    Properties:
      PrefixListName: !Join
          - '-'
          - - Fn::ImportValue: !Sub "${StackCore}-ProjectUpper"
            - Fn::ImportValue: !Sub "${StackCore}-EnvironmentUpper"
1-VPC.yml#L549
    Type: AWS::EC2::PrefixList
    Properties:
      PrefixListName: !Join
          - '-'
          - - Fn::ImportValue: !Sub "${StackCore}-ProjectUpper"
            - Fn::ImportValue: !Sub "${StackCore}-EnvironmentUpper"
original-template.yml#L248
    Type: "AWS::EC2::PrefixList"
    Properties:
      AddressFamily: "IPv4"
      PrefixListName: !Sub "com.amazonaws.${awsregion}.dynamodb"
      Entries:
        -
main.yml#L219
    Type: AWS::EC2::PrefixList
    Properties:
      PrefixListName: "WebServerPrefixList"
      AddressFamily: "IPv4"
      MaxEntries: 10
      Entries:
FIXEngineApplication.yml#L1051
    Type: AWS::EC2::PrefixList
  FIXServerDNSNameParam:
    Condition: ''
    Properties:
      Description: !Join
        - ''
awsResouceIconMatches.json#L258
        "resourceType": "AWS::EC2::PrefixList",
        "filePath": null
      },
      {
        "resourceType": "AWS::EC2::TransitGatewayRoute",
        "filePath": "icons/aws/Service/Arch_Networking-Content/64/Arch_AWS-Transit-Gateway_64@5x.png"
template.json#L2387
    "AWS::EC2::PrefixList": {
      "Type": "AWS::EC2::PrefixList",
      "Properties": {}
    },
    "AWS::EC2::VPC": {
      "Type": "AWS::EC2::VPC",
FIXEngineVPCApplication.json#L1801
            "Type": "AWS::EC2::PrefixList"
        },
        "FIXServerDNSNameParam": {
            "Condition": "",
            "Properties": {
                "Description": {
FIXEngineApplication.json#L1777
            "Type": "AWS::EC2::PrefixList"
        },
        "FIXServerDNSNameParam": {
            "Condition": "",
            "Properties": {
                "Description": {

Parameters

Explanation in CloudFormation Registry

Specifies a managed prefix list. You can add one or more entries to the prefix list. Each entry consists of a CIDR block and an optional description.

You must specify the maximum number of entries for the prefix list. The maximum number of entries cannot be changed later.

Frequently asked questions

What is AWS Amazon EC2 Managed Prefix List?

AWS Amazon EC2 Managed Prefix List is a resource for Amazon EC2 of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.

Where can I find the example code for the AWS Amazon EC2 Managed Prefix List?

For Terraform, the danielmacuare/aws-net, tedilabs/fastcampus-devops and thiagoeh/aws-iac source code examples are useful. See the Terraform Example section for further details.

For CloudFormation, the K-Masopa/CloudOps-reg-za-iac-sagesi, K-Masopa/SageSI-IaC and payne911/libgdx-desktop-multiplayer-template source code examples are useful. See the CloudFormation Example section for further details.