Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #64 from jmaduroUpbound/jmaduro/add-username-to-us…
Browse files Browse the repository at this point in the history
…er-resource-connection-details

User resources: add the username to the connection details secret output
  • Loading branch information
hasheddan authored Jun 17, 2022
2 parents 1893f0e + 1185253 commit 40c122f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions config/sql/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const (

CloudSQLSecretConnectionName = "connectionName"

CloudSQLUserName = "username"

PrivateIPKey = "privateIP"
PublicIPKey = "publicIP"
)
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions examples/sql/user.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ spec:
key: password
instanceRef:
name: example-instance
writeConnectionSecretToRef:
name: example-sql-user-secret
namespace: crossplane-system

0 comments on commit 40c122f

Please sign in to comment.