From ec14b04b9ec03fe9471575f851c5ab35a6ca7754 Mon Sep 17 00:00:00 2001 From: henryrecker-pingidentity <58565376+henryrecker-pingidentity@users.noreply.github.com> Date: Wed, 13 Nov 2024 10:50:46 -0600 Subject: [PATCH] Use realistic examples and tests for config_store resource (#426) --- docs/resources/config_store.md | 39 +++++++++++-- .../resource-list.tf | 5 ++ .../pingfederate_config_store/resource-map.tf | 14 +++++ .../resource-string.tf | 5 ++ .../pingfederate_config_store/resource.tf | 5 -- .../config_store_resource_gen_test.go | 57 +++++++++++++------ templates/resources/config_store.md.tmpl | 12 +++- 7 files changed, 107 insertions(+), 30 deletions(-) create mode 100644 examples/resources/pingfederate_config_store/resource-list.tf create mode 100644 examples/resources/pingfederate_config_store/resource-map.tf create mode 100644 examples/resources/pingfederate_config_store/resource-string.tf delete mode 100644 examples/resources/pingfederate_config_store/resource.tf diff --git a/docs/resources/config_store.md b/docs/resources/config_store.md index 917b90da..86d939af 100644 --- a/docs/resources/config_store.md +++ b/docs/resources/config_store.md @@ -9,13 +9,42 @@ description: |- Resource to create and manage bundle settings. -## Example Usage +## Example Usage - String ```terraform -resource "pingfederate_config_store" "example" { - bundle = "MyBundle" - setting_id = "MySetting" - string_value = "stringval" +resource "pingfederate_config_store" "enable_expressions" { + bundle = "org.sourceid.common.ExpressionManager" + setting_id = "evaluateExpressions" + string_value = "true" +} +``` + +## Example Usage - List + +```terraform +resource "pingfederate_config_store" "base64_required_plugins" { + bundle = "org.sourceid.oauth20.handlers.process.exchange.execution.SecurityTokenCreator" + setting_id = "base64-required-plugins" + list_value = ["org.sourceid.wstrust.processor.oauth.BearerAccessTokenTokenProcessor"] +} +``` + +## Example Usage - Map + +```terraform +resource "pingfederate_config_store" "signature_algorithms" { + bundle = "com.pingidentity.crypto.SignatureAlgorithms" + setting_id = "signature-algorithms" + map_value = { + "DSA_SHA1" : "http://www.w3.org/2000/09/xmldsig#dsa-sha1" + "RSA_SHA1" : "http://www.w3.org/2000/09/xmldsig#rsa-sha1" + "RSA_SHA256" : "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" + "RSA_SHA384" : "http://www.w3.org/2001/04/xmldsig-more#rsa-sha384" + "RSA_SHA512" : "http://www.w3.org/2001/04/xmldsig-more#rsa-sha512" + "ECDSA_SHA256" : "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256" + "ECDSA_SHA384" : "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha384" + "ECDSA_SHA512" : "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha512" + } } ``` diff --git a/examples/resources/pingfederate_config_store/resource-list.tf b/examples/resources/pingfederate_config_store/resource-list.tf new file mode 100644 index 00000000..14828287 --- /dev/null +++ b/examples/resources/pingfederate_config_store/resource-list.tf @@ -0,0 +1,5 @@ +resource "pingfederate_config_store" "base64_required_plugins" { + bundle = "org.sourceid.oauth20.handlers.process.exchange.execution.SecurityTokenCreator" + setting_id = "base64-required-plugins" + list_value = ["org.sourceid.wstrust.processor.oauth.BearerAccessTokenTokenProcessor"] +} \ No newline at end of file diff --git a/examples/resources/pingfederate_config_store/resource-map.tf b/examples/resources/pingfederate_config_store/resource-map.tf new file mode 100644 index 00000000..502843f9 --- /dev/null +++ b/examples/resources/pingfederate_config_store/resource-map.tf @@ -0,0 +1,14 @@ +resource "pingfederate_config_store" "signature_algorithms" { + bundle = "com.pingidentity.crypto.SignatureAlgorithms" + setting_id = "signature-algorithms" + map_value = { + "DSA_SHA1" : "http://www.w3.org/2000/09/xmldsig#dsa-sha1" + "RSA_SHA1" : "http://www.w3.org/2000/09/xmldsig#rsa-sha1" + "RSA_SHA256" : "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" + "RSA_SHA384" : "http://www.w3.org/2001/04/xmldsig-more#rsa-sha384" + "RSA_SHA512" : "http://www.w3.org/2001/04/xmldsig-more#rsa-sha512" + "ECDSA_SHA256" : "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256" + "ECDSA_SHA384" : "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha384" + "ECDSA_SHA512" : "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha512" + } +} \ No newline at end of file diff --git a/examples/resources/pingfederate_config_store/resource-string.tf b/examples/resources/pingfederate_config_store/resource-string.tf new file mode 100644 index 00000000..aab32508 --- /dev/null +++ b/examples/resources/pingfederate_config_store/resource-string.tf @@ -0,0 +1,5 @@ +resource "pingfederate_config_store" "enable_expressions" { + bundle = "org.sourceid.common.ExpressionManager" + setting_id = "evaluateExpressions" + string_value = "true" +} \ No newline at end of file diff --git a/examples/resources/pingfederate_config_store/resource.tf b/examples/resources/pingfederate_config_store/resource.tf deleted file mode 100644 index c4e29f47..00000000 --- a/examples/resources/pingfederate_config_store/resource.tf +++ /dev/null @@ -1,5 +0,0 @@ -resource "pingfederate_config_store" "example" { - bundle = "MyBundle" - setting_id = "MySetting" - string_value = "stringval" -} diff --git a/internal/acctest/config/configstore/config_store_resource_gen_test.go b/internal/acctest/config/configstore/config_store_resource_gen_test.go index 5c0f73f7..839d52f8 100644 --- a/internal/acctest/config/configstore/config_store_resource_gen_test.go +++ b/internal/acctest/config/configstore/config_store_resource_gen_test.go @@ -14,8 +14,12 @@ import ( "github.com/pingidentity/terraform-provider-pingfederate/internal/provider" ) -const configStoreBundle = "configStoreBundle" -const configStoreSettingId = "configStoreSettingId" +const configStoreMinimalBundle = "org.sourceid.common.ExpressionManager" +const configStoreMinimalId = "evaluateExpressions" +const configStoreBundle = "org.sourceid.oauth20.handlers.process.exchange.execution.SecurityTokenCreator" +const configStoreSettingId = "base64-required-plugins" +const configStoreMapBundle = "com.pingidentity.crypto.SignatureAlgorithms" +const configStoreMapSettingId = "signature-algorithms" func TestAccConfigStore_RemovalDrift(t *testing.T) { resource.Test(t, resource.TestCase{ @@ -23,7 +27,7 @@ func TestAccConfigStore_RemovalDrift(t *testing.T) { ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "pingfederate": providerserver.NewProtocol6WithError(provider.NewTestProvider()), }, - CheckDestroy: configStore_CheckDestroy, + CheckDestroy: configStore_CheckDestroyMinimal, Steps: []resource.TestStep{ { // Create the resource with a minimal model @@ -32,7 +36,7 @@ func TestAccConfigStore_RemovalDrift(t *testing.T) { { // Delete the resource on the service, outside of terraform, verify that a non-empty plan is generated PreConfig: func() { - configStore_Delete(t) + configStore_DeleteMinimal(t) }, RefreshState: true, ExpectNonEmptyPlan: true, @@ -47,7 +51,7 @@ func TestAccConfigStore_MinimalMaximal(t *testing.T) { ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "pingfederate": providerserver.NewProtocol6WithError(provider.NewTestProvider()), }, - CheckDestroy: configStore_CheckDestroy, + CheckDestroy: configStore_CheckDestroyMap, Steps: []resource.TestStep{ { // Create the resource with a minimal model @@ -99,12 +103,12 @@ func configStore_MinimalHCL() string { resource "pingfederate_config_store" "example" { bundle = "%s" setting_id = "%s" - string_value = "stringval" + string_value = "true" } data "pingfederate_config_store" "dataexample" { bundle = pingfederate_config_store.example.bundle } -`, configStoreBundle, configStoreSettingId) +`, configStoreMinimalBundle, configStoreMinimalId) } // Maximal HCL with all values set where possible @@ -113,50 +117,67 @@ func configStore_CompleteHCL() string { resource "pingfederate_config_store" "example" { bundle = "%s" setting_id = "%s" - list_value = ["val1", "val2", "val3"] + list_value = ["org.sourceid.wstrust.processor.oauth.BearerAccessTokenTokenProcessor"] } `, configStoreBundle, configStoreSettingId) } // HCL to configure map value -func configStore_MapValueHCL(firstKeyValue string) string { +func configStore_MapValueHCL(testKeyValue string) string { return fmt.Sprintf(` resource "pingfederate_config_store" "example" { bundle = "%s" setting_id = "%s" map_value = { - key1 = "%s" - key2 = "anotherone" + "DSA_SHA1" : "http://www.w3.org/2000/09/xmldsig#dsa-sha1" + "RSA_SHA1" : "http://www.w3.org/2000/09/xmldsig#rsa-sha1" + "RSA_SHA256" : "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" + "RSA_SHA384" : "http://www.w3.org/2001/04/xmldsig-more#rsa-sha384" + "RSA_SHA512" : "http://www.w3.org/2001/04/xmldsig-more#rsa-sha512" + "ECDSA_SHA256" : "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256" + "ECDSA_SHA384" : "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha384" + "ECDSA_SHA512" : "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha512" + "TEST" : "%s" } } -`, configStoreBundle, configStoreSettingId, firstKeyValue) +`, configStoreMapBundle, configStoreMapSettingId, testKeyValue) } // Validate any computed values when applying minimal HCL func configStore_CheckComputedValuesMinimal() resource.TestCheckFunc { return resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("pingfederate_config_store.example", "list_value.#", "0"), - resource.TestCheckResourceAttr("pingfederate_config_store.example", "id", configStoreSettingId), + resource.TestCheckResourceAttr("pingfederate_config_store.example", "id", configStoreMinimalId), resource.TestCheckResourceAttr("data.pingfederate_config_store.dataexample", "items.#", "1"), - resource.TestCheckResourceAttr("data.pingfederate_config_store.dataexample", "items.0.id", configStoreSettingId), + resource.TestCheckResourceAttr("data.pingfederate_config_store.dataexample", "items.0.id", configStoreMinimalId), resource.TestCheckResourceAttr("data.pingfederate_config_store.dataexample", "items.0.type", "STRING"), - resource.TestCheckResourceAttr("data.pingfederate_config_store.dataexample", "items.0.string_value", "stringval"), + resource.TestCheckResourceAttr("data.pingfederate_config_store.dataexample", "items.0.string_value", "true"), resource.TestCheckNoResourceAttr("data.pingfederate_config_store.dataexample", "items.0.map_value"), resource.TestCheckResourceAttr("data.pingfederate_config_store.dataexample", "items.0.list_value.#", "0"), ) } // Delete the resource -func configStore_Delete(t *testing.T) { +func configStore_DeleteMinimal(t *testing.T) { testClient := acctest.TestClient() - _, err := testClient.ConfigStoreAPI.DeleteConfigStoreSetting(acctest.TestBasicAuthContext(), configStoreBundle, configStoreSettingId).Execute() + _, err := testClient.ConfigStoreAPI.DeleteConfigStoreSetting(acctest.TestBasicAuthContext(), configStoreMinimalBundle, configStoreMinimalId).Execute() if err != nil { t.Fatalf("Failed to delete config: %v", err) } } // Test that any objects created by the test are destroyed -func configStore_CheckDestroy(s *terraform.State) error { +func configStore_CheckDestroyMinimal(s *terraform.State) error { + testClient := acctest.TestClient() + _, err := testClient.ConfigStoreAPI.DeleteConfigStoreSetting(acctest.TestBasicAuthContext(), configStoreMinimalBundle, configStoreMinimalId).Execute() + if err == nil { + return fmt.Errorf("config_store still exists after tests. Expected it to be destroyed") + } + return nil +} + +// Test that any objects created by the test are destroyed +func configStore_CheckDestroyMap(s *terraform.State) error { testClient := acctest.TestClient() _, err := testClient.ConfigStoreAPI.DeleteConfigStoreSetting(acctest.TestBasicAuthContext(), configStoreBundle, configStoreSettingId).Execute() if err == nil { diff --git a/templates/resources/config_store.md.tmpl b/templates/resources/config_store.md.tmpl index f66c6440..0de3b34b 100644 --- a/templates/resources/config_store.md.tmpl +++ b/templates/resources/config_store.md.tmpl @@ -9,9 +9,17 @@ description: |- {{ .Description | trimspace }} -## Example Usage +## Example Usage - String -{{ tffile (printf "%s%s%s" "examples/resources/" .Name "/resource.tf") }} +{{ tffile (printf "%s%s%s" "examples/resources/" .Name "/resource-string.tf") }} + +## Example Usage - List + +{{ tffile (printf "%s%s%s" "examples/resources/" .Name "/resource-list.tf") }} + +## Example Usage - Map + +{{ tffile (printf "%s%s%s" "examples/resources/" .Name "/resource-map.tf") }} {{ .SchemaMarkdown | trimspace }}