Skip to content

Commit

Permalink
Merge pull request #645 from haarchri/feature/memorydbcluster-connect…
Browse files Browse the repository at this point in the history
…iondetails

feat(memorydb): add connectiondetails for cluster
  • Loading branch information
sergenyalcin authored Apr 4, 2023
2 parents 0b639ce + 6768c08 commit 024487c
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
63 changes: 63 additions & 0 deletions config/memorydb/config.go
Original file line number Diff line number Diff line change
@@ -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
}
})
}
2 changes: 2 additions & 0 deletions config/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -201,6 +202,7 @@ func GetProvider() *config.Provider {
lakeformation.Configure,
lambda.Configure,
licensemanager.Configure,
memorydb.Configure,
mq.Configure,
neptune.Configure,
opensearch.Configure,
Expand Down
3 changes: 3 additions & 0 deletions examples/memorydb/cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 024487c

Please sign in to comment.