hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.81k stars 9.16k forks source link

Reader endpoint in aws_elasticache_replication_group #10519

Closed MateuszStefek closed 3 years ago

MateuszStefek commented 5 years ago

Community Note

Description

AWS ElastiCache replication group for Redis has attribute called ReaderEndpoint. It has the same structure as PrimaryEndpoint.

Terraform aws provider already gives us primary_endpoint_address attribute. Implement a new, similar attribute (reader_endpoint_address?) for the reader endpoint.

https://docs.aws.amazon.com/cli/latest/reference/elasticache/describe-replication-groups.html

New or Affected Resource(s)

jamesmcminn96 commented 4 years ago

If anyone is looking for a work around in the meantime, inferring the reader endpoint from the primary endpoint has worked well for us.

output "cache_reader_endpoint" {
  value = "${aws_elasticache_replication_group.cache.id}-ro.${
    join(
      ".",
      slice(
        split(".", aws_elasticache_replication_group.cache.primary_endpoint_address),
        1,
        length(split(".", aws_elasticache_replication_group.cache.primary_endpoint_address))
      )
    )
  }"
}
nikskiz commented 4 years ago

If anyone is looking for a work around in the meantime, inferring the reader endpoint from the primary endpoint has worked well for us.

output "cache_reader_endpoint" {
  value = "${aws_elasticache_replication_group.cache.id}-ro.${
    join(
      ".",
      slice(
        split(".", aws_elasticache_replication_group.cache.primary_endpoint_address),
        1,
        length(split(".", aws_elasticache_replication_group.cache.primary_endpoint_address))
      )
    )
  }"
}

It seems if you enable encryption in transit the endpoint is different. They are: Replica: replica.xxx.xxx.xxx.cache.amazonaws.com Master: master.xxx.xxx.xxx..cache.amazonaws.com

I managed to get the reader endpoint with the following if encryption in transit is enabled:

locals {
  # The AWS provider does not have a attribute reference for the reader_endpoint. Below is a way to get the reader_endpoint
  replace(aws_elasticache_replication_group.default.primary_endpoint_address, "/^master/", "replica")
}

Keep in mind this is only for a non-clustered redis.

tormodmacleod commented 4 years ago

If anyone is looking for a work around in the meantime, inferring the reader endpoint from the primary endpoint has worked well for us.

output "cache_reader_endpoint" {
  value = "${aws_elasticache_replication_group.cache.id}-ro.${
    join(
      ".",
      slice(
        split(".", aws_elasticache_replication_group.cache.primary_endpoint_address),
        1,
        length(split(".", aws_elasticache_replication_group.cache.primary_endpoint_address))
      )
    )
  }"
}

we CNAME the address of the master to cache.FULL_DOMAIN and were hoping to CNAME the address of the reader to cache-ro.FULL_DOMAIN in order to have a consistent endpoint for our services.

just wanted to highlight that while this workaround is good for many use cases, it doesn't negate the need for this feature :¬)

ghost commented 3 years ago

This has been released in version 3.23.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

ghost commented 3 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!