-
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/data-source/aws_pricing_product: Remove hardcoded us-east-1 han…
…dling (#16040) Reference: #8316 Reference: #15737 Previously in AWS GovCloud (US): ``` === CONT TestAccDataSourceAwsPricingProduct_ec2 TestAccDataSourceAwsPricingProduct_ec2: 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: bc4d07ae-04d0-4fad-b695-5ef067be32ee []}] --- FAIL: TestAccDataSourceAwsPricingProduct_ec2 (0.41s) === CONT TestAccDataSourceAwsPricingProduct_redshift TestAccDataSourceAwsPricingProduct_redshift: 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: 0871bc77-35ba-4dbe-aa49-7a54304986ce []}] --- FAIL: TestAccDataSourceAwsPricingProduct_redshift (0.38s) ``` Output from acceptance testing in AWS Commercial: ``` --- PASS: TestAccDataSourceAwsPricingProduct_ec2 (18.23s) --- PASS: TestAccDataSourceAwsPricingProduct_redshift (18.42s) ``` Output from acceptance testing in AWS GovCloud (US): ``` --- SKIP: TestAccDataSourceAwsPricingProduct_ec2 (1.54s) --- SKIP: TestAccDataSourceAwsPricingProduct_redshift (1.54s) ```
- Loading branch information
Showing
2 changed files
with
112 additions
and
22 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,81 @@ | ||
package aws | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/aws/endpoints" | ||
"github.com/aws/aws-sdk-go/service/pricing" | ||
"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" | ||
) | ||
|
||
// testAccPricingRegion is the chosen Pricing testing region | ||
// | ||
// Cached to prevent issues should multiple regions become available. | ||
var testAccPricingRegion string | ||
|
||
// testAccProviderPricing is the Pricing provider instance | ||
// | ||
// This Provider can be used in testing code for API calls without requiring | ||
// the use of saving and referencing specific ProviderFactories instances. | ||
// | ||
// testAccPreCheckPricing(t) must be called before using this provider instance. | ||
var testAccProviderPricing *schema.Provider | ||
|
||
// testAccProviderPricingConfigure ensures the provider is only configured once | ||
var testAccProviderPricingConfigure sync.Once | ||
|
||
// testAccPreCheckPricing verifies AWS credentials and that Pricing is supported | ||
func testAccPreCheckPricing(t *testing.T) { | ||
testAccPartitionHasServicePreCheck(pricing.EndpointsID, t) | ||
|
||
// Since we are outside the scope of the Terraform configuration we must | ||
// call Configure() to properly initialize the provider configuration. | ||
testAccProviderPricingConfigure.Do(func() { | ||
testAccProviderPricing = Provider() | ||
|
||
config := map[string]interface{}{ | ||
"region": testAccGetPricingRegion(), | ||
} | ||
|
||
diags := testAccProviderPricing.Configure(context.Background(), terraform.NewResourceConfigRaw(config)) | ||
|
||
if diags != nil && diags.HasError() { | ||
for _, d := range diags { | ||
if d.Severity == diag.Error { | ||
t.Fatalf("error configuring Pricing provider: %s", d.Summary) | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
|
||
// testAccPricingRegionProviderConfig is the Terraform provider configuration for Pricing region testing | ||
// | ||
// Testing Pricing assumes no other provider configurations | ||
// are necessary and overwrites the "aws" provider configuration. | ||
func testAccPricingRegionProviderConfig() string { | ||
return testAccRegionalProviderConfig(testAccGetPricingRegion()) | ||
} | ||
|
||
// testAccGetPricingRegion returns the Pricing region for testing | ||
func testAccGetPricingRegion() string { | ||
if testAccPricingRegion != "" { | ||
return testAccPricingRegion | ||
} | ||
|
||
if rs, ok := endpoints.RegionsForService(endpoints.DefaultPartitions(), testAccGetPartition(), pricing.ServiceName); ok { | ||
// return available region (random if multiple) | ||
for regionID := range rs { | ||
testAccPricingRegion = regionID | ||
return testAccPricingRegion | ||
} | ||
} | ||
|
||
testAccPricingRegion = testAccGetRegion() | ||
|
||
return testAccPricingRegion | ||
} |