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.82k stars 9.17k forks source link

[Bug]: aws_elasticache_serverless_cache has too many endpoints #39194

Open OJFord opened 1 month ago

OJFord commented 1 month ago

Terraform Core Version

1.9.5

AWS Provider Version

5.65.0

Affected Resource(s)

Expected Behavior

endpoint should be a single object reader_endpoint should not exist

Actual Behavior

endpoint is a list of nested objects reader_endpoint is a list of nested objects

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

resource "aws_elasticache_serverless_cache" "test" {
  engine = "redis"
  name   = "test"
}

Steps to Reproduce

  1. create serverless redis cache
  2. terraform console
  3. >aws_elasticache_serverless_cache.test.endpoint

Debug Output

No response

Panic Output

No response

Important Factoids

image

References

https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_serverless_cache#endpoint

https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/GettingStarted.serverless.step2.html ('the Endpoint field')

Would you like to implement a fix?

None

github-actions[bot] commented 1 month ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

justinretzolk commented 1 month ago

Hey @OJFord 👋 Thank you for taking the time to raise this! In this case, the provider is operating as expected. The schema for the resource matches the what is returned by the underlying SDK and API. For what it's worth, it also matches what's returned by the CLI command that's mentioned in the article that you linked.

You can access the value by using

aws_elasticache_serverless_cache.example.endpoint[0].address

With that in mind, I'm going to close this issue.

justinretzolk commented 1 month ago

On a second read, I realize I've misread, and you already knew it was an object. Sorry about that! Reopening for further review with that in mind.

OJFord commented 1 month ago

@justinretzolk it says they are 'structure' not list of structure? (Or in the API docs 'object', or in the SDK *Endpoint not []Endpoint)

(It does include reader_endpoint though you're right, is that only for when engine is memcached perhaps?)

justinretzolk commented 1 month ago

Looks like we commented at the same time @OJFord 🙂. I'm not entirely certain I know the answers to your follow up questions on a quick look, so I'll leave that for someone from the team or community with a bit more context.

vtstanescu commented 1 month ago

Found this while looking if there is an open issue for the missing data source for aws_elasticache_serverless_cache, and it picked my interest. Indeed the endpoint, and reader_endpoint* should be objects, and not a list of objects.

I dug through the commit history and found they are a list of objects since their initial implementation, which, according to the PR (https://github.com/hashicorp/terraform-provider-aws/pull/34951), was implemented by @meetreks and @johnsonaj, so I think they are best to chime in why that's a list and not an object.

* - reader_endpoint is rightly part of the resource as it is part of the ServerlessCache object from AWS API, and AWS SDK for Go v2, see

There is an open issue for what I was actually looking for, sadly ignored for quite some time, https://github.com/hashicorp/terraform-provider-aws/issues/35469

OJFord commented 1 month ago

reader_endpoint is rightly part of the resource as it is part of the ServerlessCache object from AWS API, and AWS SDK for Go v2

Yeah, I'm not sure if it will have a value for redis (vs. memcached) caches though (if it does it would be the same as the endpoint and not read-only) so probably worth documenting as for when engine = "memcached".

https://docs.aws.amazon.com/search/doc-search.html?searchPath=documentation-guide&searchQuery=readerendpoint&this_doc_product=Amazon%20ElastiCache

vtstanescu commented 1 month ago

Yeah, I'm not sure if it will have a value for redis (vs. memcached) caches though (if it does it would be the same as the endpoint and not read-only) so probably worth documenting as for when engine = "memcached".

It does have a value for Redis caches, and it's not the same as the endpoint one, the port is different. Here's a snippet of the AWS CLI response of aws elasticache describe-serverless-caches --serverless-cache-name $cacheName

"Engine": "redis",
"Endpoint": {
  "Address": "<redacted>.serverless.euw1.cache.amazonaws.com",
  "Port": 6379
},
"ReaderEndpoint": {
  "Address": "<redacted>.serverless.euw1.cache.amazonaws.com",
  "Port": 6380
},