> For the complete documentation index, see [llms.txt](https://docs.console.zenlayer.com/api-reference/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.console.zenlayer.com/api-reference/zec/vpc-network/modifyvpcattribute.md).

# ModifyVpcAttribute

## 1. API Description

This API (ModifyVpcAttribute) is used to modify the attributes of a global VPC.

## 2. Input Parameters

The following request parameter list only provides API request parameters.

| Parameter Name  | Required | Type    | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| --------------- | -------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| vpcId           | Yes      | String  | <p>ID of the VPC.</p><p>It can be obtained by calling <a href="/api-reference/zec/vpc-network/describevpcs.md">DescribeVpcs</a>.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| vpcName         | No       | String  | <p>Global VPC name.</p><p>This parameter must start and end with a number or a letter, containing 2 to 63 characters. Only letters, numbers, -/\_ and periods (.) are supported.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| cidrBlock       | No       | String  | <p>Primary IPv4 CIDR block to be modified.</p><p>This field modifies only the primary CIDR block. To add or remove secondary CIDR blocks, use <a href="/api-reference/zec/vpc-network/associatevpccidrblock.md">AssociateVpcCidrBlock</a> and <a href="/api-reference/zec/vpc-network/unassociatevpccidrblock.md">UnassociateVpcCidrBlock</a>.</p><p>The mask length ranges from 9 to 29, and the starting address of the CIDR block must be specified, for example <code>10.0.0.0/16</code>.</p><p>The primary CIDR block can only be expanded or shrunk within the original CIDR block, that is, the new CIDR block must overlap with the original primary CIDR block. Changing it to a CIDR block unrelated to the original primary CIDR block is rejected, and the primary CIDR block cannot be deleted.</p><p>When it is shrunk, the subnets that originally fell within the primary CIDR block must still fall within the new primary CIDR block, otherwise the request is rejected. The subnets under the secondary CIDR blocks are not affected.</p><p>It cannot overlap with the existing secondary CIDR blocks of this VPC, nor with the following reserved CIDR blocks: <code>0.0.0.0/8</code>, <code>100.64.0.0/10</code>, <code>127.0.0.0/8</code>, <code>169.254.0.0/16</code>, and <code>224.0.0.0/4</code>.</p><p>Leaving this field empty means the primary CIDR block is not modified.</p><p>The default VPC does not support modifying the CIDR block.</p> |
| enableIPv6      | No       | Boolean | <p>Whether to enable the private IPv6 CIDR block.</p><p>Only enabling it (<code>true</code>) is allowed for now, and it cannot be disabled once enabled.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| securityGroupId | No       | String  | <p>ID of the security group to be bound to the VPC.</p><p>If it is not specified, no modification is made.</p><p>It can be obtained by calling <a href="/api-reference/zec/security-group/describesecuritygroups.md">DescribeSecurityGroups</a>.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |

## 3. Output Parameters

| Parameter Name | Type   | Description                                                                                                           |
| -------------- | ------ | --------------------------------------------------------------------------------------------------------------------- |
| requestId      | String | <p>The unique request ID, which is returned for each request.</p><p>RequestId is required for locating a problem.</p> |

## 4. Code Example

{% tabs %}
{% tab title="Example" %}
**1. Modify the attributes of a VPC and enable IPv6.**

```json
POST /api/v2/zec HTTP/1.1
Host: console.zenlayer.com
Content-Type: application/json
X-ZC-Action: ModifyVpcAttribute
<Common Request Params>

Request：
{
    "vpcId": "<vpcId>",
    "vpcName": "TestVpcName",
    "enableIPv6": true
}

Response：
{
  "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
  "response": {
    "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3"
  }
}
```

**2. Expand the primary CIDR block of a VPC.**

The original primary CIDR block of the VPC is `21.0.0.0/16` and is expanded to `21.0.0.0/9`. The new primary CIDR block overlaps with the original one, which means the expansion is performed within the original CIDR block and is therefore allowed.

```json
POST /api/v2/zec HTTP/1.1
Host: console.zenlayer.com
Content-Type: application/json
X-ZC-Action: ModifyVpcAttribute
<Common Request Params>

Request：
{
    "vpcId": "<vpcId>",
    "cidrBlock": "21.0.0.0/9"
}

Response：
{
  "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
  "response": {
    "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3"
  }
}
```

**3. Shrink the primary CIDR block of a VPC.**

The original primary CIDR block of the VPC is `21.0.0.0/9` and is shrunk to `21.0.0.0/16`. All subnets that originally fell within the primary CIDR block still fall within `21.0.0.0/16`, so the operation is allowed; If any subnet would fall outside the new primary CIDR block, the request is rejected. Secondary CIDR blocks and the subnets under them are not affected.

```json
POST /api/v2/zec HTTP/1.1
Host: console.zenlayer.com
Content-Type: application/json
X-ZC-Action: ModifyVpcAttribute
<Common Request Params>

Request：
{
    "vpcId": "<vpcId>",
    "cidrBlock": "21.0.0.0/16"
}

Response：
{
  "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
  "response": {
    "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3"
  }
}
```

{% endtab %}
{% endtabs %}

## 5. Developer Resources

Zenlayer Cloud API 2.0 integrates [SDKs](/api-reference/api-introduction/toolkit/api-sdk.md)，to make it easier for you to call APIs. More programming languages will be supported.

## 6. Error Codes

The following only lists the error codes related to the API business logic. For other error codes, see [Common Error Codes](/api-reference/api-introduction/instruction/commonerrorcode.md).

| HTTP Status Code | Error Code                                               | Description                                                                                   |
| ---------------- | -------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
| 400              | INVALID\_CIDR\_BLOCK\_FORMAT                             | Invalid CIDR block format.                                                                    |
| 400              | INVALID\_CIDR\_BLOCK\_NETMASK\_RANGE                     | CIDR block range is invalid.                                                                  |
| 400              | INVALID\_CIDR\_BLOCK\_NOT\_EMPTY                         | CIDR block cannot be empty.                                                                   |
| 400              | INVALID\_IP\_BROADCAST\_ADDRESS                          | The IP address cannot be a broadcast address.                                                 |
| 404              | INVALID\_SECURITY\_GROUP\_NOT\_FOUND                     | The specified security group does not exist.                                                  |
| 404              | INVALID\_VPC\_NOT\_FOUND                                 | The global VPC does not exist.                                                                |
| 400              | OPERATION\_DENIED\_DEFAULT\_VPC                          | The default global VPC cannot be modified.                                                    |
| 400              | OPERATION\_DENIED\_VPC\_CANT\_DISABLE\_IPV6              | Once enabled, IPv6 CIDR block function cannot be disabled.                                    |
| 400              | OPERATION\_DENIED\_VPC\_CIDR\_CONFLICT                   | After the VPC CIDR block is modified, every subnet must still fall within the new CIDR block. |
| 400              | OPERATION\_DENIED\_VPC\_CIDR\_RESERVED                   | The CIDR block of the VPC overlaps with a reserved CIDR block and cannot be used.             |
| 400              | OPERATION\_DENIED\_VPC\_CIDR\_OVERLAP                    | The CIDR blocks of the VPC overlap with each other.                                           |
| 400              | OPERATION\_DENIED\_VPC\_PRIMARY\_CIDR\_NOT\_SAME\_ORIGIN | The primary CIDR block can only be expanded or shrunk within the original CIDR block.         |
