-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests/resource/aws_fms_admin_account: Remove hardcoded environment va…
…riable handling Reference: #8316 Reference: #15737 Previously in AWS GovCloud (US): ``` === CONT TestAccAwsFmsAdminAccount_basic TestAccAwsFmsAdminAccount_basic: provider_test.go:184: [{0 error configuring Terraform AWS Provider: error validating provider credentials: error calling sts:GetCallerIdentity: InvalidClientTokenId: The security token included in the request is invalid. status code: 403, request id: b96069f2-b851-4a14-814c-e04ebd3a1e7e []}] --- FAIL: TestAccAwsFmsAdminAccount_basic (0.33s) ``` Output from acceptance testing in AWS Commercial (standalone account): ``` --- PASS: TestAccAwsFmsAdminAccount_basic (97.32s) ``` Output from acceptance testing in AWS GovCloud (US): ``` --- SKIP: TestAccAwsFmsAdminAccount_basic (1.51s) ```
- Loading branch information
Showing
2 changed files
with
94 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package aws | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/aws/endpoints" | ||
"github.com/aws/aws-sdk-go/service/fms" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
) | ||
|
||
// Firewall Management Service admin APIs are only enabled in specific regions, otherwise: | ||
// InvalidOperationException: This operation is not supported in the 'us-west-2' region. | ||
|
||
// testAccFmsAdminRegion is the chosen Firewall Management Service testing region | ||
// | ||
// Cached to prevent issues should multiple regions become available. | ||
var testAccFmsAdminRegion string | ||
|
||
// testAccProviderFmsAdmin is the Firewall Management Service provider instance | ||
// | ||
// This Provider can be used in testing code for API calls without requiring | ||
// the use of saving and referencing specific ProviderFactories instances. | ||
// | ||
// testAccPreCheckFmsAdmin(t) must be called before using this provider instance. | ||
var testAccProviderFmsAdmin *schema.Provider | ||
|
||
// testAccProviderFmsAdminConfigure ensures the provider is only configured once | ||
var testAccProviderFmsAdminConfigure sync.Once | ||
|
||
// testAccPreCheckFmsAdmin verifies AWS credentials and that Firewall Management Service is supported | ||
func testAccPreCheckFmsAdmin(t *testing.T) { | ||
testAccPartitionHasServicePreCheck(fms.EndpointsID, t) | ||
|
||
// Since we are outside the scope of the Terraform configuration we must | ||
// call Configure() to properly initialize the provider configuration. | ||
testAccProviderFmsAdminConfigure.Do(func() { | ||
testAccProviderFmsAdmin = Provider() | ||
|
||
config := map[string]interface{}{ | ||
"region": testAccGetFmsAdminRegion(), | ||
} | ||
|
||
diags := testAccProviderFmsAdmin.Configure(context.Background(), terraform.NewResourceConfigRaw(config)) | ||
|
||
if diags != nil && diags.HasError() { | ||
for _, d := range diags { | ||
if d.Severity == diag.Error { | ||
t.Fatalf("error configuring Firewall Management Service provider: %s", d.Summary) | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
|
||
// testAccFmsAdminRegionProviderConfig is the Terraform provider configuration for Firewall Management Service region testing | ||
// | ||
// Testing Firewall Management Service assumes no other provider configurations | ||
// are necessary and overwrites the "aws" provider configuration. | ||
func testAccFmsAdminRegionProviderConfig() string { | ||
return testAccRegionalProviderConfig(testAccGetFmsAdminRegion()) | ||
} | ||
|
||
// testAccGetFmsAdminRegion returns the Firewall Management Service region for testing | ||
func testAccGetFmsAdminRegion() string { | ||
if testAccFmsAdminRegion != "" { | ||
return testAccFmsAdminRegion | ||
} | ||
|
||
testAccFmsAdminRegion = endpoints.UsEast1RegionID | ||
|
||
return testAccFmsAdminRegion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters