创建一个SQL Server高可用实例

最近更新时间:2019-12-12 16:53:30

在Terraform-ksyun目录下创建一个instance.tf文件,编辑文件按照指定格式输入创建SQL Server实例相关的配置参数,注意参数名称小写。 »Create a RDS SqlServer instance

provider "ksyun"{
  region = "cn-shanghai-3"
  access_key = ""
  secret_key = ""
}

variable "available_zone" {
  default = "cn-shanghai-3a"
}
resource "ksyun_vpc" "default" {
  vpc_name   = "ksyun-vpc-tf"
  cidr_block = "10.7.0.0/21"
}
resource "ksyun_subnet" "foo" {
  subnet_name = "ksyun-subnet-tf"
  cidr_block = "10.7.0.0/21"
  subnet_type = "Reserve"
  dhcp_ip_from = "10.7.0.2"
  dhcp_ip_to = "10.7.0.253"
  vpc_id  = "${ksyun_vpc.default.id}"
  gateway_ip = "10.7.0.1"
  dns1 = "198.18.254.41"
  dns2 = "198.18.254.40"
  availability_zone = "${var.available_zone}"
}

resource "ksyun_sqlserver" "sqlserver-1"{
  output_file = "output_file"
  dbinstanceclass= "db.ram.2|db.disk.20"
  dbinstancename = "ksyun_sqlserver_1"
  dbinstancetype = "HRDS_SS"
  engine = "SQLServer"
  engineversion = "2008r2"
  masterusername = "admin"
  masteruserpassword = "123qweASD"
  vpc_id = "${ksyun_vpc.default.id}"
  subnet_id = "${ksyun_subnet.foo.id}"
  billtype = "DAY"
}

执行 terraform plan 查看部署计划,这里参数前面的+代表新添加的资源,当销毁资源时,参数前面对应的符号会变为-;更改一些参数需要重新部署资源时,该资源前面的符号为-/+。

#terraform plan

sql1.png sql2.png

执行 terraform apply 进行资源创建

#terraform apply

sql3.png 输入 yes ,显示成功创建资源

sql4.png sql5.png

控制台查看SQL Server实例创建成功

sql.png

金山云,开启您的云计算之旅

注册有礼