From ce9cadcd80b9a5ec5acf41cd429ed783aafd8257 Mon Sep 17 00:00:00 2001 From: Jamal Maduro Date: Thu, 9 Jun 2022 12:44:07 -0700 Subject: [PATCH 1/2] User resources: add the username to the connection details secret output Signed-off-by: Jamal Maduro --- config/sql/config.go | 12 ++++++++++++ examples/sql/user.yaml | 3 +++ 2 files changed, 15 insertions(+) diff --git a/config/sql/config.go b/config/sql/config.go index 9981854a..cc687888 100644 --- a/config/sql/config.go +++ b/config/sql/config.go @@ -21,6 +21,8 @@ const ( CloudSQLSecretConnectionName = "connectionName" + CloudSQLUserName = "userName" + PrivateIPKey = "privateIP" PublicIPKey = "publicIP" ) @@ -149,6 +151,16 @@ func Configure(p *config.Provider) { //nolint:gocyclo Type: "DatabaseInstance", } + r.Sensitive.AdditionalConnectionDetailsFn = func(attr map[string]interface{}) (map[string][]byte, error) { + conn := map[string][]byte{} + // reference: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_user#argument-reference + // map the Terraform attribute name to the Provider's connection details attribute name + if a, ok := attr["name"].(string); ok { + conn[CloudSQLUserName] = []byte(a) + } + return conn, nil + } + r.UseAsync = true }) p.AddResourceConfigurator("google_sql_ssl_cert", func(r *config.Resource) { diff --git a/examples/sql/user.yaml b/examples/sql/user.yaml index 51390cd1..8abc102d 100644 --- a/examples/sql/user.yaml +++ b/examples/sql/user.yaml @@ -18,3 +18,6 @@ spec: key: password instanceRef: name: example-instance + writeConnectionSecretToRef: + name: example-sql-user-secret + namespace: crossplane-system From 118525354f49d3e1e8b6aa2ac0a58b4303a614d2 Mon Sep 17 00:00:00 2001 From: Jamal Maduro Date: Fri, 17 Jun 2022 09:25:32 -0700 Subject: [PATCH 2/2] mirror terraform field name for 'username' Signed-off-by: Jamal Maduro --- config/sql/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/sql/config.go b/config/sql/config.go index cc687888..06edf80f 100644 --- a/config/sql/config.go +++ b/config/sql/config.go @@ -21,7 +21,7 @@ const ( CloudSQLSecretConnectionName = "connectionName" - CloudSQLUserName = "userName" + CloudSQLUserName = "username" PrivateIPKey = "privateIP" PublicIPKey = "publicIP"