Use Terraform to create an ACK One Fleet instance along with the required networking infrastructure (VPC and vSwitch).
Prerequisites
Before you begin, make sure that you have:
An AccessKey pair created for a Resource Access Management (RAM) user
Use a RAM user instead of your Alibaba Cloud account for day-to-day operations. A RAM user has limited permissions, which reduces security risks if credentials are compromised.
The following minimum-privilege RAM policy attached to your RAM user. This policy grants permissions to create, list, and delete RAM roles, and to modify role policies. For more information, see Grant permissions to a RAM user.
{ "Version": "1", "Statement": [ { "Effect": "Allow", "Action": [ "ram:GetRole", "ram:ListRoles", "ram:AttachPolicyToRole", "ram:ListPoliciesForRole", "ram:CreateRole", "ram:DetachPolicyFromRole", "ram:DeleteRole" ], "Resource": "*" } ] }A Terraform environment set up through one of the following methods:
Method Best for Terraform Explorer Quick online experimentation without local installation Cloud Shell Running Terraform with preconfigured credentials in a browser-based terminal Local installation Custom development environments or unreliable network connections An existing ACK cluster under the current account
Terraform resources
This configuration uses the following Terraform resources:
alicloud_zones: Queries zones.
alicloud_vpc: Creates a virtual private cloud (VPC).
alicloud_vswitch: Creates a virtual switch (vSwitch) to divide one or more subnets for the VPC.
alicloud_ack_one_cluster: Creates an ACK One Fleet instance.
Procedure
Step 1: Write the Terraform configuration
Create a working directory and add a file named main.tf with the following content:
variable "name" {
default = "terraform-example"
}
provider "alicloud" {
region = "cn-hangzhou"
}
# Query available zones for vSwitch placement.
data "alicloud_zones" "default" {
available_resource_creation = "VSwitch"
}
# Create a VPC.
resource "alicloud_vpc" "defaultVpc" {
cidr_block = "172.16.0.0/12"
vpc_name = var.name
}
# Create a vSwitch inside the VPC.
resource "alicloud_vswitch" "defaultyVSwitch" {
vpc_id = alicloud_vpc.defaultVpc.id
cidr_block = "172.16.2.0/24"
zone_id = data.alicloud_zones.default.zones.0.id
vswitch_name = var.name
}
# Create an ACK One Fleet instance.
resource "alicloud_ack_one_cluster" "default" {
profile = "Default"
argocd_enabled = false
network {
vpc_id = alicloud_vpc.defaultVpc.id
vswitches = ["${alicloud_vswitch.defaultyVSwitch.id}"]
}
}The key parameters for alicloud_ack_one_cluster are:
| Parameter | Description |
|---|---|
profile | Cluster profile. Valid values: "Default", "XFlow". |
argocd_enabled | Whether to enable ArgoCD. Set to false in this example. Must be false before you delete the Fleet instance. |
network.vpc_id | The VPC where the Fleet instance is deployed. |
network.vswitches | List of vSwitch IDs that define the subnets for the Fleet instance. |
Step 2: Initialize Terraform
Run the following command to download the required provider plugins:
terraform initStep 3: Preview the execution plan
Run the following command to preview the resources that Terraform will create. This does not modify your infrastructure.
terraform planStep 4: Create the resources
Run the following command to create the VPC, vSwitch, and ACK One Fleet instance:
terraform applyType yes and press Enter when prompted. After the command completes, the following output indicates that all resources are created:
Apply complete! Resources: 3 added, 0 changed, 0 destroyed.Step 5: Verify the result
Run the following command to inspect the created resources:
terraform showYou can also verify the Fleet instance in the ACK One console.
Clean up resources
To delete all resources created by this configuration, run:
terraform destroySet argocd_enabled to false in your configuration before running terraform destroy. The Fleet instance cannot be deleted while ArgoCD is enabled.
When using theDefaultprofile,terraform destroymay fail to delete the vSwitch due to remaining network interfaces from the Fleet instance. If you encounter aDependencyViolation.NetworkInterfaceerror, wait a few minutes and runterraform destroyagain.