Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions vault/resource_gcp_secret_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func gcpSecretBackendResource() *schema.Resource {
},
"credentials": {
Type: schema.TypeString,
Required: true,
Optional: true,
Description: "JSON-encoded credentials to use to connect to GCP",
Sensitive: true,
// We rebuild the attached JSON string to a simple singleline
Expand Down Expand Up @@ -105,11 +105,15 @@ func gcpSecretBackendCreate(d *schema.ResourceData, meta interface{}) error {
d.SetPartial("max_lease_ttl_seconds")

log.Printf("[DEBUG] Writing GCP configuration to %q", configPath)
data := map[string]interface{}{
"credentials": credentials,
}
if _, err := client.Logical().Write(configPath, data); err != nil {
return fmt.Errorf("error writing GCP configuration for %q: %s", path, err)
if credentials != "" {
data := map[string]interface{}{
"credentials": credentials,
}
if _, err := client.Logical().Write(configPath, data); err != nil {
return fmt.Errorf("error writing GCP configuration for %q: %s", path, err)
}
} else {
log.Printf("[DEBUG] No credentials configured")
}
log.Printf("[DEBUG] Wrote GCP configuration to %q", configPath)
d.Partial(false)
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/gcp_secret_backend.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ resource "vault_gcp_secret_backend" "gcp" {

The following arguments are supported:

* `credentials` - (Required) The GCP service account credentails in JSON format.
* `credentials` - (Optional) The GCP service account credentails in JSON format.

~> **Important** Because Vault does not support reading the configured
credentials back from the API, Terraform cannot detect and correct drift
Expand Down