赛事靶机规模化部署 创建绑定EIP的云主机 resource "ctyunecs" "ecs" { count var.ecscount instancename "${var.instancenameprefix}${count.index + 1}" displayname "${var.displaynameprefix}${count.index + 1}" flavorname var.flavorname imageid var.imageid systemdisktype var.systemdisktype systemdisksize var.systemdisksize vpcid var.vpcids[count.index % local.vpccount] subnetid var.subnetids[count.index % local.vpccount] status var.status cycletype "ondemand" bandwidth var.bandwidth password var.passwords[count.index] } output "ecslist" { value ctyunecs.ecs } ecsvariables.tf java variable "ecscount" { type number } variable "instancenameprefix" { type string } variable "displaynameprefix" { type string } variable "flavorname" { type string } variable "imageid" { type string } variable "systemdisktype" { type string } variable "systemdisksize" { type number } variable "vpcids" { type list(string) } variable "subnetids" { type list(string) } variable "status" { type string default "running" } variable "passwords" { type list(string) } variable "bandwidth" { type number } vpcmain.tf java terraform { requiredproviders { ctyun { source "ctyunit/ctyun" version "2.1.0" } } } locals { vpccount length(var.cidr) } 创建vpc resource "ctyunvpc" "vpc" { count local.vpccount name "${var.vpcnameprefix}${count.index + 1}" cidr var.cidr[count.index] } 在vpc下创建子网 resource "ctyunsubnet" "subnet" { count local.vpccount vpcid ctyunvpc.vpc[count.index].id name "${var.subnetnameprefix}${count.index + 1}" cidr var.cidr[count.index] dns [ "114.114.114.114", "8.8.8.8", ] }