From 6768c08fecd15fe8acae23eaefbbcf9e47b39d0c Mon Sep 17 00:00:00 2001 From: Christopher Paul Haar Date: Sun, 2 Apr 2023 21:41:28 +0200 Subject: [PATCH] feat(memorydb): add connectiondetails for cluster Signed-off-by: Christopher Paul Haar --- config/memorydb/config.go | 63 ++++++++++++++++++++++++++++++++++ config/provider.go | 2 ++ examples/memorydb/cluster.yaml | 3 ++ 3 files changed, 68 insertions(+) create mode 100644 config/memorydb/config.go diff --git a/config/memorydb/config.go b/config/memorydb/config.go new file mode 100644 index 0000000000..295fffa509 --- /dev/null +++ b/config/memorydb/config.go @@ -0,0 +1,63 @@ +/* +Copyright 2022 Upbound Inc. +*/ + +package memorydb + +import ( + "fmt" + + "github.com/upbound/upjet/pkg/config" +) + +// Configure adds configurations for memorydb group. +func Configure(p *config.Provider) { + p.AddResourceConfigurator("aws_memorydb_cluster", func(r *config.Resource) { + r.UseAsync = true + + r.Sensitive.AdditionalConnectionDetailsFn = func(attr map[string]any) (map[string][]byte, error) { + conn := map[string][]byte{} + if clusterendpoints, ok := attr["cluster_endpoint"].([]any); ok { + for i, cp := range clusterendpoints { + if clusterendpoint, ok := cp.(map[string]any); ok && len(clusterendpoint) > 0 { + if address, ok := clusterendpoint["address"].(string); ok { + key := fmt.Sprintf("cluster_endpoint_%d_address", i) + conn[key] = []byte(address) + } + if port, ok := clusterendpoint["port"].(float64); ok { + key := fmt.Sprintf("cluster_endpoint_%d_port", i) + conn[key] = []byte(fmt.Sprintf("%g", port)) + } + } + } + } + if shards, ok := attr["shards"].([]any); ok { + for i, shard := range shards { + if s, ok := shard.(map[string]any); ok { + if nodes, ok := s["nodes"].([]any); ok { + for j, node := range nodes { + if nod, ok := node.(map[string]any); ok { + if endpoints, ok := nod["endpoint"].([]any); ok && len(endpoints) > 0 { + for _, endpoint := range endpoints { + if ep, ok := endpoint.(map[string]any); ok && len(ep) > 0 { + if address, ok := ep["address"].(string); ok { + key := fmt.Sprintf("shard_node_%d_%d_endpoint_address", i+1, j+1) + conn[key] = []byte(address) + } + if port, ok := ep["port"].(float64); ok { + key := fmt.Sprintf("shard_node_%d_%d_endpoint_port", i+1, j+1) + conn[key] = []byte(fmt.Sprintf("%g", port)) + } + } + } + } + } + } + } + } + } + } + return conn, nil + } + }) +} diff --git a/config/provider.go b/config/provider.go index 5aa25395e3..9648836704 100644 --- a/config/provider.go +++ b/config/provider.go @@ -62,6 +62,7 @@ import ( "github.com/upbound/provider-aws/config/lakeformation" "github.com/upbound/provider-aws/config/lambda" "github.com/upbound/provider-aws/config/licensemanager" + "github.com/upbound/provider-aws/config/memorydb" "github.com/upbound/provider-aws/config/mq" "github.com/upbound/provider-aws/config/neptune" "github.com/upbound/provider-aws/config/networkmanager" @@ -201,6 +202,7 @@ func GetProvider() *config.Provider { lakeformation.Configure, lambda.Configure, licensemanager.Configure, + memorydb.Configure, mq.Configure, neptune.Configure, opensearch.Configure, diff --git a/examples/memorydb/cluster.yaml b/examples/memorydb/cluster.yaml index f0a55daab7..ffd4f1b41f 100644 --- a/examples/memorydb/cluster.yaml +++ b/examples/memorydb/cluster.yaml @@ -19,6 +19,9 @@ spec: subnetGroupNameSelector: matchLabels: testing.upbound.io/example-name: example + writeConnectionSecretToRef: + name: memorydb-example + namespace: upbound-system --- apiVersion: ec2.aws.upbound.io/v1beta1 kind: SecurityGroup