From 2320013983c0f8d16754b8c348130d52358e6bc9 Mon Sep 17 00:00:00 2001 From: Tim Birkett Date: Mon, 25 Nov 2024 16:22:51 +0000 Subject: [PATCH] feat(elasticache/serverless): Add endpoint and reader_endpoint connectionDetails --- config/elasticache/config.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/config/elasticache/config.go b/config/elasticache/config.go index 24f5ec2583..0742cfe400 100644 --- a/config/elasticache/config.go +++ b/config/elasticache/config.go @@ -180,6 +180,41 @@ func Configure(p *config.Provider) { //nolint:gocyclo r.References["kms_key_id"] = config.Reference{ TerraformName: "aws_kms_key", } + + r.Sensitive.AdditionalConnectionDetailsFn = func(attr map[string]any) (map[string][]byte, error) { + conn := map[string][]byte{} + + if endpoints, ok := attr["endpoint"].([]any); ok { + for i, ep := range endpoints { + if endpoint, ok := ep.(map[string]any); ok && len(endpoint) > 0 { + if address, ok := endpoint["address"].(string); ok { + key := fmt.Sprintf("endpoint_%d_address", i) + conn[key] = []byte(address) + } + if port, ok := endpoint["port"].(float64); ok { + key := fmt.Sprintf("endpoint_%d_port", i) + conn[key] = []byte(fmt.Sprintf("%g", port)) + } + } + } + } + if readerendpoints, ok := attr["reader_endpoint"].([]any); ok { + for i, rp := range readerendpoints { + if readerendpoint, ok := rp.(map[string]any); ok && len(readerendpoint) > 0 { + if address, ok := readerendpoint["address"].(string); ok { + key := fmt.Sprintf("cluster_endpoint_%d_address", i) + conn[key] = []byte(address) + } + if port, ok := readerendpoint["port"].(float64); ok { + key := fmt.Sprintf("cluster_endpoint_%d_port", i) + conn[key] = []byte(fmt.Sprintf("%g", port)) + } + } + } + } + + return conn, nil + } }) p.AddResourceConfigurator("aws_elasticache_user_group", func(r *config.Resource) {