Create a Fleet instance through Terraform

更新时间:
复制 MD 格式

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:

    MethodBest for
    Terraform ExplorerQuick online experimentation without local installation
    Cloud ShellRunning Terraform with preconfigured credentials in a browser-based terminal
    Local installationCustom development environments or unreliable network connections
  • An existing ACK cluster under the current account

Terraform resources

This configuration uses the following Terraform resources:

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:

ParameterDescription
profileCluster profile. Valid values: "Default", "XFlow".
argocd_enabledWhether to enable ArgoCD. Set to false in this example. Must be false before you delete the Fleet instance.
network.vpc_idThe VPC where the Fleet instance is deployed.
network.vswitchesList 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 init

Step 3: Preview the execution plan

Run the following command to preview the resources that Terraform will create. This does not modify your infrastructure.

terraform plan

Step 4: Create the resources

Run the following command to create the VPC, vSwitch, and ACK One Fleet instance:

terraform apply

Type 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 show

You can also verify the Fleet instance in the ACK One console.

Clean up resources

To delete all resources created by this configuration, run:

terraform destroy
Important

Set argocd_enabled to false in your configuration before running terraform destroy. The Fleet instance cannot be deleted while ArgoCD is enabled.

When using the Default profile, terraform destroy may fail to delete the vSwitch due to remaining network interfaces from the Fleet instance. If you encounter a DependencyViolation.NetworkInterface error, wait a few minutes and run terraform destroy again.