-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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_route53_query_log: Remove hardcoded environment va…
…riable handling Reference: #8316 Reference: #15737 Previously in AWS GovCloud (US): ``` === CONT TestAccAWSRoute53QueryLog_basic TestAccAWSRoute53QueryLog_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: cb8c48d8-2335-4b2f-b5f0-97cd5a4ec4d7 []}] --- FAIL: TestAccAWSRoute53QueryLog_basic (0.40s) ``` Output from acceptance testing in AWS Commercial: ``` --- PASS: TestAccAWSRoute53QueryLog_basic (46.16s) ``` Output from acceptance testing in AWS GovCloud (US): ``` --- SKIP: TestAccAWSRoute53QueryLog_basic (1.56s) ```
- Loading branch information
Showing
2 changed files
with
96 additions
and
14 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
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,87 @@ | ||
package aws | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/aws/endpoints" | ||
"github.com/aws/aws-sdk-go/service/route53" | ||
"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" | ||
) | ||
|
||
// Route 53 Query Logging can only be enabled with CloudWatch Log Groups in specific regions, | ||
|
||
// testAccRoute53QueryLogRegion is the chosen Route 53 Query Logging testing region | ||
// | ||
// Cached to prevent issues should multiple regions become available. | ||
var testAccRoute53QueryLogRegion string | ||
|
||
// testAccProviderRoute53QueryLog is the Route 53 Query Logging provider instance | ||
// | ||
// This Provider can be used in testing code for API calls without requiring | ||
// the use of saving and referencing specific ProviderFactories instances. | ||
// | ||
// testAccPreCheckRoute53QueryLog(t) must be called before using this provider instance. | ||
var testAccProviderRoute53QueryLog *schema.Provider | ||
|
||
// testAccProviderRoute53QueryLogConfigure ensures the provider is only configured once | ||
var testAccProviderRoute53QueryLogConfigure sync.Once | ||
|
||
// testAccPreCheckRoute53QueryLog verifies AWS credentials and that Route 53 Query Logging is supported | ||
func testAccPreCheckRoute53QueryLog(t *testing.T) { | ||
testAccPartitionHasServicePreCheck(route53.EndpointsID, t) | ||
|
||
// Since we are outside the scope of the Terraform configuration we must | ||
// call Configure() to properly initialize the provider configuration. | ||
testAccProviderRoute53QueryLogConfigure.Do(func() { | ||
testAccProviderRoute53QueryLog = Provider() | ||
|
||
region := testAccGetRoute53QueryLogRegion() | ||
|
||
if region == "" { | ||
t.Skip("Route 53 Query Log not available in this AWS Partition") | ||
} | ||
|
||
config := map[string]interface{}{ | ||
"region": region, | ||
} | ||
|
||
diags := testAccProviderRoute53QueryLog.Configure(context.Background(), terraform.NewResourceConfigRaw(config)) | ||
|
||
if diags != nil && diags.HasError() { | ||
for _, d := range diags { | ||
if d.Severity == diag.Error { | ||
t.Fatalf("error configuring Route 53 Query Logging provider: %s", d.Summary) | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
|
||
// testAccRoute53QueryLogRegionProviderConfig is the Terraform provider configuration for Route 53 Query Logging region testing | ||
// | ||
// Testing Route 53 Query Logging assumes no other provider configurations | ||
// are necessary and overwrites the "aws" provider configuration. | ||
func testAccRoute53QueryLogRegionProviderConfig() string { | ||
return testAccRegionalProviderConfig(testAccGetRoute53QueryLogRegion()) | ||
} | ||
|
||
// testAccGetRoute53QueryLogRegion returns the Route 53 Query Logging region for testing | ||
func testAccGetRoute53QueryLogRegion() string { | ||
if testAccRoute53QueryLogRegion != "" { | ||
return testAccRoute53QueryLogRegion | ||
} | ||
|
||
// AWS Commercial: https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/query-logs.html | ||
// AWS GovCloud (US) - only private DNS: https://docs.aws.amazon.com/govcloud-us/latest/UserGuide/govcloud-r53.html | ||
// AWS China - not available yet: https://docs.amazonaws.cn/en_us/aws/latest/userguide/route53.html | ||
switch testAccGetPartition() { | ||
case endpoints.AwsPartitionID: | ||
testAccRoute53QueryLogRegion = endpoints.UsEast1RegionID | ||
} | ||
|
||
return testAccRoute53QueryLogRegion | ||
} |