创建一个高可用架构 本文为您介绍如何使用模板创建一个高可用架构的操作场景及操作步骤。 操作场景 本示例以创建一个弹性负载均衡为例,介绍如何使用模板创建一个高可用架构。 不同架构内设云资源不同,本文及供参考。 操作步骤 1. 登录控制中心。 2. 在控制台首页搜索“资源编排ROS”,或在左侧产品导航栏选择“管理工具 > 资源编排ROS”,进入资源编排控制台。 3. 在左侧导航栏选择 模板管理。 4. 在模板管理页面,单击创建模板。 5. 创建高可用架构的.tf模板示例如下,请参考文档创建模板完成模板配置。 zhu java terraform { requiredproviders { ctyun { source "ctyunit/ctyun" version "1.2.0" } } } provider "ctyun" { regionid "bb9fdb42056f11eda1610242ac110002" //选定资源池 azname "cnhuadong1jsnj1Apublicctcloud" //选定可用区 } variable "instancename" { //定义变量:云主机名称 type string default "tfecsha" description "Name of EC instances to create" } variable "vpcname" { //定义变量:虚拟私有云名称 type string default "tfvpcha" description "Name of vpc to create" } variable "eipname" { //定义变量:弹性IP名称 type string default "tfeipha" description "Name of eip to create" } variable "elbname" { //定义变量:弹性负载均衡名称 type string default "tfelbha" description "Name of elb to create" } variable "instancecount" { //定义变量:创建弹性云主机数量,默认为1个 type number default 1 description "Number of EC instances to create" } variable "password" { //定义变量:云主机密码 type string sensitive true } resource "ctyunvpc" "vpctest" { //定义vpc资源:vpctest name var.vpcname cidr "192.168.0.0/16" description "terraform测试使用" enableipv6 true } resource "ctyunsubnet" "subnettest" { //定义子网资源:subnettest vpcid ctyunvpc.vpctest.id name "tfvpcha" cidr "192.168.1.0/24" description "terraform测试使用" dns [ "114.114.114.114", "8.8.8.8", "8.8.4.4" ] enableipv6 true } resource "ctyuneip" "eiptest" { //定义弹性IP资源:eiptest name var.eipname bandwidth 1 cycletype "ondemand" demandbillingtype "bandwidth" } data "ctyunzones" "test" { } locals { az1 data.ctyunzones.test.zones[0] az2 data.ctyunzones.test.zones[1] } output "az1" { value local.az1 } data "ctyunimages" "imagetest" { //确定云主机镜像 azname local.az1 name "CTyunOS 22.06 64 位" visibility "public" pageno 1 pagesize 10 } data "ctyunecsflavors" "ecsflavortest" { //确定云主机参数 azname local.az1 cpu 2 ram 4 arch "x86" series "C" type "CPUC7" } resource "ctyunecs" "ecstest" { //定义云主机资源:ecstest count var.instancecount instancename "${var.instancename}${count.index + 1}" displayname "${var.instancename}${count.index + 1}" flavorid data.ctyunecsflavors.ecsflavortest.flavors[0].id imageid data.ctyunimages.imagetest.images[0].id isdestroyinstance true systemdisktype "sata" systemdisksize 40 vpcid ctyunvpc.vpctest.id password var.password azname local.az1 cycletype "year" cyclecount 1 subnetid ctyunsubnet.subnettest.id }