Skip to content

Commit

Permalink
Merge pull request hashicorp#239 from Phylu/master
Browse files Browse the repository at this point in the history
Make gcp_secret_backend credentials optional
  • Loading branch information
Becca Petrin authored Dec 10, 2018
2 parents 6d1642b + c24bb03 commit 3b9d6cb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
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

0 comments on commit 3b9d6cb

Please sign in to comment.