简体   繁体   English

Terraform Route 53 DNS 记录指向 AWS Aurora 读取器实例

[英]Terraform Route 53 DNS record pointing AWS Aurora reader instances

I am trying to create Aurora reader instances with terraform as below:我正在尝试使用 terraform 创建 Aurora 阅读器实例,如下所示:

resource "aws_rds_cluster_instance" "wordpress_cluster_instance_readers" {
  count              = var.number_of_instances # 3
  apply_immediately  = true
  cluster_identifier = aws_rds_cluster.wordpress_db_cluster.id
  identifier         = "wordpress-cluster-instance-reader${format(count.index + 1)}"
  instance_class     = "db.t2.small"
  engine             = aws_rds_cluster.wordpress_db_cluster.engine
  engine_version     = aws_rds_cluster.wordpress_db_cluster.engine_version

  depends_on = [aws_rds_cluster.wordpress_db_cluster]
}

for Route53 DNS pointing to Aurora readers I used.对于 Route53 DNS 指向我使用的 Aurora 阅读器。

resource "aws_route53_record" "readers" {
  count = var.number_of_instances

  zone_id = var.zone_id
  name    = "reader${count.index + 1}.${var.domain}"
  type    = "CNAME"
  ttl     = "300"
  records = [element(aws_rds_cluster_instance.wordpress_cluster_instance_readers[*], count.index)]
}

I get below error.我得到以下错误。

│ Error: Incorrect attribute value type
│   on main.tf line 463, in resource "aws_route53_record" "readers":
│  463:   records = [element(aws_rds_cluster_instance.wordpress_cluster_instance_readers[*], count.index)]
│     ├────────────────
│     │ aws_rds_cluster_instance.wordpress_cluster_instance_readers is tuple with 3 elements
│     │ count.index is 1
│ 
│ Inappropriate value for attribute "records": element 0: string required.

How should i fix the records to reflect reader instances.我应该如何修复记录以反映读者实例。

You should be able to test your terraform code using terraform console, with that you will see the outcome of that [element....] block and understand that you are not retrieving the URL with the string that should be in the records argument Marco pointed out the kind of code that should be in that argument but I would like to add this recommendation about using terraform console.您应该能够使用 terraform 控制台测试您的 terraform 代码,这样您将看到该 [element....] 块的结果,并了解您没有使用应该在记录参数 Marco 中的字符串检索 URL指出了该参数中应该包含的代码类型,但我想添加有关使用 terraform 控制台的建议。 Once in the console, you could test进入控制台后,您可以测试

element(aws_rds_cluster_instance.wordpress_cluster_instance_readers[*], 1)

and see that is kind of the same as看看这有点像

element(aws_rds_cluster_instance.wordpress_cluster_instance_readers, 1)

Which is going to return the whole aws_rds_cluster_instance object and not the value of the element that needs to go in the records argument这将返回整个 aws_rds_cluster_instance object 而不是记录参数中需要 go 的元素的值

Now if you test现在如果你测试

aws_rds_cluster_instance.wordpress_cluster_instance_readers[1]

you are going to retrieve the same as with the previous tests not needing the element function and as in Markos sugestion if you add the element from the object that you need to retrieve you will have the string you are aiming for which is probably "endpoint"您将检索与之前不需要元素 function 的测试相同的内容,如果您从 object 添加您需要检索的元素,您将获得目标字符串,这可能是“端点”

aws_rds_cluster_instance.wordpress_cluster_instance_readers[1].endpoint

so in the end the line should be looking something like this:所以最后该行应该看起来像这样:

records = aws_rds_cluster_instance.wordpress_cluster_instance_readers[count.index].endpoint

as suggested by Marko正如马尔科所建议的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM