我正在尝试使用数据文件为某些数据库获取cluster_identifier和aws_db_snapshot。我的data.tf文件看起来如下:-
data "aws_rds_cluster" "cluster" {
cluster_identifier = var.rds_sources
}
data "aws_db_snapshot" "db" {
db_instance_identifier = var.rds_sources
most_recent = true
}其中rds_sources是list(string)。但是当我做terraform plan的时候,我总是碰到:-
Error: Incorrect attribute value type
│
│ on ../data.tf line 2, in data "aws_rds_cluster" "cluster":
│ 2: cluster_identifier = var.rds_sources
│ ├────────────────
│ │ var.rds_sources is a list of string, known only after apply
│
│ Inappropriate value for attribute "cluster_identifier": string required.
╵
╷
│ Error: Incorrect attribute value type
│
│ on ../data.tf line 6, in data "aws_db_snapshot" "db":
│ 6: db_instance_identifier = var.rds_sources
│ ├────────────────
│ │ var.rds_sources is a list of string, known only after apply
│
│ Inappropriate value for attribute "db_instance_identifier": string
│ required.我的问题是如何使用for循环来获取必要的信息?谢谢。
发布于 2022-08-26 20:30:41
您说的是"for循环“,所以我假设您希望使用每一个,尽管您也可以在这里使用计数。
data "aws_rds_cluster" "cluster" {
for_each = toset(var.rds_sources)
cluster_identifier = each.key
}
data "aws_db_snapshot" "db" {
for_each = toset(var.rds_sources)
db_instance_identifier = each.key
most_recent = true
}注意,根据数据库引擎的不同,您可能需要使用快照而不是aws_db_snapshot。
https://stackoverflow.com/questions/73505971
复制相似问题