使用Terraform部署应用到EDAS的ECS集群时,您可以参见文本查看可用的接口信息和配置示例。

接口说明

Data Sources

Resources

EDAS ECS Module

terraform-alicloud-edas

配置示例

下文罗列了在EDAS的ECS实例中部署应用时的一些常用操作示例。

创建ECS集群并导入实例

您可参见如下示例创建ECS集群,并导入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
}

创建应用并绑定SLB

您可参见如下示例创建应用,并为应用绑定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
}

创建应用分组和应用扩容

您可参见如下示例创建应用分组,并完成应用扩容,请根据您的实际情况修改配置参数。

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
}