All Products
Search
Document Center

Terraform:Use Terraform to create an EDAS ECS cluster and deploy an application

Last Updated:Feb 28, 2026

Create an Elastic Compute Service (ECS) cluster in Enterprise Distributed Application Service (EDAS), deploy an application, bind a Server Load Balancer (SLB) instance, and scale the application across deploy groups with Terraform.

Prerequisites

Before you begin, ensure that you have:

  • Terraform 1.2 or later installed (Install Terraform)

  • Alibaba Cloud provider for Terraform version 1.82.0 or later

  • An Alibaba Cloud account with EDAS, ECS, VPC, and SLB activated

  • A RAM user or role with permissions to manage EDAS, ECS, VPC, and SLB resources

  • An AccessKey pair configured for Terraform authentication (via environment variables or provider configuration)

  • At least one running ECS instance in a Virtual Private Cloud (VPC)

Note

Activate EDAS in the EDAS console before you create clusters or deploy applications through Terraform.

Resources used

Provider configuration

Create a providers.tf file with the required provider version constraint:

terraform {
  required_version = ">= 1.2"

  required_providers {
    alicloud = {
      source  = "aliyun/alicloud"
      version = ">= 1.82.0"
    }
  }
}

provider "alicloud" {
  region = var.region
}

Variable definitions

Define input variables in a variables.tf file:

# --- General ---
variable "region" {
  type        = string
  description = "The Alibaba Cloud region for resource deployment."
  default     = "cn-hangzhou"
}

# --- Cluster ---
variable "cluster_name" {
  type        = string
  description = "The name of the EDAS ECS cluster."
  default     = "tf-example-cluster"
}

variable "cluster_type" {
  type        = string
  description = "The cluster type. Valid value: 2 (ECS cluster)."
  default     = "2"
}

variable "network_mode" {
  type        = string
  description = "The network mode. Valid values: 1 (classic network), 2 (VPC)."
  default     = "2"
}

variable "logical_region_id" {
  type        = string
  description = "The logical region ID assigned by EDAS. Usually matches the physical region ID, such as cn-hangzhou."
}

variable "vpc_id" {
  type        = string
  description = "The ID of the VPC where the ECS cluster resides. Required when network_mode is 2."
}

variable "instance_ids" {
  type        = list(string)
  description = "A list of ECS instance IDs to add to the EDAS cluster."
}

# --- Application ---
variable "application_name" {
  type        = string
  description = "The name of the EDAS application."
}

variable "package_type" {
  type        = string
  description = "The package type of the application. Valid values: WAR, JAR."
  default     = "WAR"
}

variable "build_pack_id" {
  type        = number
  description = "The build pack ID (runtime environment stack) for the application. Obtain available IDs from the EDAS console."
}

variable "health_check_url" {
  type        = string
  description = "The URL path for application health checks, such as /health."
  default     = ""
}

variable "ecu_info" {
  type        = list(string)
  description = "A list of Elastic Compute Unit (ECU) IDs for the application. ECUs represent computing resources allocated within the EDAS cluster."
  default     = []
}

variable "war_url" {
  type        = string
  description = "The URL of the application deployment package (WAR or JAR file)."
}

variable "package_version" {
  type        = string
  description = "The version label for this deployment package."
}

# --- SLB ---
variable "slb_id" {
  type        = string
  description = "The ID of the SLB instance to bind to the application."
}

variable "slb_ip" {
  type        = string
  description = "The IP address of the SLB instance."
}

variable "slb_type" {
  type        = string
  description = "The SLB listener type. Valid values: internet, intranet."
  default     = "internet"
}

variable "listener_port" {
  type        = number
  description = "The listening port on the SLB instance."
  default     = 80
}

variable "vserver_group_id" {
  type        = string
  description = "The ID of the vServer group on the SLB instance."
  default     = ""
}

# --- Deploy group ---
variable "group_name" {
  type        = string
  description = "The name of the deploy group (also known as an application group in the EDAS console)."
  default     = "tf-example-group"
}

variable "force_status" {
  type        = bool
  description = "Whether to force the scaling operation when the application is being deployed."
  default     = false
}

Step 1: Create an ECS cluster and add instances

Define the EDAS ECS cluster and attach ECS instances. Save the following configuration in main.tf:

# Create an EDAS ECS cluster
resource "alicloud_edas_cluster" "this" {
  cluster_name      = var.cluster_name

  # cluster_type: 2 = ECS cluster
  cluster_type      = var.cluster_type

  # network_mode: 1 = classic network, 2 = VPC
  network_mode      = var.network_mode

  logical_region_id = var.logical_region_id
  vpc_id            = var.vpc_id
}

# Add ECS instances to the cluster
resource "alicloud_edas_instance_cluster_attachment" "this" {
  cluster_id   = alicloud_edas_cluster.this.id
  instance_ids = var.instance_ids
}

Step 2: Create an application and bind SLB

Create an EDAS application in the cluster and bind an SLB instance for traffic routing:

# Create an EDAS ECS application
resource "alicloud_edas_application" "this" {
  application_name  = var.application_name
  package_type      = var.package_type
  cluster_id        = alicloud_edas_cluster.this.id
  build_pack_id     = var.build_pack_id
  descriotion       = var.application_name
  health_check_url  = var.health_check_url
  logical_region_id = var.logical_region_id
  ecu_info          = var.ecu_info
  group_id          = ""
  package_version   = var.package_version
  war_url           = var.war_url
}

# Bind an SLB instance to the application
resource "alicloud_edas_slb_attachment" "this" {
  app_id           = alicloud_edas_application.this.id
  slb_id           = var.slb_id
  slb_ip           = var.slb_ip
  type             = var.slb_type
  listener_port    = var.listener_port
  vserver_group_id = var.vserver_group_id
}
Note

The descriotion parameter name is a known misspelling in the Alibaba Cloud Terraform provider. Use descriotion (not description) to match the provider API.

Step 3: Create a deploy group and scale out the application

Create a deploy group, scale out instances, and deploy the application package:

# Create a deploy group (application group in the EDAS console)
resource "alicloud_edas_deploy_group" "this" {
  app_id     = alicloud_edas_application.this.id
  group_name = var.group_name
}

# Scale out the application by adding ECUs to the deploy group
resource "alicloud_edas_application_scale" "this" {
  app_id       = alicloud_edas_application.this.id

  # deploy_group ID is the third segment of the composite ID (format: app_id:group_name:group_id)
  deploy_group = split(":", alicloud_edas_deploy_group.this.id)[2]

  ecu_info     = var.ecu_info
  force_status = var.force_status
}

# Delay to prevent race conditions between scaling and deployment
resource "null_resource" "delay" {
  provisioner "local-exec" {
    command = "sleep 5"
  }
  triggers = {
    "before" = join(",", [alicloud_edas_application_scale.this.id])
  }
}

# Deploy the application package to the deploy group
resource "alicloud_edas_application_deployment" "this" {
  depends_on = [
    alicloud_edas_application_scale.this,
  ]

  app_id          = alicloud_edas_application.this.id
  group_id        = split(":", alicloud_edas_deploy_group.this.id)[2]
  package_version = var.package_version
  war_url         = var.war_url
}

Output definitions

Add output values in an outputs.tf file to retrieve key resource identifiers after deployment:

output "cluster_id" {
  description = "The ID of the EDAS ECS cluster."
  value       = alicloud_edas_cluster.this.id
}

output "application_id" {
  description = "The ID of the EDAS application."
  value       = alicloud_edas_application.this.id
}

output "deploy_group_id" {
  description = "The ID of the deploy group."
  value       = split(":", alicloud_edas_deploy_group.this.id)[2]
}

output "slb_binding_id" {
  description = "The ID of the SLB binding."
  value       = alicloud_edas_slb_attachment.this.id
}

Deploy the infrastructure

Initialize the working directory

Run terraform init to download the Alibaba Cloud provider plugin:

terraform init

Expected output:

Initializing the backend...

Initializing provider plugins...
- Finding aliyun/alicloud versions matching ">= 1.82.0"...
- Installing aliyun/alicloud v1.xxx.x...

Terraform has been successfully initialized!

Preview the execution plan

Run terraform plan to review the resources Terraform will create:

terraform plan

Confirm the plan includes the expected resources: an EDAS cluster, instance attachment, application, SLB attachment, deploy group, application scale, and application deployment.

Apply the configuration

Run terraform apply to create the resources:

terraform apply

Type yes when prompted. Terraform creates resources in dependency order: cluster, instances, application, SLB binding, deploy group, scaling, and deployment.

Verify the deployment

After terraform apply completes, verify the resources:

  1. Check the Terraform outputs:

       terraform output
  2. View the resource state:

       terraform show
  3. Log in to the EDAS console and verify:

    • The ECS cluster appears under Resource Management > Clusters.

    • The application appears under Application Management with a Running status.

    • The SLB instance is bound to the application.

    • The deploy group is listed under the application's Deploy Group tab.

Data source reference

Use these data sources to query existing EDAS resources:

Data sourceDescriptionDocumentation
alicloud_edas_applicationsQuery EDAS applications, including ECS and Container Service for Kubernetes (ACK) applicationsalicloud_edas_applications
alicloud_edas_clustersQuery EDAS clusters, including ECS and ACK clustersalicloud_edas_clusters
alicloud_edas_deploy_groupsQuery deploy groups for ECS applications in EDASalicloud_edas_deploy_groups

Resource reference

The following table lists the EDAS Terraform resources used in this tutorial:

ResourceDescriptionDocumentation
alicloud_edas_clusterManage an EDAS ECS clusteralicloud_edas_cluster
alicloud_edas_instance_cluster_attachmentAdd ECS instances to an EDAS ECS clusteralicloud_edas_instance_cluster_attachment
alicloud_edas_applicationManage an ECS application in EDASalicloud_edas_application
alicloud_edas_slb_attachmentBind an SLB instance to an EDAS ECS applicationalicloud_edas_slb_attachment
alicloud_edas_deploy_groupManage a deploy group for an EDAS ECS applicationalicloud_edas_deploy_group
alicloud_edas_application_scaleScale out an EDAS ECS applicationalicloud_edas_application_scale
alicloud_edas_application_deploymentDeploy an application package to an EDAS ECS applicationalicloud_edas_application_deployment

EDAS ECS module

For a production-ready, reusable module that encapsulates these resources, see the terraform-alicloud-edas module on GitHub.

Clean up resources

To avoid ongoing charges, destroy the resources when you no longer need them:

terraform destroy

Type yes when prompted.

Warning

terraform destroy permanently deletes all resources managed by this configuration, including the EDAS cluster, applications, and deploy groups. Verify that you no longer need these resources before confirming.