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

Export LDAP Auth Backend accessor #195

Merged
merged 1 commit into from
Oct 26, 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
23 changes: 22 additions & 1 deletion vault/resource_ldap_auth_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ func ldapAuthBackendResource() *schema.Resource {
return strings.Trim(v.(string), "/")
},
},

"accessor": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The accessor of the LDAP auth backend",
},
},
}
}
Expand Down Expand Up @@ -233,7 +239,22 @@ func ldapAuthBackendUpdate(d *schema.ResourceData, meta interface{}) error {

func ldapAuthBackendRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*api.Client)
path := ldapAuthBackendConfigPath(d.Id())

path := d.Id()
auths, err := client.Sys().ListAuth()
if err != nil {
return fmt.Errorf("error reading from Vault: %s", err)
}

authMount := auths[strings.Trim(path, "/")+"/"]
if authMount == nil {
return fmt.Errorf("auth mount %s not present", path)
}

d.Set("description", authMount.Description)
d.Set("accessor", authMount.Accessor)

path = ldapAuthBackendConfigPath(path)

log.Printf("[DEBUG] Reading LDAP auth backend config %q", path)
resp, err := client.Logical().Read(path)
Expand Down
5 changes: 5 additions & 0 deletions vault/resource_ldap_auth_backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ func testLDAPAuthBackendCheck_attrs(path string) resource.TestCheckFunc {
return fmt.Errorf("incorrect mount type: %s", authMount.Type)
}

if instanceState.Attributes["accessor"] != authMount.Accessor {
return fmt.Errorf("accessor in state %s does not match accessor returned from vault %s", instanceState.Attributes["accessor"], authMount.Accessor)
}

configPath := "auth/" + endpoint + "/config"

resp, err := client.Logical().Read(configPath)
Expand Down Expand Up @@ -188,6 +192,7 @@ resource "vault_ldap_auth_backend" "test" {
bindpass = "supersecurepassword"
discoverdn = false
deny_null_bind = true
description = "example"
}
`, path)

Expand Down
6 changes: 4 additions & 2 deletions website/docs/r/ldap_auth_backend.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ credentials back from the API, Terraform cannot detect and correct drift
on `bindpass`. Changing the values, however, _will_ overwrite the
previously stored values.

## Attribute Reference
## Attributes Reference

No additional attributes are exposed by this resource.
In addition to the fields above, the following attributes are exported:

* `accessor` - The accessor for this auth mount.