Grab multiple instances of a cluster

I have a few clusters in Aurora, I want to grab the instances within each cluster and create alarms for those intances.

data "aws_rds_cluster" "db" {
  cluster_identifier = "auroracluster3"
}

//output "cluster_instance_identifiers" {
  //value = data.aws_rds_cluster.db.reader_endpoint
//}
output "cluster_instance_identifiers" {
value = data.aws_rds_cluster_instance.db.*.id
}

I want to use these values while creating the alarms

resource "aws_cloudwatch_metric_alarm" "aurora_cpu" {
  count               = length(var.cluster_instance_identifiers)

  alarm_name          = "CPUUtilizationAlarm-${var.cluster_instance_identifiers[count.index]}"
  alarm_description   = "Aurora CPU alarm for -${var.cluster_instance_identifiers[count.index]}"

ERROR:

terraform plan 
╷
│ Error: Reference to undeclared resource
│
│   on main.tf line 6, in output "cluster_instance_identifiers":
│    6: value = data.aws_rds_cluster_instance.db.*.id
│
│ A data resource "aws_rds_cluster_instance" "db" has not been declared in the root module.
╵
╷
│ Error: Reference to undeclared resource
│
│   on main.tf line 18, in module "cloudwatch":
│   18:   cluster_instance_identifiers=data.aws_rds_cluster_instance.db.*.id
│
│ A data resource "aws_rds_cluster_instance" "db" has not been declared in the root module.
╵

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.