-
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/service/costandusagereporting: Migrate to automatic region lookup
Reference: #8316 Reference: #15737 Output from acceptance testing in AWS Commercial: ``` --- PASS: TestAccAwsCurReportDefinition_refresh (13.35s) --- PASS: TestAccAwsCurReportDefinition_overwrite (13.53s) --- PASS: TestAccAwsCurReportDefinition_athena (13.55s) --- PASS: TestAccAwsCurReportDefinition_basic (13.56s) --- PASS: TestAccAwsCurReportDefinition_textOrCsv (13.77s) --- PASS: TestAccAwsCurReportDefinition_parquet (13.83s) --- PASS: TestAccDataSourceAwsCurReportDefinition_additional (15.71s) --- PASS: TestAccDataSourceAwsCurReportDefinition_basic (16.05s) ``` Output from acceptance testing in AWS GovCloud (US): ``` --- SKIP: TestAccAwsCurReportDefinition_refresh (1.22s) --- SKIP: TestAccAwsCurReportDefinition_athena (1.22s) --- SKIP: TestAccAwsCurReportDefinition_basic (1.23s) --- SKIP: TestAccAwsCurReportDefinition_textOrCsv (1.23s) --- SKIP: TestAccAwsCurReportDefinition_overwrite (1.24s) --- SKIP: TestAccAwsCurReportDefinition_parquet (1.25s) ```
- Loading branch information
Showing
3 changed files
with
125 additions
and
125 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,83 @@ | ||
package aws | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/aws/endpoints" | ||
"github.com/aws/aws-sdk-go/service/costandusagereportservice" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
) | ||
|
||
// testAccCurRegion is the chosen Cost and Usage Reporting testing region | ||
// | ||
// Cached to prevent issues should multiple regions become available. | ||
var testAccCurRegion string | ||
|
||
// testAccProviderCur is the Cost and Usage Reporting provider instance | ||
// | ||
// This Provider can be used in testing code for API calls without requiring | ||
// the use of saving and referencing specific ProviderFactories instances. | ||
// | ||
// testAccPreCheckCur(t) must be called before using this provider instance. | ||
var testAccProviderCur *schema.Provider | ||
|
||
// testAccProviderCurConfigure ensures the provider is only configured once | ||
var testAccProviderCurConfigure sync.Once | ||
|
||
// testAccPreCheckCur verifies AWS credentials and that Cost and Usage Reporting is supported | ||
func testAccPreCheckCur(t *testing.T) { | ||
testAccPartitionHasServicePreCheck(costandusagereportservice.ServiceName, t) | ||
|
||
// Since we are outside the scope of the Terraform configuration we must | ||
// call Configure() to properly initialize the provider configuration. | ||
testAccProviderCurConfigure.Do(func() { | ||
testAccProviderCur = Provider() | ||
|
||
config := map[string]interface{}{ | ||
"region": testAccGetCurRegion(), | ||
} | ||
|
||
err := testAccProviderCur.Configure(context.Background(), terraform.NewResourceConfigRaw(config)) | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
}) | ||
} | ||
|
||
// testAccCurRegionProviderConfig is the Terraform provider configuration for Cost and Usage Reporting region testing | ||
// | ||
// Testing Cost and Usage Reporting assumes no other provider configurations | ||
// are necessary and overwrites the "aws" provider configuration. | ||
func testAccCurRegionProviderConfig() string { | ||
return testAccRegionalProviderConfig(testAccGetCurRegion()) | ||
} | ||
|
||
// testAccGetCurRegion returns the Cost and Usage Reporting region for testing | ||
func testAccGetCurRegion() string { | ||
if testAccCurRegion != "" { | ||
return testAccCurRegion | ||
} | ||
|
||
if rs, ok := endpoints.RegionsForService(endpoints.DefaultPartitions(), testAccGetPartition(), costandusagereportservice.ServiceName); ok { | ||
// return available region (random if multiple) | ||
for regionID := range rs { | ||
testAccCurRegion = regionID | ||
return testAccCurRegion | ||
} | ||
} | ||
|
||
testAccCurRegion = testAccGetRegion() | ||
|
||
return testAccCurRegion | ||
} | ||
|
||
// testAccProviderFactoriesCur initializes providers for Cost and Usage Reporting testing. | ||
// | ||
// Deprecated: This will be replaced with testAccProviderFactories when it only returns the "aws" provider | ||
func testAccProviderFactoriesCur() map[string]func() (*schema.Provider, error) { | ||
return testAccProviderFactoriesInit(nil, []string{ProviderNameAws}) | ||
} |
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
Oops, something went wrong.