I’m using a module to create aws sns resources, another module to create aws cloudwatch alarm resources, and trying to to access the value of the sns topic arn of the former from the latter.
In modules/sns/outputs.tf I’ve output the sns topic arn that the module creates:
output "sns_topic_arn" {
value = aws_sns_topic.sns_topic.arn
}
Then in modules/cloudwatch-alarms/main.tf I’ve called a variable declared as “sns_topic_arn”: alarm_actions = [var.sns_topic_arn]
And finally, in the tf file where I’m calling cloudwatch-alarms module (located in a repository where I’m also calling the sns module), I’ve tried to pass in a value for sns_topic_arn by attempting to access the output of modules/sns: sns_topic_arn = "${module.sns.sns_topic_arn}"
But in doing so I get the following error:
Unsupported attribute.
This object (module.sns) does not have an attribute named "sns_topic_arn".
I’m wondering why I’m unable to access the output value from modules/sns/outputs.tf, or if there’s another way of accessing that value from the repo where I’m calling the cloudwatch-alarms module?
H’m, it’s tough to guess, given the lack of detail in the original post… Maybe some sort of name clash, or to do with how the modules are being called? I’m not sure the interpolation is required either, but I don’t think that would cause the quoted error.
Can you share some details about your problem? Maybe we can help.
I have 2 modules, calling the same sns_topic from cloudwatch. But, I am using for_each in the root’s main.tf as I have multiple clusters.
main.tf
locals {
cluster_configurations = {
for key, cluster in var.rds_clusters : key => {
cluster_identifier = cluster.cluster_identifier
engine_mode = cluster.engine_mode
sns_set_topic_name = "${cluster.cluster_identifier}-${var.rds_set_environment_name}-monitoring-topic"
}
}
}
# SNS topic
module "sns_topic" {
source = "../../modules/sns_topic"
for_each = local.cluster_configurations
sns_set_topic_name = each.value.sns_set_topic_name
}
# Cloudwatch alarms
module "cloudwatch_alarms" {
source = "../../modules/cloudwatch_monitoring_rds"
for_each = local.cluster_configurations
rds_set_cluster_identifier = "auroracluster1" //To be updated
rds_set_engine_mode = "auroracluster1" //To be updated
rds_set_environment_name = "auroracluster1" //To be updated
#set_rds_topic_arn = "monitoring" ---------> This works
set_rds_topic_arn = module.sns_topic.set_rds_topic_arn --------> This doesn't work
}
I want to know how to call that module.
Error:
╷
│ Error: Unsupported attribute
│
│ on main.tf line 37, in module “cloudwatch_alarms”:
│ 37: set_rds_topic_arn = module.sns_topic.set_rds_topic_arn[0]
│ ├──────────────── │ │ module.sns_topic is object with 2 attributes
│ │ This object does not have an attribute named “set_rds_topic_arn”.
╵
Please start a new topic for your new question. Although it might be related to the earlier question in this topic, questions posted as their own topics tend to be more visible to forum visitors and thus more likely to get a useful answer.