@@ -13,37 +13,53 @@ import (
1313// Configure configures individual resources by adding custom
1414// ResourceConfigurators.
1515func Configure (p * config.Provider ) {
16- p .AddResourceConfigurator ("google_redis_instance" , func (r * config.Resource ) {
17- config .MarkAsRequired (r .TerraformResource , "region" )
18- r .Sensitive .AdditionalConnectionDetailsFn = func (attr map [string ]any ) (map [string ][]byte , error ) {
19- conn := map [string ][]byte {}
20- if a , ok := attr ["host" ].(string ); ok {
21- conn ["host" ] = []byte (a )
16+ p .AddResourceConfigurator ("google_redis_instance" , redisInstance )
17+ p .AddResourceConfigurator ("google_redis_cluster" , redisCluster )
18+ }
19+
20+ func redisInstance (r * config.Resource ) {
21+ config .MarkAsRequired (r .TerraformResource , "region" )
22+ r .Sensitive .AdditionalConnectionDetailsFn = func (attr map [string ]any ) (map [string ][]byte , error ) {
23+ conn := map [string ][]byte {}
24+ if host , ok := attr ["host" ].(string ); ok {
25+ conn ["host" ] = []byte (host )
26+ }
27+ if port , ok := attr ["port" ].(float64 ); ok {
28+ conn ["port" ] = []byte (fmt .Sprintf ("%g" , port ))
29+ }
30+ if caCerts , ok := attr ["server_ca_certs" ].([]any ); ok {
31+ for i , ca := range caCerts {
32+ if caCerts , ok := ca .(map [string ]any ); ok && len (caCerts ) > 0 {
33+ if cert , ok := caCerts ["cert" ].(string ); ok {
34+ key := fmt .Sprintf ("server_ca_certs_%d_cert" , i )
35+ conn [key ] = []byte (cert )
36+ }
37+ }
2238 }
23- return conn , nil
2439 }
25- })
40+ return conn , nil
41+ }
42+ }
2643
27- p .AddResourceConfigurator ("google_redis_cluster" , func (r * config.Resource ) {
28- r .MarkAsRequired ("region" )
29- r .UseAsync = true
30- r .Sensitive .AdditionalConnectionDetailsFn = func (attr map [string ]any ) (map [string ][]byte , error ) {
31- conn := map [string ][]byte {}
32- if discoveryendpoints , ok := attr ["discovery_endpoints" ].([]any ); ok {
33- for i , de := range discoveryendpoints {
34- if discoveryendpoints , ok := de .(map [string ]any ); ok && len (discoveryendpoints ) > 0 {
35- if address , ok := discoveryendpoints ["address" ].(string ); ok {
36- key := fmt .Sprintf ("discovery_endpoints_%d_address" , i )
37- conn [key ] = []byte (address )
38- }
39- if port , ok := discoveryendpoints ["port" ].(float64 ); ok {
40- key := fmt .Sprintf ("discovery_endpoints_%d_port" , i )
41- conn [key ] = []byte (fmt .Sprintf ("%g" , port ))
42- }
44+ func redisCluster (r * config.Resource ) {
45+ r .MarkAsRequired ("region" )
46+ r .UseAsync = true
47+ r .Sensitive .AdditionalConnectionDetailsFn = func (attr map [string ]any ) (map [string ][]byte , error ) {
48+ conn := map [string ][]byte {}
49+ if discoveryendpoints , ok := attr ["discovery_endpoints" ].([]any ); ok {
50+ for i , de := range discoveryendpoints {
51+ if discoveryendpoints , ok := de .(map [string ]any ); ok && len (discoveryendpoints ) > 0 {
52+ if address , ok := discoveryendpoints ["address" ].(string ); ok {
53+ key := fmt .Sprintf ("discovery_endpoints_%d_address" , i )
54+ conn [key ] = []byte (address )
55+ }
56+ if port , ok := discoveryendpoints ["port" ].(float64 ); ok {
57+ key := fmt .Sprintf ("discovery_endpoints_%d_port" , i )
58+ conn [key ] = []byte (fmt .Sprintf ("%g" , port ))
4359 }
4460 }
4561 }
46- return conn , nil
4762 }
48- })
63+ return conn , nil
64+ }
4965}
0 commit comments