Skip to content

Commit

Permalink
move cloud specific params into cloud-enabled getters
Browse files Browse the repository at this point in the history
  • Loading branch information
kpcraig committed Oct 2, 2023
1 parent f5ce3ed commit 274f0f3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 14 deletions.
48 changes: 37 additions & 11 deletions vault/resource_database_secret_backend_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -1029,16 +1029,6 @@ func getConnectionDetailsFromResponse(d *schema.ResourceData, prefix string, res
result["username_template"] = v.(string)
}
}
if v, ok := data["auth_type"]; ok {
result["auth_type"] = v.(string)
}
if v, ok := d.GetOk(prefix + "service_account_json"); ok {
result["service_account_json"] = v.(string)
} else {
if v, ok := data["service_account_json"]; ok {
result["service_account_json"] = v.(string)
}
}

return result
}
Expand All @@ -1061,6 +1051,29 @@ func getMSSQLConnectionDetailsFromResponse(d *schema.ResourceData, prefix string
return result, nil
}

func getPostgresConnectionDetailsFromResponse(d *schema.ResourceData, prefix string, resp *api.Secret) map[string]interface{} {
result := getConnectionDetailsFromResponseWithDisableEscaping(d, prefix, resp)
details := resp.Data["connection_details"]
data, ok := details.(map[string]interface{})
if !ok {
return nil
}

// cloud specific
if v, ok := data["auth_type"]; ok {
result["auth_type"] = v.(string)
}
if v, ok := d.GetOk(prefix + "service_account_json"); ok {
result["service_account_json"] = v.(string)
} else {
if v, ok := data["service_account_json"]; ok {
result["service_account_json"] = v.(string)
}
}

return result
}

func getConnectionDetailsFromResponseWithDisableEscaping(d *schema.ResourceData, prefix string, resp *api.Secret) map[string]interface{} {
result := getConnectionDetailsFromResponseWithUserPass(d, prefix, resp)
if result == nil {
Expand Down Expand Up @@ -1096,6 +1109,19 @@ func getMySQLConnectionDetailsFromResponse(d *schema.ResourceData, prefix string
result["tls_ca"] = v.(string)
}
}

// cloud specific
if v, ok := data["auth_type"]; ok {
result["auth_type"] = v.(string)
}
if v, ok := d.GetOk(prefix + "service_account_json"); ok {
result["service_account_json"] = v.(string)
} else {
if v, ok := data["service_account_json"]; ok {
result["service_account_json"] = v.(string)
}
}

return result
}

Expand Down Expand Up @@ -1855,7 +1881,7 @@ func getDBConnectionConfig(d *schema.ResourceData, engine *dbEngine, idx int,
case dbEngineOracle:
result = getConnectionDetailsFromResponseWithUserPass(d, prefix, resp)
case dbEnginePostgres:
result = getConnectionDetailsFromResponseWithDisableEscaping(d, prefix, resp)
result = getPostgresConnectionDetailsFromResponse(d, prefix, resp)
case dbEngineElasticSearch:
result = getElasticsearchConnectionDetailsFromResponse(d, prefix, resp)
case dbEngineSnowflake:
Expand Down
5 changes: 2 additions & 3 deletions vault/resource_database_secret_backend_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1670,10 +1670,9 @@ resource "vault_database_secret_backend_connection" "test" {
root_rotation_statements = ["FOOBAR"]
postgresql {
connection_url = "%s"
auth_type = "%s"
connection_url = "%s"
auth_type = "%s"
service_account_json = "%s"
disable_escaping = true
}
}
`, path, name, connURL, authType, serviceAccountJSON)
Expand Down

0 comments on commit 274f0f3

Please sign in to comment.