赛事靶机规模化部署 查询安全组 data "ctyunsecuritygroups" "securitygroup" { count local.vpccount vpcid ctyunvpc.vpc[count.index].id } locals { securitygroupids [for idx in range(local.vpccount) : data.ctyunsecuritygroups.securitygroup[idx].securitygroups[0].securitygroupid] } resource "ctyunsecuritygrouprule" "securitygrouprule" { 双重循环:每个安全组 × 每个规则 foreach { for index, pair in setproduct(local.securitygroupids, var.sgrules) : "rule${index}" > { securitygroupid pair[0] rule pair[1] } } securitygroupid each.value.securitygroupid direction each.value.rule.direction protocol each.value.rule.protocol destcidrip each.value.rule.destcidrip range each.value.rule.range action "accept" priority 1 ethertype "ipv4" } output "vpcid" { value ctyunvpc.vpc[].id } output "subnetid" { value ctyunsubnet.subnet[].id } vpcvariables.tf java variable "cidr" { type list(string) } variable "vpcnameprefix" { type string } variable "subnetnameprefix" { type string } variable "sgrules" { type list(object({ range string 端口/端口段 destcidrip string 目标网段 direction string 出方向还是入方向 protocol string 协议 })) default [] } 6. 在资源栈管理中,参考创建资源栈,选择刚才创建的模板,并填写参数触发资源栈的创建。 7. 8. 参考部署资源栈,完成资源栈部署。 9. 部署完成后,您可前往对应资源栈控制台查看资源的创建结果。 可以在资源Tab查看创建的资源 可以在输出Tab查看云主机ID、云主机名称、弹性IP地址、内网地址和密码等信息。 10. 使用完毕,可以点击删除按钮进行删除。