From badbb8ada8eceb76e3efff74de29330012dd9182 Mon Sep 17 00:00:00 2001 From: Kay Craig Date: Wed, 11 Dec 2024 14:21:01 -0500 Subject: [PATCH] add tests for import and update --- vault/resource_aws_secret_backend_test.go | 37 +++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/vault/resource_aws_secret_backend_test.go b/vault/resource_aws_secret_backend_test.go index 0543cc4e6..560b3818b 100644 --- a/vault/resource_aws_secret_backend_test.go +++ b/vault/resource_aws_secret_backend_test.go @@ -95,8 +95,26 @@ func TestAccAWSSecretBackend_fallback(t *testing.T) { resource.TestCheckResourceAttr(resourceName, consts.FieldSTSRegion, "us-west-1"), resource.TestCheckResourceAttr(resourceName, consts.FieldSTSFallbackRegions+".0", "us-east-2"), resource.TestCheckResourceAttr(resourceName, consts.FieldSTSFallbackRegions+".1", "us-east-1"), + resource.TestCheckResourceAttr(resourceName, consts.FieldSTSFallbackRegions+".#", "2"), resource.TestCheckResourceAttr(resourceName, consts.FieldSTSFallbackEndpoints+".0", "https://sts.us-east-2.amazonaws.com"), resource.TestCheckResourceAttr(resourceName, consts.FieldSTSFallbackEndpoints+".1", "https://sts.us-east-1.amazonaws.com"), + resource.TestCheckResourceAttr(resourceName, consts.FieldSTSFallbackEndpoints+".#", "2"), + ), + }, + testutil.GetImportTestStep(resourceName, false, nil, consts.FieldSecretKey, consts.FieldDisableRemount), + { + Config: testAccAWSSecretBackendConfig_fallbackUpdated(path, accessKey, secretKey), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, consts.FieldPath, path), + resource.TestCheckResourceAttr(resourceName, consts.FieldDescription, "updated description"), + resource.TestCheckResourceAttr(resourceName, consts.FieldSTSEndpoint, "https://sts.us-central-2.amazonaws.com"), + resource.TestCheckResourceAttr(resourceName, consts.FieldSTSRegion, "us-central-2"), + resource.TestCheckResourceAttr(resourceName, consts.FieldSTSFallbackRegions+".0", "us-east-2"), + resource.TestCheckResourceAttr(resourceName, consts.FieldSTSFallbackRegions+".1", "eu-central-1"), + resource.TestCheckResourceAttr(resourceName, consts.FieldSTSFallbackRegions+".#", "2"), + resource.TestCheckResourceAttr(resourceName, consts.FieldSTSFallbackEndpoints+".0", "https://sts.us-east-2.amazonaws.com"), + resource.TestCheckResourceAttr(resourceName, consts.FieldSTSFallbackEndpoints+".1", "https://sts.eu-central-1.amazonaws.com"), + resource.TestCheckResourceAttr(resourceName, consts.FieldSTSFallbackEndpoints+".#", "2"), ), }, }, @@ -241,6 +259,25 @@ resource "vault_aws_secret_backend" "test" { }`, path, accessKey, secretKey) } +func testAccAWSSecretBackendConfig_fallbackUpdated(path, accessKey, secretKey string) string { + return fmt.Sprintf(` +resource "vault_aws_secret_backend" "test" { + path = "%s" + description = "updated description" + default_lease_ttl_seconds = 60 + max_lease_ttl_seconds = 1000 + access_key = "%s" + secret_key = "%s" + region = "us-central-2" + + sts_endpoint = "https://sts.us-central-2.amazonaws.com" + + sts_region = "us-central-2" + sts_fallback_regions = ["us-east-2", "eu-central-1"] + sts_fallback_endpoints = ["https://sts.us-east-2.amazonaws.com","https://sts.eu-central-1.amazonaws.com"] +}`, path, accessKey, secretKey) +} + func testAccAWSSecretBackendConfig_wifBasic(path string) string { return fmt.Sprintf(` resource "vault_aws_secret_backend" "test" {