本文介绍如何使用Terraform创建只读实例。
前提条件
已创建RDS PostgreSQL实例,详情请参见创建RDS PostgreSQL实例。
实例状态为运行中,您可以通过如下两种方式查看:
参见查询实例详情查看参数status,如果取值为Runing则表示实例状态为运行中。
前往RDS管理控制台,切换到目标地域,找到指定实例后,查看实例状态。
操作步骤
在terraform.tf文件中增加
resource "alicloud_db_readonly_instance" "default" {}
配置项,具体配置如下:... resource "alicloud_db_readonly_instance" "default" { master_db_instance_id = alicloud_db_instance.instance.id zone_id = alicloud_db_instance.instance.zone_id engine_version = alicloud_db_instance.instance.engine_version instance_type = "pgro.n4.2c.1m" instance_storage = "50" instance_name = "${alicloud_db_instance.instance.id}ro" vswitch_id = alicloud_vswitch.main.id }
运行
terraform apply
。出现如下配置信息后,确认配置信息并输入yes,开始创建只读实例。
alicloud_db_instance.instance: Refreshing state... [id=pgm-****] alicloud_db_backup_policy.instance: Refreshing state... [id=pgm-****] Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: + create Terraform will perform the following actions: # alicloud_db_readonly_instance.default will be created + resource "alicloud_db_readonly_instance" "default" { + acl = (known after apply) + ca_type = (known after apply) + connection_string = (known after apply) + engine = (known after apply) + engine_version = "13.0" + force_restart = false + id = (known after apply) + instance_name = "pgm-****" + instance_storage = 50 + instance_type = "pgro.n4.2c.1m" + master_db_instance_id = "pgm-****" + port = (known after apply) + replication_acl = (known after apply) + resource_group_id = (known after apply) + server_cert = (known after apply) + server_key = (known after apply) + ssl_enabled = (known after apply) + target_minor_version = (known after apply) + vswitch_id = "vsw-****" + zone_id = "cn-hangzhou-j" + parameters { + name = (known after apply) + value = (known after apply) } } Plan: 1 to add, 0 to change, 0 to destroy. Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve. Enter a value:
出现类似如下日志时,表示创建成功。
alicloud_db_readonly_instance.default: Creating... alicloud_db_readonly_instance.default: Still creating... [10s elapsed] ... alicloud_db_readonly_instance.default: Still creating... [15m11s elapsed] alicloud_db_readonly_instance.default: Creation complete after 15m15s [id=pgr-****] Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
查看结果。
运行
terraform show
查看只读实例。... # alicloud_db_readonly_instance.default: resource "alicloud_db_readonly_instance" "default" { client_ca_enabled = 0 client_crl_enabled = 0 connection_string = "pgr-****.pg.rds.aliyuncs.com" deletion_protection = false engine = "PostgreSQL" engine_version = "13.0" force_restart = false id = "pgr-****" instance_name = "pgm-****" instance_storage = 50 instance_type = "pgro.n4.2c.1m" master_db_instance_id = "pgm-****" port = "5432" resource_group_id = "rg-****" ssl_enabled = 0 target_minor_version = "rds_postgres_1300_20220830" vswitch_id = "vsw-****" zone_id = "cn-hangzhou-j" }
登录RDS控制台查看只读实例。
文档内容是否对您有帮助?