批量创建云主机 创建vpc resource "ctyunvpc" "vpctest" { name "vpcforecs" cidr "192.168.0.0/16" description "terraform测试使用" enableipv6 true } 在vpc下创建子网 resource "ctyunsubnet" "subnettest" { vpcid ctyunvpc.vpctest.id name "subnetforecs" cidr "192.168.1.0/24" description "terraform测试使用" dns [ "114.114.114.114", "8.8.8.8", ] enableipv6 true } 开通N台按需云主机 resource "ctyunecs" "ecstest" { count var.instancecount instancename "${var.instancename}${count.index + 1}" displayname "${var.instancename}${count.index + 1}" flavorname var.flavorname imageid var.imageid systemdisktype var.systemdisktype systemdisksize var.systemdisksize password var.password bandwidth var.bandwidth cycletype "ondemand" vpcid ctyunvpc.vpctest.id subnetid ctyunsubnet.subnettest.id } 模板2:创建多台配置不同的云主机,模板使用foreach语法实现 java terraform { requiredproviders { ctyun { source "ctyunit/ctyun" version "2.1.0" } } } provider "ctyun" { azname var.azname } variable "azname" { type string default "cnhuadong1jsnj1Apublicctcloud" description "可用区名称" } variable "password" { type string sensitive true description "密码" } 创建vpc resource "ctyunvpc" "vpctest" { name "vpcforecs2" cidr "192.168.0.0/16" description "terraform测试使用" enableipv6 true }