使用 Terraform 的过程是围绕 main.tf
文件进行,通过在 main.tf
文件中追加相应的内容实现资源的管理与编排。本文以创建云数据库 SQL Server 版实例为例进行说明。
以创建云数据库 SQL Server 版实例为例,追加以下内容到 main.tf
文件,参数内容需要自行修改,其中 my-instance-0
表示资源名字。
resource "volcengine_rds_mssql_instance" "my-instance-0" { db_engine_version = "SQLServer_2019_Std" instance_type = "HA" subnet_id = ["subnet-****"] node_spec = "rds.mssql.se.ha.d4.4c16g" storage_space = 100 super_account_password = "Test@****" instance_name = "Na****" charge_info { charge_type="PostPaid" } }
进入 main.tf
所在目录,在终端执行以下命令,查看执行计划。terraform plan
执行后,在终端中会显示待创建实例的相关信息,示例如下。
# [volcengine_rds_mssql_instance.my](http://volcengine_rds_mssql_instance.my)-instance-0 will be created + resource "volcengine_rds_mssql_instance" "my-instance-0" { + db_engine_version = "SQLServer_2019_Std" + id = (known after apply) + instance_name = "Na****" + instance_type = "HA" + node_spec = "rds.mssql.se.ha.d4.4c16g" + project_name = (known after apply) + storage_space = 100 + subnet_id = [ + "subnet-****", ] + super_account_password = (sensitive value) + charge_info { + auto_renew = (known after apply) + charge_end_time = (known after apply) + charge_start_time = (known after apply) + charge_status = (known after apply) + charge_type = "PostPaid" + overdue_reclaim_time = (known after apply) + overdue_time = (known after apply) + period = (known after apply) } } Plan: 1 to add, 0 to change, 0 to destroy.
执行以下命令,执行应用计划。
terraform apply
执行后,在终端中会显示确认信息。如确认执行,则输入 yes;输入其他内容可取消执行计划。
Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve. Enter a value:
输入 yes 后,开始执行计划。执行后,终端中会有以下提示消息。
$ terraform apply ... Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve. Enter a value: yes ... Apply complete! Resources: 1 added, 0 changed, 0 destroyed.