Skip to content

Commit

Permalink
Allow updating connection certificate (#40)
Browse files Browse the repository at this point in the history
* Allow updating connection certificate

* Remove calculated flag and add description

* Update docs

* docs fix

* Add id field back to docs
  • Loading branch information
dave-pollock authored Oct 2, 2022
1 parent 06246c4 commit 89a1ec4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.8.8
0.8.9
4 changes: 2 additions & 2 deletions docs/resources/connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ resource "looker_connection" "snowflake_connection" {
### Optional

- `after_connect_statements` (String)
- `certificate` (String, Sensitive)
- `certificate` (String, Sensitive) Base64 encoded certificate body for server authentication (when appropriate for the dialect). Due to limitations in the Looker API, changes made outside of Terraform cannot be detected.
- `db_timezone` (String)
- `disable_context_comment` (Boolean)
- `file_type` (String)
- `file_type` (String) Certificate key file type (.json or .p12).
- `id` (String) The ID of this resource.
- `jdbc_additional_params` (String)
- `maintenance_cron` (String)
Expand Down
25 changes: 8 additions & 17 deletions pkg/looker/resource_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,19 @@ func resourceConnection() *schema.Resource {
},
},
"certificate": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Sensitive: true,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
return d.Id() != ""
},
Type: schema.TypeString,
Description: "Base64 encoded certificate body for server authentication (when " +
"appropriate for the dialect). Due to limitations in the Looker " +
"API, changes made outside of Terraform cannot be detected.",
Optional: true,
Sensitive: true,
StateFunc: hash,
},
"file_type": {
Type: schema.TypeString,
Description: "Certificate key file type (.json or .p12).",
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{".json", ".p12"}, false),
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
return d.Id() != ""
},
},
"database": {
Type: schema.TypeString,
Expand Down Expand Up @@ -480,12 +477,6 @@ func flattenConnection(connection apiclient.DBConnection, d *schema.ResourceData
if err := d.Set("password", connection.Password); err != nil {
return err
}
if err := d.Set("certificate", connection.Certificate); err != nil {
return err
}
if err := d.Set("file_type", connection.FileType); err != nil {
return err
}
if err := d.Set("database", connection.Database); err != nil {
return err
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/looker/util.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package looker

import (
"crypto/sha256"
"encoding/hex"
"fmt"
"strings"

Expand Down Expand Up @@ -51,3 +53,11 @@ func flattenStringListToSet(strings []string) *schema.Set {
// }
// return ints
// }

func hash(val interface{}) string {
if val == nil || val.(string) == "" {
return ""
}
sha := sha256.Sum256([]byte(val.(string)))
return hex.EncodeToString(sha[:])
}

0 comments on commit 89a1ec4

Please sign in to comment.