-
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/provider: Prepare EC2-Classic handling to remove reseting defau…
…lt region environment variable and better document existing provider initialization Reference: #8316 Reference: #15737 Reference: #15791 Output from acceptance testing in AWS Commercial (DynamoDB to verify existing testAccProviderFactories handling): ``` --- PASS: TestAccAWSDynamoDbTable_Replica_Single (274.15s) --- PASS: TestAccAWSRedshiftSecurityGroup_basic (10.87s) --- PASS: TestAccAWSRedshiftSecurityGroup_ingressCidr (10.88s) --- PASS: TestAccAWSRedshiftSecurityGroup_ingressSecurityGroup (12.45s) --- PASS: TestAccAWSRedshiftSecurityGroup_updateIngressCidr (24.07s) --- PASS: TestAccAWSRedshiftSecurityGroup_updateIngressSecurityGroup (27.14s) ``` Output from acceptance testing in AWS GovCloud (US): ``` --- SKIP: TestAccAWSRedshiftSecurityGroup_updateIngressCidr (2.50s) --- SKIP: TestAccAWSRedshiftSecurityGroup_basic (2.50s) --- SKIP: TestAccAWSRedshiftSecurityGroup_ingressCidr (2.50s) --- SKIP: TestAccAWSRedshiftSecurityGroup_ingressSecurityGroup (2.50s) --- SKIP: TestAccAWSRedshiftSecurityGroup_updateIngressSecurityGroup (2.50s) ```
- Loading branch information
Showing
5 changed files
with
236 additions
and
113 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,84 @@ | ||
package aws | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/aws/endpoints" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
) | ||
|
||
const ( | ||
// EC2-Classic region testing environment variable name | ||
Ec2ClassicRegionEnvVar = "AWS_EC2_CLASSIC_REGION" | ||
) | ||
|
||
// testAccProviderEc2Classic is the EC2-Classic provider instance | ||
// | ||
// This Provider can be used in testing code for API calls without requiring | ||
// the use of saving and referencing specific ProviderFactories instances. | ||
// | ||
// testAccEC2ClassicPreCheck(t) must be called before using this provider instance. | ||
var testAccProviderEc2Classic *schema.Provider | ||
|
||
// testAccProviderEc2ClassicConfigure ensures the provider is only configured once | ||
var testAccProviderEc2ClassicConfigure sync.Once | ||
|
||
// testAccEC2ClassicPreCheck verifies AWS credentials and that EC2-Classic is supported | ||
func testAccEC2ClassicPreCheck(t *testing.T) { | ||
// Since we are outside the scope of the Terraform configuration we must | ||
// call Configure() to properly initialize the provider configuration. | ||
testAccProviderEc2ClassicConfigure.Do(func() { | ||
testAccProviderEc2Classic = Provider() | ||
|
||
config := map[string]interface{}{ | ||
"region": testAccGetEc2ClassicRegion(), | ||
} | ||
|
||
err := testAccProviderEc2Classic.Configure(context.Background(), terraform.NewResourceConfigRaw(config)) | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
}) | ||
|
||
client := testAccProviderEc2Classic.Meta().(*AWSClient) | ||
platforms := client.supportedplatforms | ||
region := client.region | ||
if !hasEc2Classic(platforms) { | ||
t.Skipf("this test can only run in EC2-Classic, platforms available in %s: %q", region, platforms) | ||
} | ||
} | ||
|
||
// testAccEc2ClassicRegionProviderConfig is the Terraform provider configuration for EC2-Classic region testing | ||
// | ||
// Testing EC2-Classic assumes no other provider configurations are necessary | ||
// and overwrites the "aws" provider configuration. | ||
func testAccEc2ClassicRegionProviderConfig() string { | ||
return testAccRegionalProviderConfig(testAccGetEc2ClassicRegion()) | ||
} | ||
|
||
// testAccGetEc2ClassicRegion returns the EC2-Classic region for testing | ||
func testAccGetEc2ClassicRegion() string { | ||
v := os.Getenv(Ec2ClassicRegionEnvVar) | ||
|
||
if v != "" { | ||
return v | ||
} | ||
|
||
if testAccGetPartition() == endpoints.AwsPartitionID { | ||
return endpoints.UsEast1RegionID | ||
} | ||
|
||
return testAccGetRegion() | ||
} | ||
|
||
// testAccProviderFactoriesEc2Classic initializes providers for EC2-Classic testing. | ||
// | ||
// Deprecated: This will be replaced with testAccProviderFactories when it only returns the "aws" provider | ||
func testAccProviderFactoriesEc2Classic() 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.