All Products
Search
Document Center

Enterprise Distributed Application Service:Use Terraform to create an ACK cluster and deploy an application

Last Updated:Mar 10, 2026

Terraform lets you define infrastructure as code to create a Container Service for Kubernetes (ACK) cluster, import it into Enterprise Distributed Application Service (EDAS), and deploy an application -- all in a single, automated workflow.

How it works

The deployment chains three Terraform resources:

  1. alicloud_cs_managed_kubernetes -- Creates a managed Kubernetes cluster in ACK.

  2. alicloud_edas_k8s_cluster -- Imports the ACK cluster into EDAS.

  3. alicloud_edas_k8s_application -- Deploys an application to the EDAS-managed cluster.

Terraform interfaces

Data sources

Data sourceDescription
alicloud_edas_applicationsQuery EDAS applications, including both Elastic Compute Service (ECS) and ACK applications
alicloud_edas_clustersQuery EDAS clusters, including both ECS and ACK clusters

Resources

ResourceDescription
alicloud_edas_k8s_clusterImport an ACK cluster into EDAS
alicloud_edas_k8s_applicationCreate and deploy an application in an EDAS-managed ACK cluster

Configuration example

This example creates a managed Kubernetes cluster in ACK, imports it into EDAS, and deploys a container-based application. Modify configuration parameters as needed.

Note

Terraform supports various ACK cluster types. This example uses a managed Kubernetes cluster.

Note

This example assumes that you have already defined VPC and vSwitch resources (for example, alicloud_vpc and alicloud_vswitch) and an alicloud_instance_types data source in your configuration. For details, see the Alibaba Cloud Terraform provider documentation.

Step 1: Create a managed Kubernetes cluster

resource "alicloud_cs_managed_kubernetes" "default" {
  name                        = var.name
  worker_instance_types       = [data.alicloud_instance_types.default.instance_types.0.id]
  worker_vswitch_ids          = [alicloud_vswitch.default.id]
  worker_number               = "1"
  password                    = "Test12345"
  pod_cidr                    = "172.20.0.0/16"
  service_cidr                = "172.21.0.0/20"
  worker_disk_size            = "50"
  worker_disk_category        = "cloud_ssd"
  worker_data_disk_size       = "20"
  worker_data_disk_category   = "cloud_ssd"
  worker_instance_charge_type = "PostPaid"
  slb_internet_enabled        = "true"
}

The following table describes the key parameters:

ParameterDescriptionExample
nameCluster nameReferenced from a variable
worker_instance_typesECS instance type for worker nodesecs.g6.large
worker_vswitch_idsvSwitch ID for worker nodesReferenced from an alicloud_vswitch resource
passwordSSH login password for worker nodesTest12345
pod_cidrCIDR block for pod IP addresses. Must not overlap with VPC or service CIDR ranges.172.20.0.0/16
service_cidrCIDR block for service IP addresses. Must not overlap with VPC or pod CIDR ranges.172.21.0.0/20

Step 2: Import the cluster into EDAS

resource "alicloud_edas_k8s_cluster" "default" {
  cs_cluster_id = "xxxx-xxx-xxx"
}

This resource imports the ACK cluster created in Step 1 into EDAS. After the import, EDAS can manage application deployments on this cluster.

Step 3: Deploy an application

resource "alicloud_edas_k8s_application" "default" {
  application_name = "shesheng-test-k8s"
  cluster_id       = "45bc8232-3233-46be-ab20-6d4a9b506d5c"
  replicas         = 1
  package_type     = "Image"
  image_url        = "cr.registry.cloud.ste2.com/test/gw-provider:1028"
  command          = "/bin/sh"
  command_args     = ["-c", "while true; do echo hello; sleep 1000;done"]
}

The following table describes the key parameters:

ParameterDescription
application_nameName of the application in EDAS
cluster_idID of the EDAS-managed cluster from Step 2
replicasNumber of pod replicas
package_typeDeployment package type. Set to Image for container image deployments.
image_urlFull URL of the container image
commandEntrypoint command for the container
command_argsArguments passed to the entrypoint command

Deploy the infrastructure

Run the following commands to initialize and apply the Terraform configuration:

  1. Initialize the Terraform working directory.

    terraform init

    Expected output:

    Initializing provider plugins...
    - Installing aliyun/alicloud...
    
    Terraform has been successfully initialized!
  2. Preview the changes.

    terraform plan
  3. Apply the configuration to create all resources.

    terraform apply

    When prompted, type yes to confirm. Cluster creation typically takes 10 to 15 minutes.

    Expected output:

    Apply complete! Resources: X added, 0 changed, 0 destroyed.

Clean up resources

To avoid ongoing charges, destroy all resources created by this configuration when they are no longer needed:

terraform destroy

When prompted, type yes to confirm. This removes the EDAS application, the EDAS cluster import, and the ACK cluster.

Warning

terraform destroy permanently deletes all resources managed by this configuration. Back up any important data before you run this command.

Related information