Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make gcp_secret_backend credentials optional #239

Merged
merged 2 commits into from
Dec 10, 2018
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