--- subcategory: "VPC (Virtual Private Cloud)" layout: "aws" page_title: "AWS: aws_vpc" description: |- Provides a VPC resource. --- # Resource: aws_vpc Provides a VPC resource. ~> **NOTE:** When AWS GuardDuty is enabled in your account, it automatically creates VPC endpoints and security groups in your VPCs to monitor network traffic. During VPC deletion, the provider automatically detects and removes these GuardDuty-managed VPC endpoints and security groups if they are blocking the deletion. This cleanup only targets resources tagged with `GuardDutyManaged=true` and happens automatically during destroy operations with no manual intervention required. For optimal functionality, the IAM role used by Terraform should have the [optional permissions listed below](#guardduty-cleanup-permissions). If these permissions are not available, the provider will continue with the deletion attempt and surface warnings only if the deletion ultimately fails. ## Example Usage Basic usage: ```terraform resource "aws_vpc" "main" { cidr_block = "10.0.0.0/16" } ``` Basic usage with tags: ```terraform resource "aws_vpc" "main" { cidr_block = "10.0.0.0/16" instance_tenancy = "default" tags = { Name = "main" } } ``` VPC with CIDR from AWS IPAM: ```terraform data "aws_region" "current" {} resource "aws_vpc_ipam" "test" { operating_regions { region_name = data.aws_region.current.region } } resource "aws_vpc_ipam_pool" "test" { address_family = "ipv4" ipam_scope_id = aws_vpc_ipam.test.private_default_scope_id locale = data.aws_region.current.region } resource "aws_vpc_ipam_pool_cidr" "test" { ipam_pool_id = aws_vpc_ipam_pool.test.id cidr = "172.20.0.0/16" } resource "aws_vpc" "test" { ipv4_ipam_pool_id = aws_vpc_ipam_pool.test.id ipv4_netmask_length = 28 depends_on = [ aws_vpc_ipam_pool_cidr.test ] } ``` ## Argument Reference This resource supports the following arguments: * `assign_generated_ipv6_cidr_block` - (Optional) Requests an Amazon-provided IPv6 CIDR block with a /56 prefix length for the VPC. You cannot specify the range of IP addresses, or the size of the CIDR block. Default is `false`. Conflicts with `ipv6_ipam_pool_id`. * `cidr_block` - (Optional) IPv4 CIDR block for the VPC. CIDR can be explicitly set or it can be derived from IPAM using `ipv4_netmask_length`. * `enable_dns_hostnames` - (Optional) Whether to enable DNS hostnames in the VPC. Defaults to `false`. * `enable_dns_support` - (Optional) Whether to enable DNS support in the VPC. Defaults to `true`. * `enable_network_address_usage_metrics` - (Optional) Whether to enable Network Address Usage metrics for your VPC. Defaults to `false`. * `instance_tenancy` - (Optional) Tenancy option for instances launched into the VPC. Default is `default`, which ensures that EC2 instances launched in this VPC use the EC2 instance tenancy attribute specified when the EC2 instance is launched. The only other option is `dedicated`, which ensures that EC2 instances launched in this VPC are run on dedicated tenancy instances regardless of the tenancy attribute specified at launch. This has a dedicated per region fee of $2 per hour, plus an hourly per instance usage fee. * `ipv4_ipam_pool_id` - (Optional) 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` - (Optional) Netmask length of the IPv4 CIDR you want to allocate to this VPC. Requires specifying a `ipv4_ipam_pool_id`. * `ipv6_cidr_block` - (Optional) IPv6 CIDR block to request from an IPAM Pool. Can be set explicitly or derived from IPAM using `ipv6_netmask_length`. * `ipv6_cidr_block_network_border_group` - (Optional) By default when an IPv6 CIDR is assigned to a VPC a default ipv6_cidr_block_network_border_group will be set to the region of the VPC. This can be changed to restrict advertisement of public addresses to specific Network Border Groups such as LocalZones. * `ipv6_ipam_pool_id` - (Optional) IPAM Pool ID for a IPv6 pool. Conflicts with `assign_generated_ipv6_cidr_block`. * `ipv6_netmask_length` - (Optional) Netmask length to request from IPAM Pool. Conflicts with `ipv6_cidr_block`. This can be omitted if IPAM pool as a `allocation_default_netmask_length` set. Valid values are from `44` to `60` in increments of 4. * `region` - (Optional) Region where this resource will be [managed](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints). Defaults to the Region set in the [provider configuration](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#aws-configuration-reference). * `tags` - (Optional) Map of tags to assign to the resource. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level. ## Attribute Reference This resource exports the following attributes in addition to the arguments above: * `arn` - ARN of VPC. * `default_network_acl_id` - ID of the network ACL created by default on VPC creation. * `default_route_table_id` - ID of the route table created by default on VPC creation. * `default_security_group_id` - ID of the security group created by default on VPC creation. * `dhcp_options_id` - DHCP options id of the desired VPC. * `enable_dns_hostnames` - Whether the VPC has DNS hostname support. * `enable_dns_support` - Whether the VPC has DNS support. * `enable_network_address_usage_metrics` - Whether Network Address Usage metrics are enabled for the VPC. * `id` - ID of the VPC. * `instance_tenancy` - Tenancy of instances spin up within VPC. * `ipv6_association_id` - Association ID for the IPv6 CIDR block. * `ipv6_cidr_block_network_border_group` - Network Border Group Zone name. * `main_route_table_id` - ID of the main route table associated with this VPC. Note that you can change a VPC's main route table by using an [`aws_main_route_table_association`](/docs/providers/aws/r/main_route_table_association.html). * `owner_id` - ID of the AWS account that owns the VPC. * `tags_all` - Map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block). ### GuardDuty Cleanup Permissions ~> **Note:** The following IAM permissions are optional but recommended for automatic cleanup of GuardDuty-managed resources during VPC deletion: `ec2:DescribeVpcEndpoints`, `ec2:DescribeSecurityGroups` (on all resources), and `ec2:DeleteVpcEndpoints`, `ec2:ModifyVpcEndpoint`, `ec2:DeleteSecurityGroup` (on resources tagged `GuardDutyManaged: true`). ## Import In Terraform v1.12.0 and later, the [`import` block](https://developer.hashicorp.com/terraform/language/import) can be used with the `identity` attribute. For example: ```terraform import { to = aws_vpc.test_vpc identity = { id = "vpc-a01106c2" } } resource "aws_vpc" "test_vpc" { ### Configuration omitted for brevity ### } ``` ### Identity Schema #### Required * `id` (String) VPC ID. #### Optional * `account_id` (String) Account ID where this resource is managed. * `region` (String) Region where this resource is managed. In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import VPCs using the VPC `id`. For example: ```terraform import { to = aws_vpc.test_vpc id = "vpc-a01106c2" } ``` Using `terraform import`, import VPCs using the VPC `id`. For example: ```console % terraform import aws_vpc.test_vpc vpc-a01106c2 ```