Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

null reader endpoint address #236

Closed
bbeesley opened this issue Jun 12, 2024 · 3 comments · Fixed by #245
Closed

null reader endpoint address #236

bbeesley opened this issue Jun 12, 2024 · 3 comments · Fixed by #245
Labels
bug 🐛 An issue with the system

Comments

@bbeesley
Copy link

Describe the Bug

Since version 1.3.0, terraform plan fails with an existing cluster (running in cluster mode) as all the reader endpoint options are null.

Expected Behavior

Terraform plan with no changes to an existing cluster should just successfully plan and show no changes.

Steps to Reproduce

Create a cluster using version 1.2.0 of this module. Update to version 1.3.0. Run terraform plan.

Screenshots

Error observed during terraform plan

Error: Error in function call
  on .terraform/modules/redis.redis/main.tf line 119, in locals:
 119:   reader_endpoint_address = coalesce(local.reader_endpoint_serverless, local.reader_endpoint_cluster, local.reader_endpoint_instance)
    ├────────────────
    │ while calling coalesce(vals...)
    │ local.reader_endpoint_cluster is null
    │ local.reader_endpoint_instance is null
    │ local.reader_endpoint_serverless is null
Call to function "coalesce" failed: no non-null, non-empty-string arguments.

Environment

TERRAFORM_VERSION: 1.5.6
OS: ubuntu (github actions)
terraform-aws-elasticache-redis version: 1.3.0

Additional Context

Elasticache doesn't give you a reader endpoint when using redis in cluster mode, only a configuration endpoint, so

coalesce(local.reader_endpoint_serverless, local.reader_endpoint_cluster, local.reader_endpoint_instance)

is always going to be coalesce(null, null, null) if you're using cluster mode, and is always going to throw this error.

@bbeesley bbeesley added the bug 🐛 An issue with the system label Jun 12, 2024
@nitrocode
Copy link
Member

nitrocode commented Jun 22, 2024

I see 2 coalesce statements. From your description only the reader endpoint is affected when in cluster mode.

endpoint_address = coalesce(local.endpoint_serverless, local.endpoint_cluster, local.endpoint_instance)

reader_endpoint_address = coalesce(local.reader_endpoint_serverless, local.reader_endpoint_cluster, local.reader_endpoint_instance)

The docs say to use the configuration endpoint

Redis (cluster mode enabled) clusters, use the cluster's Configuration Endpoint for all operations that support cluster mode enabled commands. You must use a client that supports Redis Cluster (Redis 3.2). You can still read from individual node endpoints (In the API/CLI these are referred to as Read Endpoints).

https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/Endpoints.html

Since we use the aws_elasticache_replication_group resource we can add this output to the coalesce

configuration_endpoint_address - Address of the replication group configuration endpoint when cluster mode is enabled

https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_replication_group#configuration_endpoint_address

What do you think?

@marcuz
Copy link
Contributor

marcuz commented Jul 8, 2024

I see 2 coalesce statements. From your description only the reader endpoint is affected when in cluster mode.
[...]

It also fails when var.enabled is false:

│ Error: Error in function call
│ 
│   on .terraform/modules/[REDACTED]/main.tf line 113, in locals:
│  113:   endpoint_address = coalesce(local.endpoint_serverless, local.endpoint_cluster, local.endpoint_instance)
│     ├────────────────
│     │ while calling coalesce(vals...)
│     │ local.endpoint_cluster is null
│     │ local.endpoint_instance is null
│     │ local.endpoint_serverless is null
│ 
│ Call to function "coalesce" failed: no non-null, non-empty-string arguments.
╵
╷
│ Error: Error in function call
│ 
│   on .terraform/modules/[REDACTED]/main.tf line 119, in locals:
│  119:   reader_endpoint_address = coalesce(local.reader_endpoint_serverless, local.reader_endpoint_cluster, local.reader_endpoint_instance)
│     ├────────────────
│     │ while calling coalesce(vals...)
│     │ local.reader_endpoint_cluster is null
│     │ local.reader_endpoint_instance is null
│     │ local.reader_endpoint_serverless is null
│ 
│ Call to function "coalesce" failed: no non-null, non-empty-string arguments.

@chunboontangov
Copy link

as cluster_endpoint doesn't have reader endpoint, that's why when you try to read
try(aws_elasticache_replication_group.default[0].reader_endpoint_address, null) it return null
workaround for me is to update reader_endpoint_cluster = try(aws_elasticache_replication_group.default[0].reader_endpoint_address, null) to reader_endpoint_cluster = try(aws_elasticache_replication_group.default[0].configuration_endpoint_address, null)
just do it after your terraform init. good if someone can verify it's good and create a merge request in, I'm unable to push and raised a merge request for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 An issue with the system
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants