alicloud_vswitch
Provides a VPC Vswitch resource. ## Module Support
You can use to the existing vpc module to create a VPC and several VSwitches one-click.
For information about VPC Vswitch and how to use it, see What is Vswitch.
-> NOTE: Available since v1.0.0.
Example Usage
Basic Usage
data "alicloud_zones" "foo" {
available_resource_creation = "VSwitch"
}
resource "alicloud_vpc" "foo" {
vpc_name = "terraform-example"
cidr_block = "172.16.0.0/12"
}
resource "alicloud_vswitch" "foo" {
vswitch_name = "terraform-example"
cidr_block = "172.16.0.0/21"
vpc_id = alicloud_vpc.foo.id
zone_id = data.alicloud_zones.foo.zones.0.id
}
data "alicloud_zones" "foo" {
available_resource_creation = "VSwitch"
}
resource "alicloud_vpc" "vpc" {
vpc_name = "terraform-example"
cidr_block = "172.16.0.0/12"
}
resource "alicloud_vpc_ipv4_cidr_block" "cidr_blocks" {
vpc_id = alicloud_vpc.vpc.id
secondary_cidr_block = "192.163.0.0/16"
}
resource "alicloud_vswitch" "island-nat" {
vpc_id = alicloud_vpc_ipv4_cidr_block.cidr_blocks.vpc_id
cidr_block = "172.16.0.0/21"
zone_id = data.alicloud_zones.foo.zones.0.id
vswitch_name = "terraform-example"
tags = {
BuiltBy = "example_value"
cnm_version = "example_value"
Environment = "example_value"
ManagedBy = "example_value"
}
}
Create a switch associated with the additional network segment
data "alicloud_zones" "foo" {
available_resource_creation = "VSwitch"
}
resource "alicloud_vpc" "foo" {
vpc_name = "terraform-example"
cidr_block = "172.16.0.0/12"
}
resource "alicloud_vpc_ipv4_cidr_block" "foo" {
vpc_id = alicloud_vpc.foo.id
secondary_cidr_block = "192.163.0.0/16"
}
resource "alicloud_vswitch" "foo" {
vpc_id = alicloud_vpc_ipv4_cidr_block.foo.vpc_id
cidr_block = "192.163.0.0/24"
zone_id = data.alicloud_zones.foo.zones.0.id
}
Need more examples? VIEW MORE EXAMPLES
Argument Reference
The following arguments are supported:
-
cidr_block- (Optional, ForceNew) The IPv4 CIDR block of the VSwitch. The subnet mask must be16to29bits in length. NOTE: From version 1.233.0, if you do not setis_default, or setis_defaulttofalse,cidr_blockis required. -
description- (Optional) The description of VSwitch. The description must be1to256characters in length, and cannot start withhttp://orhttps://. -
zone_id- (Optional, ForceNew, Available since v1.119.0) The AZ for the VSwitch. Note: Required for a VPC VSwitch. -
enable_ipv6- (Optional, Computed, Available since v1.201.0) Whether the IPv6 function is enabled in the switch. Value:true: enables IPv6.false(default): IPv6 is not enabled.
-> NOTE: Since v1.281.0,
ipv6_cidr_block_maskonly takes effect whenenable_ipv6istrue, and it is required whenenable_ipv6istrue.-> NOTE: When
enable_ipv6istrue, modifyingipv6_cidr_block_maskwill disable IPv6 and then re-enable it to assign the new subnet. This re-assignment may interrupt the IPv6 service of the VSwitch, so plan such changes with care. -
ipv6_cidr_block_mask- (Optional, Available since v1.201.0) The last 4, 8, or 12 bits of the IPv6 CIDR block of the VSwitch, corresponding to a VPC IPv6 address mask of60,56, or52respectively. It only takes effect and is required whenenable_ipv6istrue, and is used only for create and update operations. The valid values are determined by the IPv6 address mask of the VPC:- When the VPC IPv6 address mask is
52:0to4095. - When the VPC IPv6 address mask is
56:0to255. - When the VPC IPv6 address mask is
60:0to15.
- When the VPC IPv6 address mask is
-
tags- (Optional, Map, Available since v1.55.3) The tags of VSwitch. -
vswitch_name- (Optional, Available since v1.119.0) The name of the VSwitch. The name must be1to128characters in length, and cannot start withhttp://orhttps://. -
vpc_id- (Optional, ForceNew) The VPC ID. NOTE: From version 1.233.0, if you do not setis_default, or setis_defaulttofalse,vpc_idis required. -
is_default- (Optional, Computed, ForceNew, Bool, Available since v1.233.0) Specifies whether to create the default VSwitch. Default value:false. Valid values:true: Creates a default vSwitch.false: Creates a vSwitch.
-> NOTE: When
is_defaultistrue, a default VPC must already exist in the region. A zone can contain only one default vSwitch, and creating another one in the same zone fails. After a default vSwitch is created, its CIDR block cannot be modified. The first and last three IP addresses in each default vSwitch CIDR block are reserved by the system, default vSwitches do not support multicast or broadcast, and the number of cloud product instances in a default vSwitch cannot exceed the remaining available instance quota of the VPC. -
vpc_ipv6_cidr_block- (Optional, Available since v1.280.0) The IPv6 CIDR block of the VPC. If the VPC has multiple IPv6 CIDR blocks, you can use this parameter to specify the IPv6 CIDR block range to which the VSwitch belongs. This parameter is used only for create and update operations.
The following arguments will be discarded. Please use new fields as soon as possible:
name- (Deprecated since v1.119.0) Fieldnamehas been deprecated from provider version 1.119.0. New fieldvswitch_nameinstead.availability_zone- (Deprecated since v1.119.0) Fieldavailability_zonehas been deprecated from provider version 1.119.0. New fieldzone_idinstead.
Attributes Reference
The following attributes are exported:
id- The ID of the resource supplied above.create_time- The creation time of the VSwitch.ipv6_cidr_block- The IPv6 CIDR block of the VSwitch.status- The status of the resource.
Timeouts
The timeouts block allows you to specify timeouts for certain actions:
create- (Defaults to 5 mins) Used when create the Vswitch.delete- (Defaults to 10 mins) Used when delete the Vswitch.update- (Defaults to 5 mins) Used when update the Vswitch.
Import
VPC Vswitch can be imported using the id, e.g.
$ terraform import alicloud_vswitch.example <id>