Skip to content

Commit

Permalink
Use encoded db credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
bansal01yash committed Nov 13, 2024
1 parent ef63c73 commit 66ae770
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/hashicorp/terraform-plugin-framework-validators v0.4.0
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/sethvargo/go-retry v0.2.3
github.com/yugabyte/yugabytedb-managed-go-client-internal v0.0.0-20241103123630-73a2876ea773
github.com/yugabyte/yugabytedb-managed-go-client-internal v0.0.0-20241111184456-64fb00419bec
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9
github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc=
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
github.com/yugabyte/yugabytedb-managed-go-client-internal v0.0.0-20241103123630-73a2876ea773 h1:t+n2/bsR3vGpFoPKjs0vlzErRcxlVR8YHBEZawlYSa0=
github.com/yugabyte/yugabytedb-managed-go-client-internal v0.0.0-20241103123630-73a2876ea773/go.mod h1:5vW0xIzIZw+1djkiWKx0qqNmqbRBSf4mjc4qw8lIMik=
github.com/yugabyte/yugabytedb-managed-go-client-internal v0.0.0-20241111184456-64fb00419bec h1:VLtUGFreqNxI54GgSuwypYHl+MA8aqxl22bLWpxAP0w=
github.com/yugabyte/yugabytedb-managed-go-client-internal v0.0.0-20241111184456-64fb00419bec/go.mod h1:5vW0xIzIZw+1djkiWKx0qqNmqbRBSf4mjc4qw8lIMik=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
21 changes: 14 additions & 7 deletions managed/resource_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package managed

import (
"context"
"encoding/base64"
"errors"
"fmt"
"net/http"
Expand All @@ -30,6 +31,11 @@ import (

type resourceClusterType struct{}

// Short function for Base64 encoding
func b64(s string) string {
return base64.StdEncoding.EncodeToString([]byte(s))
}

func (r resourceClusterType) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) {
return tfsdk.Schema{
Description: `The resource to create a YugabyteDB cluster. Use this resource to create both
Expand Down Expand Up @@ -1018,16 +1024,17 @@ func (r resourceCluster) Create(ctx context.Context, req tfsdk.CreateResourceReq
return
}

credentials := openapiclient.NewCreateClusterRequestDbCredentialsWithDefaults()
createClusterRequest := *openapiclient.NewCreateClusterRequest(*clusterSpec)

encryptedCredentials := openapiclient.NewCreateClusterRequestEncryptedDbCredentialsWithDefaults()
if plan.Credentials.Username.IsNull() {
credentials.SetYsql(*openapiclient.NewDBCredentials(plan.Credentials.YSQLUsername.Value, plan.Credentials.YSQLPassword.Value))
credentials.SetYcql(*openapiclient.NewDBCredentials(plan.Credentials.YCQLUsername.Value, plan.Credentials.YCQLPassword.Value))
encryptedCredentials.SetYsql(*openapiclient.NewEncryptedDBCredentials(b64(plan.Credentials.YSQLUsername.Value), b64(plan.Credentials.YSQLPassword.Value)))
encryptedCredentials.SetYcql(*openapiclient.NewEncryptedDBCredentials(b64(plan.Credentials.YCQLUsername.Value), b64(plan.Credentials.YCQLPassword.Value)))
} else {
credentials.SetYsql(*openapiclient.NewDBCredentials(plan.Credentials.Username.Value, plan.Credentials.Password.Value))
credentials.SetYcql(*openapiclient.NewDBCredentials(plan.Credentials.Username.Value, plan.Credentials.Password.Value))
encryptedCredentials.SetYsql(*openapiclient.NewEncryptedDBCredentials(b64(plan.Credentials.Username.Value), b64(plan.Credentials.Password.Value)))
encryptedCredentials.SetYcql(*openapiclient.NewEncryptedDBCredentials(b64(plan.Credentials.Username.Value), b64(plan.Credentials.Password.Value)))
}

createClusterRequest := *openapiclient.NewCreateClusterRequest(*clusterSpec, *credentials)
createClusterRequest.SetEncryptedDbCredentials(*encryptedCredentials)

var cmkSpec *openapiclient.CMKSpec

Expand Down

0 comments on commit 66ae770

Please sign in to comment.