1. Packages
  2. AWS
  3. API Docs
  4. ec2
  5. VpcIpv4CidrBlockAssociation
AWS v6.73.0 published on Wednesday, Mar 19, 2025 by Pulumi

aws.ec2.VpcIpv4CidrBlockAssociation

Explore with Pulumi AI

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.ec2.VpcIpv4CidrBlockAssociation resource allows further IPv4 CIDR blocks to be added to the VPC.

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const main = new aws.ec2.Vpc("main", {cidrBlock: "10.0.0.0/16"});
const secondaryCidr = new aws.ec2.VpcIpv4CidrBlockAssociation("secondary_cidr", {
    vpcId: main.id,
    cidrBlock: "172.20.0.0/16",
});
Copy
import pulumi
import pulumi_aws as aws

main = aws.ec2.Vpc("main", cidr_block="10.0.0.0/16")
secondary_cidr = aws.ec2.VpcIpv4CidrBlockAssociation("secondary_cidr",
    vpc_id=main.id,
    cidr_block="172.20.0.0/16")
Copy
package main

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

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		main, err := ec2.NewVpc(ctx, "main", &ec2.VpcArgs{
			CidrBlock: pulumi.String("10.0.0.0/16"),
		})
		if err != nil {
			return err
		}
		_, err = ec2.NewVpcIpv4CidrBlockAssociation(ctx, "secondary_cidr", &ec2.VpcIpv4CidrBlockAssociationArgs{
			VpcId:     main.ID(),
			CidrBlock: pulumi.String("172.20.0.0/16"),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;

return await Deployment.RunAsync(() => 
{
    var main = new Aws.Ec2.Vpc("main", new()
    {
        CidrBlock = "10.0.0.0/16",
    });

    var secondaryCidr = new Aws.Ec2.VpcIpv4CidrBlockAssociation("secondary_cidr", new()
    {
        VpcId = main.Id,
        CidrBlock = "172.20.0.0/16",
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.ec2.Vpc;
import com.pulumi.aws.ec2.VpcArgs;
import com.pulumi.aws.ec2.VpcIpv4CidrBlockAssociation;
import com.pulumi.aws.ec2.VpcIpv4CidrBlockAssociationArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var main = new Vpc("main", VpcArgs.builder()
            .cidrBlock("10.0.0.0/16")
            .build());

        var secondaryCidr = new VpcIpv4CidrBlockAssociation("secondaryCidr", VpcIpv4CidrBlockAssociationArgs.builder()
            .vpcId(main.id())
            .cidrBlock("172.20.0.0/16")
            .build());

    }
}
Copy
resources:
  main:
    type: aws:ec2:Vpc
    properties:
      cidrBlock: 10.0.0.0/16
  secondaryCidr:
    type: aws:ec2:VpcIpv4CidrBlockAssociation
    name: secondary_cidr
    properties:
      vpcId: ${main.id}
      cidrBlock: 172.20.0.0/16
Copy

Create VpcIpv4CidrBlockAssociation Resource

Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

Constructor syntax

new VpcIpv4CidrBlockAssociation(name: string, args: VpcIpv4CidrBlockAssociationArgs, opts?: CustomResourceOptions);
@overload
def VpcIpv4CidrBlockAssociation(resource_name: str,
                                args: VpcIpv4CidrBlockAssociationArgs,
                                opts: Optional[ResourceOptions] = None)

@overload
def VpcIpv4CidrBlockAssociation(resource_name: str,
                                opts: Optional[ResourceOptions] = None,
                                vpc_id: Optional[str] = None,
                                cidr_block: Optional[str] = None,
                                ipv4_ipam_pool_id: Optional[str] = None,
                                ipv4_netmask_length: Optional[int] = None)
func NewVpcIpv4CidrBlockAssociation(ctx *Context, name string, args VpcIpv4CidrBlockAssociationArgs, opts ...ResourceOption) (*VpcIpv4CidrBlockAssociation, error)
public VpcIpv4CidrBlockAssociation(string name, VpcIpv4CidrBlockAssociationArgs args, CustomResourceOptions? opts = null)
public VpcIpv4CidrBlockAssociation(String name, VpcIpv4CidrBlockAssociationArgs args)
public VpcIpv4CidrBlockAssociation(String name, VpcIpv4CidrBlockAssociationArgs args, CustomResourceOptions options)
type: aws:ec2:VpcIpv4CidrBlockAssociation
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

Parameters

name This property is required. string
The unique name of the resource.
args This property is required. VpcIpv4CidrBlockAssociationArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name This property is required. str
The unique name of the resource.
args This property is required. VpcIpv4CidrBlockAssociationArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name This property is required. string
The unique name of the resource.
args This property is required. VpcIpv4CidrBlockAssociationArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name This property is required. string
The unique name of the resource.
args This property is required. VpcIpv4CidrBlockAssociationArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name This property is required. String
The unique name of the resource.
args This property is required. VpcIpv4CidrBlockAssociationArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

Constructor example

The following reference example uses placeholder values for all input properties.

var vpcIpv4CidrBlockAssociationResource = new Aws.Ec2.VpcIpv4CidrBlockAssociation("vpcIpv4CidrBlockAssociationResource", new()
{
    VpcId = "string",
    CidrBlock = "string",
    Ipv4IpamPoolId = "string",
    Ipv4NetmaskLength = 0,
});
Copy
example, err := ec2.NewVpcIpv4CidrBlockAssociation(ctx, "vpcIpv4CidrBlockAssociationResource", &ec2.VpcIpv4CidrBlockAssociationArgs{
	VpcId:             pulumi.String("string"),
	CidrBlock:         pulumi.String("string"),
	Ipv4IpamPoolId:    pulumi.String("string"),
	Ipv4NetmaskLength: pulumi.Int(0),
})
Copy
var vpcIpv4CidrBlockAssociationResource = new VpcIpv4CidrBlockAssociation("vpcIpv4CidrBlockAssociationResource", VpcIpv4CidrBlockAssociationArgs.builder()
    .vpcId("string")
    .cidrBlock("string")
    .ipv4IpamPoolId("string")
    .ipv4NetmaskLength(0)
    .build());
Copy
vpc_ipv4_cidr_block_association_resource = aws.ec2.VpcIpv4CidrBlockAssociation("vpcIpv4CidrBlockAssociationResource",
    vpc_id="string",
    cidr_block="string",
    ipv4_ipam_pool_id="string",
    ipv4_netmask_length=0)
Copy
const vpcIpv4CidrBlockAssociationResource = new aws.ec2.VpcIpv4CidrBlockAssociation("vpcIpv4CidrBlockAssociationResource", {
    vpcId: "string",
    cidrBlock: "string",
    ipv4IpamPoolId: "string",
    ipv4NetmaskLength: 0,
});
Copy
type: aws:ec2:VpcIpv4CidrBlockAssociation
properties:
    cidrBlock: string
    ipv4IpamPoolId: string
    ipv4NetmaskLength: 0
    vpcId: string
Copy

VpcIpv4CidrBlockAssociation Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

The VpcIpv4CidrBlockAssociation resource accepts the following input properties:

VpcId
This property is required.
Changes to this property will trigger replacement.
string
The ID of the VPC to make the association with.
CidrBlock Changes to this property will trigger replacement. string
The IPv4 CIDR block for the VPC. CIDR can be explicitly set or it can be derived from IPAM using ipv4_netmask_length.
Ipv4IpamPoolId Changes to this property will trigger replacement. string
The ID of an IPv4 IPAM pool you want to use for allocating this VPC's CIDR. IPAM is a VPC feature that you can use to automate your IP address management workflows including assigning, tracking, troubleshooting, and auditing IP addresses across AWS Regions and accounts. Using IPAM you can monitor IP address usage throughout your AWS Organization.
Ipv4NetmaskLength Changes to this property will trigger replacement. int
The netmask length of the IPv4 CIDR you want to allocate to this VPC. Requires specifying a ipv4_ipam_pool_id.
VpcId
This property is required.
Changes to this property will trigger replacement.
string
The ID of the VPC to make the association with.
CidrBlock Changes to this property will trigger replacement. string
The IPv4 CIDR block for the VPC. CIDR can be explicitly set or it can be derived from IPAM using ipv4_netmask_length.
Ipv4IpamPoolId Changes to this property will trigger replacement. string
The ID of an IPv4 IPAM pool you want to use for allocating this VPC's CIDR. IPAM is a VPC feature that you can use to automate your IP address management workflows including assigning, tracking, troubleshooting, and auditing IP addresses across AWS Regions and accounts. Using IPAM you can monitor IP address usage throughout your AWS Organization.
Ipv4NetmaskLength Changes to this property will trigger replacement. int
The netmask length of the IPv4 CIDR you want to allocate to this VPC. Requires specifying a ipv4_ipam_pool_id.
vpcId
This property is required.
Changes to this property will trigger replacement.
String
The ID of the VPC to make the association with.
cidrBlock Changes to this property will trigger replacement. String
The IPv4 CIDR block for the VPC. CIDR can be explicitly set or it can be derived from IPAM using ipv4_netmask_length.
ipv4IpamPoolId Changes to this property will trigger replacement. String
The ID of an IPv4 IPAM pool you want to use for allocating this VPC's CIDR. IPAM is a VPC feature that you can use to automate your IP address management workflows including assigning, tracking, troubleshooting, and auditing IP addresses across AWS Regions and accounts. Using IPAM you can monitor IP address usage throughout your AWS Organization.
ipv4NetmaskLength Changes to this property will trigger replacement. Integer
The netmask length of the IPv4 CIDR you want to allocate to this VPC. Requires specifying a ipv4_ipam_pool_id.
vpcId
This property is required.
Changes to this property will trigger replacement.
string
The ID of the VPC to make the association with.
cidrBlock Changes to this property will trigger replacement. string
The IPv4 CIDR block for the VPC. CIDR can be explicitly set or it can be derived from IPAM using ipv4_netmask_length.
ipv4IpamPoolId Changes to this property will trigger replacement. string
The ID of an IPv4 IPAM pool you want to use for allocating this VPC's CIDR. IPAM is a VPC feature that you can use to automate your IP address management workflows including assigning, tracking, troubleshooting, and auditing IP addresses across AWS Regions and accounts. Using IPAM you can monitor IP address usage throughout your AWS Organization.
ipv4NetmaskLength Changes to this property will trigger replacement. number
The netmask length of the IPv4 CIDR you want to allocate to this VPC. Requires specifying a ipv4_ipam_pool_id.
vpc_id
This property is required.
Changes to this property will trigger replacement.
str
The ID of the VPC to make the association with.
cidr_block Changes to this property will trigger replacement. str
The IPv4 CIDR block for the VPC. CIDR can be explicitly set or it can be derived from IPAM using ipv4_netmask_length.
ipv4_ipam_pool_id Changes to this property will trigger replacement. str
The ID of an IPv4 IPAM pool you want to use for allocating this VPC's CIDR. IPAM is a VPC feature that you can use to automate your IP address management workflows including assigning, tracking, troubleshooting, and auditing IP addresses across AWS Regions and accounts. Using IPAM you can monitor IP address usage throughout your AWS Organization.
ipv4_netmask_length Changes to this property will trigger replacement. int
The netmask length of the IPv4 CIDR you want to allocate to this VPC. Requires specifying a ipv4_ipam_pool_id.
vpcId
This property is required.
Changes to this property will trigger replacement.
String
The ID of the VPC to make the association with.
cidrBlock Changes to this property will trigger replacement. String
The IPv4 CIDR block for the VPC. CIDR can be explicitly set or it can be derived from IPAM using ipv4_netmask_length.
ipv4IpamPoolId Changes to this property will trigger replacement. String
The ID of an IPv4 IPAM pool you want to use for allocating this VPC's CIDR. IPAM is a VPC feature that you can use to automate your IP address management workflows including assigning, tracking, troubleshooting, and auditing IP addresses across AWS Regions and accounts. Using IPAM you can monitor IP address usage throughout your AWS Organization.
ipv4NetmaskLength Changes to this property will trigger replacement. Number
The netmask length of the IPv4 CIDR you want to allocate to this VPC. Requires specifying a ipv4_ipam_pool_id.

Outputs

All input properties are implicitly available as output properties. Additionally, the VpcIpv4CidrBlockAssociation resource produces the following output properties:

Id string
The provider-assigned unique ID for this managed resource.
Id string
The provider-assigned unique ID for this managed resource.
id String
The provider-assigned unique ID for this managed resource.
id string
The provider-assigned unique ID for this managed resource.
id str
The provider-assigned unique ID for this managed resource.
id String
The provider-assigned unique ID for this managed resource.

Look up Existing VpcIpv4CidrBlockAssociation Resource

Get an existing VpcIpv4CidrBlockAssociation resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: VpcIpv4CidrBlockAssociationState, opts?: CustomResourceOptions): VpcIpv4CidrBlockAssociation
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        cidr_block: Optional[str] = None,
        ipv4_ipam_pool_id: Optional[str] = None,
        ipv4_netmask_length: Optional[int] = None,
        vpc_id: Optional[str] = None) -> VpcIpv4CidrBlockAssociation
func GetVpcIpv4CidrBlockAssociation(ctx *Context, name string, id IDInput, state *VpcIpv4CidrBlockAssociationState, opts ...ResourceOption) (*VpcIpv4CidrBlockAssociation, error)
public static VpcIpv4CidrBlockAssociation Get(string name, Input<string> id, VpcIpv4CidrBlockAssociationState? state, CustomResourceOptions? opts = null)
public static VpcIpv4CidrBlockAssociation get(String name, Output<String> id, VpcIpv4CidrBlockAssociationState state, CustomResourceOptions options)
resources:  _:    type: aws:ec2:VpcIpv4CidrBlockAssociation    get:      id: ${id}
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
The following state arguments are supported:
CidrBlock Changes to this property will trigger replacement. string
The IPv4 CIDR block for the VPC. CIDR can be explicitly set or it can be derived from IPAM using ipv4_netmask_length.
Ipv4IpamPoolId Changes to this property will trigger replacement. string
The ID of an IPv4 IPAM pool you want to use for allocating this VPC's CIDR. IPAM is a VPC feature that you can use to automate your IP address management workflows including assigning, tracking, troubleshooting, and auditing IP addresses across AWS Regions and accounts. Using IPAM you can monitor IP address usage throughout your AWS Organization.
Ipv4NetmaskLength Changes to this property will trigger replacement. int
The netmask length of the IPv4 CIDR you want to allocate to this VPC. Requires specifying a ipv4_ipam_pool_id.
VpcId Changes to this property will trigger replacement. string
The ID of the VPC to make the association with.
CidrBlock Changes to this property will trigger replacement. string
The IPv4 CIDR block for the VPC. CIDR can be explicitly set or it can be derived from IPAM using ipv4_netmask_length.
Ipv4IpamPoolId Changes to this property will trigger replacement. string
The ID of an IPv4 IPAM pool you want to use for allocating this VPC's CIDR. IPAM is a VPC feature that you can use to automate your IP address management workflows including assigning, tracking, troubleshooting, and auditing IP addresses across AWS Regions and accounts. Using IPAM you can monitor IP address usage throughout your AWS Organization.
Ipv4NetmaskLength Changes to this property will trigger replacement. int
The netmask length of the IPv4 CIDR you want to allocate to this VPC. Requires specifying a ipv4_ipam_pool_id.
VpcId Changes to this property will trigger replacement. string
The ID of the VPC to make the association with.
cidrBlock Changes to this property will trigger replacement. String
The IPv4 CIDR block for the VPC. CIDR can be explicitly set or it can be derived from IPAM using ipv4_netmask_length.
ipv4IpamPoolId Changes to this property will trigger replacement. String
The ID of an IPv4 IPAM pool you want to use for allocating this VPC's CIDR. IPAM is a VPC feature that you can use to automate your IP address management workflows including assigning, tracking, troubleshooting, and auditing IP addresses across AWS Regions and accounts. Using IPAM you can monitor IP address usage throughout your AWS Organization.
ipv4NetmaskLength Changes to this property will trigger replacement. Integer
The netmask length of the IPv4 CIDR you want to allocate to this VPC. Requires specifying a ipv4_ipam_pool_id.
vpcId Changes to this property will trigger replacement. String
The ID of the VPC to make the association with.
cidrBlock Changes to this property will trigger replacement. string
The IPv4 CIDR block for the VPC. CIDR can be explicitly set or it can be derived from IPAM using ipv4_netmask_length.
ipv4IpamPoolId Changes to this property will trigger replacement. string
The ID of an IPv4 IPAM pool you want to use for allocating this VPC's CIDR. IPAM is a VPC feature that you can use to automate your IP address management workflows including assigning, tracking, troubleshooting, and auditing IP addresses across AWS Regions and accounts. Using IPAM you can monitor IP address usage throughout your AWS Organization.
ipv4NetmaskLength Changes to this property will trigger replacement. number
The netmask length of the IPv4 CIDR you want to allocate to this VPC. Requires specifying a ipv4_ipam_pool_id.
vpcId Changes to this property will trigger replacement. string
The ID of the VPC to make the association with.
cidr_block Changes to this property will trigger replacement. str
The IPv4 CIDR block for the VPC. CIDR can be explicitly set or it can be derived from IPAM using ipv4_netmask_length.
ipv4_ipam_pool_id Changes to this property will trigger replacement. str
The ID of an IPv4 IPAM pool you want to use for allocating this VPC's CIDR. IPAM is a VPC feature that you can use to automate your IP address management workflows including assigning, tracking, troubleshooting, and auditing IP addresses across AWS Regions and accounts. Using IPAM you can monitor IP address usage throughout your AWS Organization.
ipv4_netmask_length Changes to this property will trigger replacement. int
The netmask length of the IPv4 CIDR you want to allocate to this VPC. Requires specifying a ipv4_ipam_pool_id.
vpc_id Changes to this property will trigger replacement. str
The ID of the VPC to make the association with.
cidrBlock Changes to this property will trigger replacement. String
The IPv4 CIDR block for the VPC. CIDR can be explicitly set or it can be derived from IPAM using ipv4_netmask_length.
ipv4IpamPoolId Changes to this property will trigger replacement. String
The ID of an IPv4 IPAM pool you want to use for allocating this VPC's CIDR. IPAM is a VPC feature that you can use to automate your IP address management workflows including assigning, tracking, troubleshooting, and auditing IP addresses across AWS Regions and accounts. Using IPAM you can monitor IP address usage throughout your AWS Organization.
ipv4NetmaskLength Changes to this property will trigger replacement. Number
The netmask length of the IPv4 CIDR you want to allocate to this VPC. Requires specifying a ipv4_ipam_pool_id.
vpcId Changes to this property will trigger replacement. String
The ID of the VPC to make the association with.

Import

or

or

Using pulumi import, import aws_vpc_ipv4_cidr_block_association using the VPC CIDR association ID and optionally the IPv4 IPAM pool ID and netmask length. For example:

$ pulumi import aws:ec2/vpcIpv4CidrBlockAssociation:VpcIpv4CidrBlockAssociation example vpc-cidr-assoc-021e8461d70ed08be
Copy

or

$ pulumi import aws:ec2/vpcIpv4CidrBlockAssociation:VpcIpv4CidrBlockAssociation example vpc-cidr-assoc-021e8461d70ed08be,ipam-pool-0a07c432810393463
Copy

or

$ pulumi import aws:ec2/vpcIpv4CidrBlockAssociation:VpcIpv4CidrBlockAssociation example vpc-cidr-assoc-021e8461d70ed08be,ipam-pool-0a07c432810393463,28
Copy

To learn more about importing existing cloud resources, see Importing resources.

Package Details

Repository
AWS Classic pulumi/pulumi-aws
License
Apache-2.0
Notes
This Pulumi package is based on the aws Terraform Provider.