From deb02086e3f26bbbbd83eab025573ff98e50985b Mon Sep 17 00:00:00 2001 From: Louis Ruch Date: Thu, 25 Aug 2022 20:55:31 -0700 Subject: [PATCH] feat(vault-library): Add support for credential type --- docs/resources/credential_library_vault.md | 1 + .../resource_credential_library_vault.go | 9 +++++ .../resource_credential_library_vault_test.go | 33 ++++++++++++++++++- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/docs/resources/credential_library_vault.md b/docs/resources/credential_library_vault.md index eff2fc57..2e4ed122 100644 --- a/docs/resources/credential_library_vault.md +++ b/docs/resources/credential_library_vault.md @@ -68,6 +68,7 @@ EOT ### Optional +- `credential_type` (String) The type of credential the library generates. - `description` (String) The Vault credential library description. - `http_method` (String) The HTTP method the library uses when requesting credentials from Vault. Defaults to 'GET' - `http_request_body` (String) The body of the HTTP request the library sends to Vault when requesting credentials. Only valid if `http_method` is set to `POST`. diff --git a/internal/provider/resource_credential_library_vault.go b/internal/provider/resource_credential_library_vault.go index d6553b8c..2dbff4f8 100644 --- a/internal/provider/resource_credential_library_vault.go +++ b/internal/provider/resource_credential_library_vault.go @@ -15,6 +15,7 @@ const ( credentialLibraryVaultHttpMethodKey = "http_method" credentialLibraryVaultHttpRequestBodyKey = "http_request_body" credentialLibraryVaultPathKey = "path" + credentialLibraryCredentialTypeKey = "credential_type" ) var libraryVaultAttrs = []string{ @@ -72,6 +73,11 @@ func resourceCredentialLibraryVault() *schema.Resource { Type: schema.TypeString, Required: true, }, + credentialLibraryCredentialTypeKey: { + Description: "The type of credential the library generates.", + Type: schema.TypeString, + Optional: true, + }, }, } } @@ -120,6 +126,9 @@ func resourceCredentialLibraryCreateVault(ctx context.Context, d *schema.Resourc if v, ok := d.GetOk(credentialLibraryVaultPathKey); ok { opts = append(opts, credentiallibraries.WithVaultCredentialLibraryPath(v.(string))) } + if v, ok := d.GetOk(credentialLibraryCredentialTypeKey); ok { + opts = append(opts, credentiallibraries.WithCredentialType(v.(string))) + } var credentialStoreId string cid, ok := d.GetOk(credentialStoreIdKey) diff --git a/internal/provider/resource_credential_library_vault_test.go b/internal/provider/resource_credential_library_vault_test.go index ff87d74c..c53c8ae1 100644 --- a/internal/provider/resource_credential_library_vault_test.go +++ b/internal/provider/resource_credential_library_vault_test.go @@ -17,6 +17,7 @@ import ( const ( vaultCredResc = "boundary_credential_library_vault.example" + vaultCredTypedResc = "boundary_credential_library_vault.typed_example" vaultCredLibName = "foo" vaultCredLibDesc = "the foo" vaultCredLibPath = "/foo/bar" @@ -52,6 +53,19 @@ resource "boundary_credential_library_vault" "example" { vaultCredLibMethodPost, vaultCredLibRequestBody) +var vaultTypedCredLibResource = fmt.Sprintf(` +resource "boundary_credential_library_vault" "typed_example" { + name = "%s" + description = "%s" + credential_store_id = boundary_credential_store_vault.example.id + path = "%s" + http_method = "%s" + credential_type = "ssh_private_key" +}`, vaultCredLibName, + vaultCredLibDesc, + vaultCredLibPath, + vaultCredLibMethodGet) + func TestAccCredentialLibraryVault(t *testing.T) { tc := controller.NewTestController(t, tcConfig...) defer tc.Shutdown() @@ -69,8 +83,9 @@ func TestAccCredentialLibraryVault(t *testing.T) { var provider *schema.Provider resource.Test(t, resource.TestCase{ + IsUnitTest: true, ProviderFactories: providerFactories(&provider), - CheckDestroy: testAccCheckAuthMethodResourceDestroy(t, provider), + CheckDestroy: testAccCheckCredentialLibraryVaultResourceDestroy(t, provider), Steps: []resource.TestStep{ { // create @@ -101,6 +116,22 @@ func TestAccCredentialLibraryVault(t *testing.T) { ), }, importStep(vaultCredResc), + + { + // create typed credential library, note credential type is immutable so no need for update test + Config: testConfig(url, fooOrg, firstProjectFoo, credStoreRes, vaultCredLibResourceUpdate, vaultTypedCredLibResource), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(vaultCredTypedResc, NameKey, vaultCredLibName), + resource.TestCheckResourceAttr(vaultCredTypedResc, DescriptionKey, vaultCredLibDesc), + resource.TestCheckResourceAttr(vaultCredTypedResc, credentialLibraryVaultPathKey, vaultCredLibPath), + resource.TestCheckResourceAttr(vaultCredTypedResc, credentialLibraryVaultHttpMethodKey, vaultCredLibMethodGet), + resource.TestCheckResourceAttr(vaultCredTypedResc, credentialLibraryVaultHttpRequestBodyKey, ""), + resource.TestCheckResourceAttr(vaultCredTypedResc, credentialLibraryCredentialTypeKey, "ssh_private_key"), + + testAccCheckCredentialLibraryVaultResourceExists(provider, vaultCredTypedResc), + ), + }, + importStep(vaultCredResc), }, }) }