Delete an ACK cluster created by Terraform

Updated at:

Delete a Container Service for Kubernetes (ACK) cluster created with Terraform while keeping the resources that you still need.

Prerequisites

One of the following clusters has been created with Terraform:

Usage notes

When deleting a cluster with Terraform, you can use retain_resources to retain the resources that you need, and you can also configure delete_options to manage resource deletion and retention.

Category

delete_options

retain_resources

Methods

Specifies whether to retain or delete specific resources.

Specifies resources to retain.

Example:

delete_options {
 delete_mode = "delete"
 resource_type = "SLS_ControlPlane"
 }
Note

You can set delete_mode to the following values:

  • delete: removes the specified resource type.

  • retain: retains the specified resource type.

Example:

retain_resources = ["ngw-xxxx"]

Input the resource instance ID into the retain_resources parameter. To obtain the instance ID, query the associated resources of the specified cluster.

Supported resources

  • SLB: Server Load Balancer (SLB) resources created for Services. By default, the SLB resources are automatically deleted. Set delete_mode to retain to keep them.

  • ALB: Application Load Balancer (ALB) resources created by the ALB Ingress Controller. By default, the ALB resources are retained. Set delete_mode to delete to remove them.

  • SLS_Data: Simple Log Service projects used by the cluster logging feature. By default, the Simple Log Service projects are retained. Set delete_mode to delete to remove them.

  • SLS_ControlPlane: Simple Log Service projects used to store the logs of control planes in ACK managed clusters. By default, the Simple Log Service projects are retained. Set delete_mode to delete to remove them.

  • PrivateZone: PrivateZone resources created by ACK Serverless clusters. By default, the PrivateZone resources are retained. Set delete_mode to delete to remove them.

  • Load balancer (SLB instances of the cluster API server)

  • Internet NAT gateway

  • SNAT entries on an Internet NAT gateway

  • Elastic IP address (Internet NAT gateway)

Supported cluster types

  • ACK managed clusters

  • ACK dedicated clusters

  • ACK Serverless clusters

  • ACK managed clusters

  • ACK Serverless clusters

  • ACK dedicated clusters

  • ACK Edge clusters

Step 1: Add resource management parameters

Add the following parameters to the main.tf file for the ACK cluster that you created to control the deletion or retention of resources:

resource "alicloud_cs_managed_kubernetes" "default" {    # Add location.
  ...
  // Add the resource instance ID to [].
  retain_resources = ["ngw-xxxx"]
  // Delete SLB resources created by the cluster.
  delete_options {
    delete_mode = "delete"
    resource_type = "SLB"
  }
  // Delete ALB resources created by the ALB Ingress Controller.
  delete_options {
    delete_mode = "delete"
    resource_type = "ALB"
  }
  // Delete the Simple Log Service projects used by the cluster logging feature.
  delete_options {
    delete_mode = "delete"
    resource_type = "SLS_Data"
  }
  // Delete the Simple Log Service projects used by the managed cluster control plane.
  delete_options {
    delete_mode = "delete"
    resource_type = "SLS_ControlPlane"
  }
}

Apply the changes:

terraform apply

Step 2: Delete the cluster

Use the following steps to delete the Terraform-created cluster:

Important

The terraform destroy command deletes all resources managed by Terraform, which includes irreversible actions such as data deletion. It is crucial to back up any important data and resources before proceeding.

  1. Delete the Terraform-created cluster:

    terraform destroy
  2. If the following information is returned, type yes , and press Enter . Then, the cluster will be deleted.

    ...
    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.