Open dovka opened 1 year ago
Voting for Prioritization
Volunteering to Work on This Issue
My guess from what you provided is that you have another aws_rds_cluster_instance
resource with the same identifier
set? You'll need to have a unique string or omit it to allow Terraform to assign a random, unique identifier.
If this is not the case, please provide a complete example?
Hey @dovka 👋 Thank you for taking the time to raise this! I think I might see what's happening here. The documentation quote that you called out mentioned that you can either use the count
meta-parameter or create distinct resources. What this means is that if you just need multiple instances, but don't need varying sizes, you can use count
, as is shown in the example in the docs:
resource "aws_rds_cluster_instance" "cluster_instances" {
count = 2
identifier = "aurora-cluster-demo-${count.index}"
cluster_identifier = aws_rds_cluster.default.id
instance_class = "db.r4.large"
engine = aws_rds_cluster.default.engine
engine_version = aws_rds_cluster.default.engine_version
}
On the other hand, if you need varying sizes, you'd omit the count
parameter, and instead use multiple distinct resources, similar to:
resource "aws_rds_cluster_instance" "cluster_instance_large" {
identifier = "aurora-cluster-demo-large"
cluster_identifier = aws_rds_cluster.default.id
instance_class = "db.r4.large"
engine = aws_rds_cluster.default.engine
engine_version = aws_rds_cluster.default.engine_version
}
resource "aws_rds_cluster_instance" "cluster_instance_xlarge" {
identifier = "aurora-cluster-demo-xlarge"
cluster_identifier = aws_rds_cluster.default.id
instance_class = "db.r4.xlarge"
engine = aws_rds_cluster.default.engine
engine_version = aws_rds_cluster.default.engine_version
}
Note that the identifier
is unique; as called out above, I suspect that the error you received was due to using the same identifier for multiple instances.
Hey @dovka 👋 I wanted to follow up here and see if you're okay with this issue being closed, or whether you still need assistance.
Documentation Link
https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/rds_cluster_instance.html
Description
The doc says:
This makes it unclear to me how to create AWS Postgres Aurora read replica with instance type different from writer or one replica different form another.
I create AWS Postgres Aurora writer + 1 read replicas using the documentation example - it works with no issues.
However I need the flexibility of creating the read replicas of different instance types or even another instance class like db.serverless (Aurora serverless V2)
I can easily create and add alternative read replicas to my rds cluster via AWS UI or AWS CLI but can't figure out how to do it via terraform. Is it implemented and this is only a case of unclear documentation?
This line makes me assume that I can define multiple aws_rds_cluster_instance objects and add them up to the same cluster: "or you may specify different Cluster Instance resources with various instance_class sizes."
but docs has no examples of how to do it and my attempt to do so casues an error:
Thank you very much for your time! David
References
No response
Would you like to implement a fix?
None