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

c3-vpc-instance.tf#L11
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
20-vpc.tf#L9
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

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 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.

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::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

base-vpc-example-improved.template.yml#L71
    Type: AWS::EC2::VPCCidrBlock
    Properties:
      CidrBlock: !GetAtt CidrGenerator.VpcCidrExtra1
      VpcId: !Ref VPC

  VPCExtraBlock2:
ec2_networkaclentry_protocol_icmpv6.yml#L11
    Type: AWS::EC2::VPCCidrBlock
    Properties:
      AmazonProvidedIpv6CidrBlock: true
      VpcId: !Ref myVPC
  myNetworkAcl:
    Type: AWS::EC2::NetworkAcl
ec2_networkaclentry_deny_full_ipv6_cidr_range.yml#L11
    Type: AWS::EC2::VPCCidrBlock
    Properties:
      AmazonProvidedIpv6CidrBlock: true
      VpcId: !Ref myVPC
  myNetworkAcl:
    Type: AWS::EC2::NetworkAcl
ec2_networkaclentry_protocol_icmpv6_missing_icmp.yml#L11
    Type: AWS::EC2::VPCCidrBlock
    Properties:
      AmazonProvidedIpv6CidrBlock: true
      VpcId: !Ref myVPC
  myNetworkAcl:
    Type: AWS::EC2::NetworkAcl
create-vpc.yml#L10
    Type: AWS::EC2::VPCCidrBlock
    Properties:
      AmazonProvidedIpv6CidrBlock: true
#      CidrBlock: 10.0.0.0/16
#      VpcId: vpc-036dd04db74375617
      VpcId: !Ref JKFirstCFVPC
Ec2VpcCidrBlockSpecification.json#L3
    "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",
Ec2VpcCidrBlockSpecification.json#L3
    "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",
EC2VPCCidrBlockSpecification.json#L3
    "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",
Ec2VpcCidrBlockSpecification.json#L3
    "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",
cidr.json#L12
        "Type" : "AWS::EC2::VPCCidrBlock",
        "Properties" : {
          "AmazonProvidedIpv6CidrBlock" : true,
          "VpcId" : { "Ref" : "ExampleVpc" }
        }
      },

Parameters

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.