Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests/resource/aws_instance: Remove hardcoded us-east-1 handling #16035

Merged
merged 1 commit into from
Nov 11, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 20 additions & 31 deletions aws/resource_aws_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package aws
import (
"fmt"
"log"
"os"
"reflect"
"regexp"
"strconv"
Expand Down Expand Up @@ -204,27 +203,21 @@ func TestAccAWSInstance_inDefaultVpcBySgId(t *testing.T) {

func TestAccAWSInstance_inEc2Classic(t *testing.T) {
resourceName := "aws_instance.test"
rInt := acctest.RandInt()
var v ec2.Instance

// EC2 Classic enabled
oldvar := os.Getenv("AWS_DEFAULT_REGION")
os.Setenv("AWS_DEFAULT_REGION", "us-east-1")
defer os.Setenv("AWS_DEFAULT_REGION", oldvar)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccEC2ClassicPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckInstanceDestroy,
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccEC2ClassicPreCheck(t) },
ProviderFactories: testAccProviderFactories,
CheckDestroy: testAccCheckInstanceDestroy,
Steps: []resource.TestStep{
{
Config: testAccInstanceConfigInEc2Classic(rInt),
Config: testAccInstanceConfigInEc2Classic(),
Check: resource.ComposeTestCheckFunc(
testAccCheckInstanceExists(resourceName, &v),
testAccCheckInstanceEc2ClassicExists(resourceName, &v),
),
},
{
Config: testAccInstanceConfigInEc2Classic(rInt),
Config: testAccInstanceConfigInEc2Classic(),
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
Expand Down Expand Up @@ -3172,6 +3165,10 @@ func testAccCheckInstanceExists(n string, i *ec2.Instance) resource.TestCheckFun
return testAccCheckInstanceExistsWithProvider(n, i, func() *schema.Provider { return testAccProvider })
}

func testAccCheckInstanceEc2ClassicExists(n string, i *ec2.Instance) resource.TestCheckFunc {
return testAccCheckInstanceExistsWithProvider(n, i, func() *schema.Provider { return testAccProviderEc2Classic })
}

func testAccCheckInstanceExistsWithProvider(n string, i *ec2.Instance, providerF func() *schema.Provider) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down Expand Up @@ -3357,25 +3354,17 @@ resource "aws_instance" "test" {
`, rName)
}

func testAccInstanceConfigInEc2Classic(rInt int) string {
return composeConfig(testAccLatestAmazonLinuxHvmEbsAmiConfig(), fmt.Sprintf(`
provider "aws" {
region = "us-east-1"
}

resource "aws_security_group" "sg" {
name = "tf_acc_test_%d"
description = "Test security group"
}

func testAccInstanceConfigInEc2Classic() string {
return composeConfig(
testAccEc2ClassicRegionProviderConfig(),
testAccLatestAmazonLinuxHvmEbsAmiConfig(),
testAccAvailableEc2InstanceTypeForRegion("t1.micro", "m3.medium", "m3.large", "c3.large", "r3.large"),
`
resource "aws_instance" "test" {
ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id

# tflint-ignore: aws_instance_previous_type
instance_type = "m3.medium"
security_groups = [aws_security_group.sg.name]
ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id
instance_type = data.aws_ec2_instance_type_offering.available.instance_type
}
`, rInt))
`)
}

func testAccInstanceConfigBasic() string {
Expand Down