Deploy a Terway-based ACK dedicated cluster with auto-provisioned VPC, vSwitches, and add-ons.
Run this code in your browser on OpenAPI Portal.
Creating ACK dedicated clusters is restricted. To request access, submit a ticket.
Prerequisites
Ensure the following:
-
ACK is activated (activate ACK by using Terraform).
-
An AccessKey pair created for the RAM user running Terraform (Create an AccessKey pair, RAM users).
Use a RAM user instead of your Alibaba Cloud root account. Limited permissions reduce risk if credentials are compromised.
-
The following minimum permissions policy attached to the RAM user. Covers creating, viewing, and deleting Virtual Private Clouds (VPCs), vSwitches, and ACK clusters (grant permissions).
{ "Version": "1", "Statement": [ { "Effect": "Allow", "Action": [ "vpc:CreateVpc", "vpc:CreateVSwitch", "vpc:DescribeRouteTableList", "vpc:DescribeVpcAttribute", "vpc:ListEnhancedNatGatewayAvailableZones", "vpc:DescribeVSwitchAttributes", "vpc:DescribeNatGateways", "cs:CreateCluster", "cs:DescribeTaskInfo", "cs:DescribeClusterDetail", "cs:DescribeClusterCerts", "cs:CheckControlPlaneLogEnable", "vpc:DeleteVpc", "vpc:DeleteVSwitch", "cs:DeleteCluster" ], "Resource": "*" } ] } -
Terraform v0.12.28 or later. Verify with
terraform --version.Option
Best for
— online, no installation required
Quick testing and debugging at no cost
Cloud Shell — pre-installed, pre-configured with your credentials
Fast, convenient runs without local setup
Resource Orchestration Service (ROS) — managed Terraform
Templates that define Alibaba Cloud, AWS, or Azure resources with managed lifecycle
Custom development environments or restricted network access
-
alicloud_instance_types: queries ECS instance types that meet specific conditions.
-
alicloud_vpc: creates a VPC.
-
alicloud_vswitch: creates vSwitches in a VPC to divide it into subnets.
-
alicloud_resource_manager_resource_groups: queries resource groups of the current Alibaba Cloud user.
-
alicloud_cs_kubernetes: creates an ACK dedicated cluster.
Terraform resources
The configuration uses the following resources. Fees apply—release them when no longer needed.
|
Resource |
Purpose |
|
Query Elastic Compute Service (ECS) instance types that meet specific conditions |
|
|
Create a VPC |
|
|
Create vSwitches (subnets) inside the VPC |
|
|
Query the resource group managed by the RAM user |
|
|
Create an ACK dedicated cluster |
The configuration selects instance types available across all three zones, ensuring control plane nodes can be scheduled in any zone.
Generate Terraform parameters from the console
If the example doesn't match your requirements, generate parameters from the ACK console:
-
Log on to the ACK console. In the left navigation pane, click Clusters.
-
On the Clusters page, click Cluster Templates.
-
Select a cluster type, click Create, and configure the cluster on the Cluster Configurations page.
-
On the Confirm page, click Console-to-Code.
-
In the sidebar, click the Terraform tab and copy the generated parameters.
Create an ACK dedicated cluster with Terway
These steps create an ACK dedicated cluster with Terway. The configuration provisions a VPC, three control-plane vSwitches, three Terway pod vSwitches, and the cluster—8 resources total.
Step 1: Create the configuration file
Step 2: Initialize Terraform
terraform init
A successful initialization returns:
Terraform has been successfully initialized!
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.
If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
Step 3: Preview the execution plan
terraform plan
Previews the planned resource changes without applying them.
A successful plan returns:
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.
...
Plan: 8 to add, 0 to change, 0 to destroy.
...
Step 4: Create the cluster
terraform apply
When prompted, type yes and press Enter.
A successful apply returns:
...
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
...
alicloud_cs_managed_kubernetes.default: Creation complete after 8m26s [id=************]
Apply complete! Resources: 8 added, 0 changed, 0 destroyed.
Verify the cluster
After terraform apply completes, verify the cluster using either method:
Run the terraform show command
Option 1: Use `terraform show`
terraform show
Lists all resources Terraform created and their current state.
Log on to the ACK console
Option 2: Check the ACK console
Log on to the ACK console and confirm the new cluster appears in the Clusters list.
Clean up resources
Running terraform destroy permanently deletes all resources created by this configuration. This action cannot be undone.
Release the resources. See Common commands for terraform destroy options.Run with one click
terraform destroy
When prompted, type yes and press Enter. A successful destroy returns:
...
Do you really want to destroy all resources?
Terraform will destroy all your managed infrastructure, as shown above.
There is no undo. Only 'yes' will be accepted to confirm.
Enter a value: yes
...
Destroy complete! Resources: 7 destroyed.
Sample code
Next steps
-
Use Terraform to manage add-ons — install add-ons for your cluster
-
Use Terraform to create a node pool that has auto scaling enabled — add managed node pools to the cluster
-
Create a Terraform stack — deploy Terraform templates with ROS
-
If terraform init times out due to network latency, configure Terraform init acceleration.