使用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
    }