全部產品
Search
文件中心

Enterprise Distributed Application Service:使用Terraform建立ECS叢集並部署應用

更新時間:Nov 25, 2024

使用Terraform能夠在EDAS中建立ECS叢集並部署應用,還能夠為應用綁定SLB、建立應用分組及擴容。您可以參見文本查看可用的介面資訊和配置樣本。

介面說明

Data Sources

Resources

EDAS ECS Module

terraform-alicloud-edas

配置樣本

下文列出了在EDAS的ECS叢集中部署應用的操作樣本。請根據您的實際情況修改配置參數。

  1. 建立ECS叢集並添加ECS執行個體。

    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. 建立應用並綁定SLB。

    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. 建立應用分組,並完成應用擴容。

    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
    }