AWS Amazon EC2 IPv4 Cidr Block Association
This page shows how to write Terraform and CloudFormation for Amazon EC2 IPv4 Cidr Block Association and write them securely.
aws_vpc_ipv4_cidr_block_association (Terraform)
The IPv4 Cidr Block Association in Amazon EC2 can be configured in Terraform with the resource name aws_vpc_ipv4_cidr_block_association
. The following sections describe 2 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "aws_vpc_ipv4_cidr_block_association" "secondary_cidr" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.1.0/16"
}
resource "aws_vpc_ipv4_cidr_block_association" "secondary_cidr" {
vpc_id = aws_vpc.main.id
resource "aws_vpc_ipv4_cidr_block_association" "cidr2" {
vpc_id = aws_vpc.vpc1.id
cidr_block = "172.2.0.0/16"
}
# nie chce tego przyjac
Parameters
-
cidr_block
required - string -
id
optional computed - string -
vpc_id
required - string -
timeouts
single block
Explanation in Terraform Registry
Provides a resource to associate additional IPv4 CIDR blocks with a VPC. When a VPC is created, a primary IPv4 CIDR block for the VPC must be specified. The
aws_vpc_ipv4_cidr_block_association
resource allows further IPv4 CIDR blocks to be added to the VPC.
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::VPCCidrBlock (CloudFormation)
The VPCCidrBlock in EC2 can be configured in CloudFormation with the resource name AWS::EC2::VPCCidrBlock
. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
Type: AWS::EC2::VPCCidrBlock
Properties:
CidrBlock: !GetAtt CidrGenerator.VpcCidrExtra1
VpcId: !Ref VPC
VPCExtraBlock2:
Type: AWS::EC2::VPCCidrBlock
Properties:
AmazonProvidedIpv6CidrBlock: true
VpcId: !Ref myVPC
myNetworkAcl:
Type: AWS::EC2::NetworkAcl
Type: AWS::EC2::VPCCidrBlock
Properties:
AmazonProvidedIpv6CidrBlock: true
VpcId: !Ref myVPC
myNetworkAcl:
Type: AWS::EC2::NetworkAcl
Type: AWS::EC2::VPCCidrBlock
Properties:
AmazonProvidedIpv6CidrBlock: true
VpcId: !Ref myVPC
myNetworkAcl:
Type: AWS::EC2::NetworkAcl
Type: AWS::EC2::VPCCidrBlock
Properties:
AmazonProvidedIpv6CidrBlock: true
# CidrBlock: 10.0.0.0/16
# VpcId: vpc-036dd04db74375617
VpcId: !Ref JKFirstCFVPC
"AWS::EC2::VPCCidrBlock": {
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-vpccidrblock.html",
"Properties": {
"AmazonProvidedIpv6CidrBlock": {
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-vpccidrblock.html#cfn-ec2-vpccidrblock-amazonprovidedipv6cidrblock",
"PrimitiveType": "Boolean",
"AWS::EC2::VPCCidrBlock": {
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-vpccidrblock.html",
"Properties": {
"AmazonProvidedIpv6CidrBlock": {
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-vpccidrblock.html#cfn-ec2-vpccidrblock-amazonprovidedipv6cidrblock",
"PrimitiveType": "Boolean",
"AWS::EC2::VPCCidrBlock": {
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-vpccidrblock.html",
"Properties": {
"AmazonProvidedIpv6CidrBlock": {
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-vpccidrblock.html#cfn-ec2-vpccidrblock-amazonprovidedipv6cidrblock",
"PrimitiveType": "Boolean",
"AWS::EC2::VPCCidrBlock": {
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-vpccidrblock.html",
"Properties": {
"AmazonProvidedIpv6CidrBlock": {
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-vpccidrblock.html#cfn-ec2-vpccidrblock-amazonprovidedipv6cidrblock",
"PrimitiveType": "Boolean",
"Type" : "AWS::EC2::VPCCidrBlock",
"Properties" : {
"AmazonProvidedIpv6CidrBlock" : true,
"VpcId" : { "Ref" : "ExampleVpc" }
}
},
Parameters
-
AmazonProvidedIpv6CidrBlock
optional - Boolean -
CidrBlock
optional - String -
Ipv6CidrBlock
optional - String -
Ipv6Pool
optional - String -
VpcId
required - String
Explanation in CloudFormation Registry
Associates a CIDR block with your VPC. You can only associate a single IPv6 CIDR block with your VPC. The IPv6 CIDR block size is fixed at /56.
For more information about associating CIDR blocks with your VPC and applicable restrictions, see VPC and Subnet Sizing in the Amazon Virtual Private Cloud User Guide.
Frequently asked questions
What is AWS Amazon EC2 IPv4 Cidr Block Association?
AWS Amazon EC2 IPv4 Cidr Block Association 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 IPv4 Cidr Block Association?
For Terraform, the karkarbhautik/certified-terraform-associate and lukdeboss/aws_tf source code examples are useful. See the Terraform Example section for further details.
For CloudFormation, the kennyk65/aws-teaching-demos, stelligent/cfn_nag and stelligent/cfn_nag source code examples are useful. See the CloudFormation Example section for further details.