最近更新时间: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
执行 terraform apply 进行资源创建
#terraform apply
控制台查看SQL Server实例创建成功
纯净模式