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
resource "aws_ec2_managed_prefix_list" "prod_euw2_euw1" {
provider = aws.eu-west-2
name = "pfx-euw1-prod"
address_family = "IPv4"
max_entries = 5
resource "aws_ec2_managed_prefix_list" "ipv4" {
for_each = {
for prefix_list in local.config.prefix_lists.ipv4 :
prefix_list.name => prefix_list
}
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 {
resource "aws_ec2_managed_prefix_list" "internal_networks" {
name = "Internal Networks"
address_family = "IPv4"
max_entries = length(var.internal_networks)
dynamic "entry" {
Parameters
-
address_family
required - string -
arn
optional computed - string -
id
optional computed - string -
max_entries
required - number -
name
required - string -
owner_id
optional computed - string -
tags
optional - map from string to string -
version
optional computed - number -
entry
set block-
cidr
required - string -
description
optional - string
-
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.
aws_default_vpc
Ensure to avoid using default VPC
It is better to define the own VPC and use it.
aws_network_acl_rule
Ensure your network ACL rule blocks unwanted inbound traffic
It is better to block unwanted inbound traffic.
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).
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.
aws_security_group
Ensure your security group blocks unwanted inbound traffic
It is better to block unwanted inbound traffic.
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
Type: AWS::EC2::PrefixList
Properties:
PrefixListName: !Join
- '-'
- - Fn::ImportValue: !Sub "${StackCore}-ProjectUpper"
- Fn::ImportValue: !Sub "${StackCore}-EnvironmentUpper"
Type: AWS::EC2::PrefixList
Properties:
PrefixListName: !Join
- '-'
- - Fn::ImportValue: !Sub "${StackCore}-ProjectUpper"
- Fn::ImportValue: !Sub "${StackCore}-EnvironmentUpper"
Type: "AWS::EC2::PrefixList"
Properties:
AddressFamily: "IPv4"
PrefixListName: !Sub "com.amazonaws.${awsregion}.dynamodb"
Entries:
-
Type: AWS::EC2::PrefixList
Properties:
PrefixListName: "WebServerPrefixList"
AddressFamily: "IPv4"
MaxEntries: 10
Entries:
Type: AWS::EC2::PrefixList
FIXServerDNSNameParam:
Condition: ''
Properties:
Description: !Join
- ''
"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"
"AWS::EC2::PrefixList": {
"Type": "AWS::EC2::PrefixList",
"Properties": {}
},
"AWS::EC2::VPC": {
"Type": "AWS::EC2::VPC",
"Type": "AWS::EC2::PrefixList"
},
"FIXServerDNSNameParam": {
"Condition": "",
"Properties": {
"Description": {
"Type": "AWS::EC2::PrefixList"
},
"FIXServerDNSNameParam": {
"Condition": "",
"Properties": {
"Description": {
Parameters
-
PrefixListName
required - String -
AddressFamily
required - String -
MaxEntries
required - Integer -
Tags
optional - List of Tag -
Entries
optional - List of Entry
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.