如何在阿里云中定义私有区域id

How to define private zone id in Alicloud

我目前在阿里云上工作,想使用 alicloud_pvtz_zone_record 为 GPDB 资源定义 DNS,但出现如下错误。

Error: [ERROR] terraform-provider-alicloud/alicloud/resource_alicloud_pvtz_zone_record.go:167: Resource alicloud_pvtz_zone_record AddZoneRecord Failed!!! [SDK alibaba-cloud-sdk-go ERROR]:
SDK.ServerError
ErrorCode: Record.Invalid.Value
Recommend: 
RequestId: A69A1D2A-19A8-48D9-A5AC-EF3BB85C9CFE
Message: Record value is invalid.

  on ../../main.tf line 32, in resource "alicloud_pvtz_zone_record" "pvtz_zone_records":
  32: resource "alicloud_pvtz_zone_record" "pvtz_zone_records" {

下面是我的地形代码。

resource "alicloud_gpdb_instance" "gpdb_instance" {
  description          = "tf-gpdb-test"
  engine               = "gpdb"
  engine_version       = "4.3"
  instance_class       = var.gpdb_instance_class
  instance_group_count = var.gpdb_instance_group_count
  vswitch_id           = var.vswitch_id
  security_ip_list     = var.allowed_ips
}

resource "alicloud_pvtz_zone_record" "pvtz_zone_records" {
  zone_id         = var.dns_zone_id
  resource_record = "server.gpdb"
  type            = "CNAME"
  value           = alicloud_gpdb_instance.gpdb_instance.id
  ttl             = var.dns_ttl
}

在 Terraform doc 中,alicloud_pvtz_zone_record 资源仅接受值域。

在您的示例中,alicloud_pvtz_zone_record 的值 接受来自 gpdb 实例的 ID 。这就是 Terraform 产生 无效值 .

的原因

这是添加 alicloud_gpdb_connection 资源的解决方案 here:

resource "alicloud_gpdb_connection" "gpdb_connection" {
  instance_id = alicloud_gpdb_instance.gpdb_instance.id
}

resource "alicloud_pvtz_zone_record" "pvtz_zone_records" {
  zone_id         = var.dns_zone_id
  resource_record = "server.gpdb.pgsoft.local"
  type            = "CNAME"
  value           = alicloud_gpdb_connection.gpdb_connection.connection_string
  ttl             = var.dns_ttl
}

alicloud_gpdb_connection 资源输出 connection_string 这是来自特定 gpdb 实例的域 的值。