Hi,
I'm writing a module that creates a snapshot-based RDS instance if the snapshot_name variable has a value, otherwise create a plain vanilla Oracle instance.
I'm using the count attribute and conditional replace to pass the with-snapshot resource's count a 1 if there is a snapshot_name, or 0 if snapshot_name is empty.
Likewise I'm using the count attribute and conditional replace to pass the without-snapshot resource's count a 1 if there isn't a snapshot_name, or 0 if there is.
So far, so good, this code is working. But I want to create an rds_instance_address output that will take either the value of:
aws_db_instance.with_snap.address or
aws_db_instance.without_snap.address
Things I've tried:
output "rds_instance_address" {
value = "${aws_db_instance.with_snap.address}"
value = "${aws_db_instance.without_snap.address}"
}
But when without_snap has no value (because we've provisioned a snapshot-based RDS instead), rds_instance_address has no value. Same happens with:
output "rds_instance_address" {
value = "${aws_db_instance.with_snap.address}${aws_db_instance.with_snap.address}"
}
Unf output takes no count attribute, so can't use above boolean trick to assign a 1 if aws_db_instance.with_snap.address has a value, etc.
Is there any way to achieve this? The reason I need a single output that has one or other value is that I need to output to a text file and if you pass an empty variable to local-exec (that cat's variables to a text file), it errors: "local-exec provisioner command must be a non-empty string".
Many thanks