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

Allow vault_ldap_auth resources to be imported #387

Merged

Conversation

lucymhdavies
Copy link
Contributor

@lucymhdavies lucymhdavies commented Apr 6, 2019

Fixes #383

Having pushed this, I now see that the ldap_auth_backend part of this may become redundant, given #273

lucymhdavies and others added 2 commits April 5, 2019 17:08
Fixes hashicorp#383

```
terraform import -allow-missing-config vault_ldap_auth_backend_group.foo auth/ldap/groups/foo
vault_ldap_auth_backend_group.foo: Importing from ID "auth/ldap/groups/foo"...
vault_ldap_auth_backend_group.foo: Import complete!
  Imported vault_ldap_auth_backend_group (ID: auth/ldap/groups/foo)
vault_ldap_auth_backend_group.foo: Refreshing state... (ID: auth/ldap/groups/foo)

Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.
```

I've not updated any docs yet, and I've only manually tested
`vault_ldap_auth_backend_group` by hand so far, so this still needs docs
written and tests added.
Turns out, there's more to it than appeared to be the case from my
previous commit.

I've not run the full test suite, but only tested the resources I have
modified as follows

```
docker run -it --rm -p 8200:8200 vault server -dev -dev-root-token-id="root"

VAULT_ADDR=http://0.0.0.0:8200 VAULT_TOKEN=root TF_ACC=1 go test -v --run TestLDAPAuthBackendGroup github.com/terraform-providers/terraform-provider-vault/vault
```

Currently they fail due to, for example:

```
=== RUN   TestLDAPAuthBackendGroup_import
--- FAIL: TestLDAPAuthBackendGroup_import (0.12s)
    testing.go:538: Step 1 error: ImportStateVerify attributes not equivalent. Difference is shown below. Top is actual, bottom is expected.

        (map[string]string) {
        }

        (map[string]string) (len=2) {
         (string) (len=7) "backend": (string) (len=39) "tf-test-ldap-backend-392924653340835300",
         (string) (len=9) "groupname": (string) (len=38) "tf-test-ldap-group-3866433073382041940"
        }
```
I took inspiration from how AppRoles work, borrowing a lot of the code
from there.

```
$ VAULT_ADDR=http://0.0.0.0:8200 VAULT_TOKEN=root TF_ACC=1 go test -v --run TestLDAPAuthBackend github.com/terraform-providers/terraform-provider-vault/vault
=== RUN   TestLDAPAuthBackendGroup_import
--- PASS: TestLDAPAuthBackendGroup_import (0.11s)
=== RUN   TestLDAPAuthBackendGroup_basic
--- PASS: TestLDAPAuthBackendGroup_basic (0.09s)
=== RUN   TestLDAPAuthBackend_import
--- PASS: TestLDAPAuthBackend_import (0.08s)
=== RUN   TestLDAPAuthBackend_basic
--- PASS: TestLDAPAuthBackend_basic (0.07s)
=== RUN   TestLDAPAuthBackendUser_import
--- PASS: TestLDAPAuthBackendUser_import (0.08s)
=== RUN   TestLDAPAuthBackendUser_basic
--- PASS: TestLDAPAuthBackendUser_basic (0.08s)
PASS
ok  	github.com/terraform-providers/terraform-provider-vault/vault	0.529s
```

Needed to modify `TestLDAPAuthBackend_import` slightly, as I forgot that
`bindpass` isn't returned from the Vault API
Copy link
Contributor

@tyrannosaurus-becks tyrannosaurus-becks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lucymhdavies fantastic! Thank you!

@tyrannosaurus-becks tyrannosaurus-becks merged commit 30a5210 into hashicorp:master Apr 29, 2019
dandandy pushed a commit to dandandy/terraform-provider-vault that referenced this pull request Jun 17, 2021
Allow vault_ldap_auth resources to be imported
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

resource vault_ldap_auth_backend_group doesn't support import
2 participants