All Products
Search
Document Center

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

Last Updated:Nov 25, 2024

You can use Terraform to create Elastic Compute Service (ECS) clusters and deploy applications in Enterprise Distributed Application Service (EDAS), bind Server Load Balancer (SLB) to the applications, create application groups, and scale out the applications. This topic provides information about available interfaces and a configuration example.

Interface description

Data Sources

  • alicloud_edas_applications: EDAS application data sources, including ECS applications and Container Service for Kubernetes (ACK) applications in EDAS.

  • alicloud_edas_clusters: EDAS cluster data sources, including ECS clusters and ACK clusters in EDAS.

  • alicloud_edas_deploy_groups: EDAS deploy groups data sources, which are the application groups of ECS applications in EDAS.

Resources

EDAS ECS Module

terraform-alicloud-edas

Configuration example

In the following example, an application is deployed in an ECS cluster in EDAS. Modify configuration parameters as needed.

  1. Create an ECS cluster and add an ECS instance.

    resource "alicloud_edas_cluster" "this" {
      cluster_name = var.cluster_name
      cluster_type = var.cluster_type
      network_mode = var.network_mode
      logical_region_id = var.logical_region_id
      vpc_id = var.vpc_id
    }
    
    resource "alicloud_edas_instance_cluster_attachment" "this" {
      cluster_id = alicloud_edas_cluster.this[count.index].id
      instance_ids = var.instance_ids
    }
  2. Create an application and bind SLB to the application.

    resource "alicloud_edas_application" "this" {
      application_name  = var.application_name
      package_type      = var.package_type
      cluster_id        = var.cluster_id
      build_pack_id     = var.build_pack_id
      descriotion       = var.description
      health_check_url  = var.health_check_url
      logical_region_id = var.logical_region_id
      ecu_info          = var.ecu_info
      group_id          = var.group_id
      package_version   = var.package_version
      war_url           = var.war_url
    }
    
    
    resource "alicloud_edas_slb_attachment" "this" {
      app_id            = alicloud_edas_application.this[count.index].id
      slb_id            = var.slb_id
      slb_ip            = var.slb_ip
      type              = var.type
      listener_port     = var.listener_port
      vserver_group_id  = var.vserver_group_id
    }
  3. Create an application group and scale out the application.

    resource "alicloud_edas_deploy_group" "this" {
      app_id      = var.app_id
      group_name  = var.group_name
    }
    
    resource "alicloud_edas_application_scale" "this" {
      app_id        = var.app_id
      deploy_group  = split(":", alicloud_edas_deploy_group.this[count.index].id)[2]
      ecu_info      = var.ecu_info
      force_status  = var.force_status
    }
    
    
    resource "null_resource" "delay" {
      provisioner "local-exec" {
        command = "sleep 5"
      }
      triggers = {
        "before" = "${join(",", alicloud_edas_application_scale.this.*.id)}"
      }
    }
    
    resource "alicloud_edas_application_deployment" "this" {
      depends_on = [
        alicloud_edas_application_scale.this,
      ]
      app_id          = var.app_id
      group_id        = split(":", alicloud_edas_deploy_group.this[count.index].id)[2]
      package_version = var.package_version
      war_url         = var.war_url
    }