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/provider: Remove extraneously hardcoded provider configurations in test configurations #12277

Merged
merged 1 commit into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
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
39 changes: 31 additions & 8 deletions aws/data_source_aws_elastic_beanstalk_hosted_zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,43 @@ import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
)

func TestAccAWSDataSourceElasticBeanstalkHostedZone(t *testing.T) {
func TestAccAWSDataSourceElasticBeanstalkHostedZone_basic(t *testing.T) {
dataSourceName := "data.aws_elastic_beanstalk_hosted_zone.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckAwsElasticBeanstalkHostedZoneDataSource_currentRegion,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.aws_elastic_beanstalk_hosted_zone.current", "id", "Z2PCDNR3VC2G1N"),
testAccCheckAwsElasticBeanstalkHostedZone(dataSourceName, testAccGetRegion()),
),
},
},
})
}

func TestAccAWSDataSourceElasticBeanstalkHostedZone_Region(t *testing.T) {
dataSourceName := "data.aws_elastic_beanstalk_hosted_zone.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckAwsElasticBeanstalkHostedZoneDataSource_byRegion("ap-southeast-2"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.aws_elastic_beanstalk_hosted_zone.test", "id", "Z2PCDNR3VC2G1N"),
testAccCheckAwsElasticBeanstalkHostedZone(dataSourceName, "ap-southeast-2"),
),
},
{
Config: testAccCheckAwsElasticBeanstalkHostedZoneDataSource_byRegion("eu-west-1"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.aws_elastic_beanstalk_hosted_zone.test", "id", "Z2NYPWQ7DFZAZH"),
testAccCheckAwsElasticBeanstalkHostedZone(dataSourceName, "eu-west-1"),
),
},
{
Expand All @@ -39,11 +53,20 @@ func TestAccAWSDataSourceElasticBeanstalkHostedZone(t *testing.T) {
})
}

const testAccCheckAwsElasticBeanstalkHostedZoneDataSource_currentRegion = `
provider "aws" {
region = "ap-southeast-2"
func testAccCheckAwsElasticBeanstalkHostedZone(resourceName string, region string) resource.TestCheckFunc {
return func(s *terraform.State) error {
expectedValue, ok := elasticBeanstalkHostedZoneIds[region]

if !ok {
return fmt.Errorf("Unsupported region: %s", region)
}

return resource.TestCheckResourceAttr(resourceName, "id", expectedValue)(s)
}
}
data "aws_elastic_beanstalk_hosted_zone" "current" {}

const testAccCheckAwsElasticBeanstalkHostedZoneDataSource_currentRegion = `
data "aws_elastic_beanstalk_hosted_zone" "test" {}
`

func testAccCheckAwsElasticBeanstalkHostedZoneDataSource_byRegion(r string) string {
Expand Down
34 changes: 15 additions & 19 deletions aws/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,25 +381,6 @@ func testAccPartitionHasServicePreCheck(serviceId string, t *testing.T) {
}
}

// testAccRegionHasServicePreCheck skips a test if the AWS Go SDK endpoint value in a region is missing
// NOTE: Most acceptance testing should prefer behavioral checks against an API (e.g. making an API call and
// using response errors) to determine if a test should be skipped since AWS Go SDK endpoint information
// can be incorrect, especially for newer endpoints or for private feature testing. This functionality
// is provided for cases where the API behavior may be completely unacceptable, such as permanent
// retries by the AWS Go SDK.
func testAccRegionHasServicePreCheck(serviceId string, t *testing.T) {
regionId := testAccGetRegion()
if partition, ok := endpoints.PartitionForRegion(endpoints.DefaultPartitions(), regionId); ok {
service, ok := partition.Services()[serviceId]
if !ok {
t.Skip(fmt.Sprintf("skipping tests; partition %s does not support %s service", partition.ID(), serviceId))
}
if _, ok := service.Regions()[regionId]; !ok {
t.Skip(fmt.Sprintf("skipping tests; region %s does not support %s service", regionId, serviceId))
}
}
}

func testAccMultipleRegionsPreCheck(t *testing.T) {
if partition, ok := endpoints.PartitionForRegion(endpoints.DefaultPartitions(), testAccGetRegion()); ok {
if len(partition.Regions()) < 2 {
Expand All @@ -422,6 +403,7 @@ func testAccOrganizationsAccountPreCheck(t *testing.T) {
}

func testAccAlternateAccountProviderConfig() string {
//lintignore:AT004
return fmt.Sprintf(`
provider "aws" {
access_key = %[1]q
Expand All @@ -433,6 +415,7 @@ provider "aws" {
}

func testAccAlternateAccountAlternateRegionProviderConfig() string {
//lintignore:AT004
return fmt.Sprintf(`
provider "aws" {
access_key = %[1]q
Expand All @@ -445,6 +428,7 @@ provider "aws" {
}

func testAccAlternateRegionProviderConfig() string {
//lintignore:AT004
return fmt.Sprintf(`
provider "aws" {
alias = "alternate"
Expand All @@ -454,6 +438,7 @@ provider "aws" {
}

func testAccProviderConfigIgnoreTagPrefixes1(keyPrefix1 string) string {
//lintignore:AT004
return fmt.Sprintf(`
provider "aws" {
ignore_tag_prefixes = [%[1]q]
Expand All @@ -462,6 +447,7 @@ provider "aws" {
}

func testAccProviderConfigIgnoreTags1(key1 string) string {
//lintignore:AT004
return fmt.Sprintf(`
provider "aws" {
ignore_tags = [%[1]q]
Expand All @@ -476,6 +462,7 @@ provider "aws" {
// Other valid usage is for services only available in us-east-1 such as the
// Cost and Usage Reporting and Pricing services.
func testAccUsEast1RegionProviderConfig() string {
//lintignore:AT004
return fmt.Sprintf(`
provider "aws" {
alias = "us-east-1"
Expand Down Expand Up @@ -1112,6 +1099,7 @@ func testAccCheckAWSProviderPartition(providers *[]*schema.Provider, expectedPar
}

func testAccAWSProviderConfigEndpoints(endpoints string) string {
//lintignore:AT004
return fmt.Sprintf(`
provider "aws" {
skip_credentials_validation = true
Expand All @@ -1132,6 +1120,7 @@ data "aws_arn" "test" {
}

func testAccAWSProviderConfigIgnoreTagPrefixes0() string {
//lintignore:AT004
return fmt.Sprintf(`
provider "aws" {
skip_credentials_validation = true
Expand All @@ -1148,6 +1137,7 @@ data "aws_arn" "test" {
}

func testAccAWSProviderConfigIgnoreTagPrefixes1(tagPrefix1 string) string {
//lintignore:AT004
return fmt.Sprintf(`
provider "aws" {
ignore_tag_prefixes = [%[1]q]
Expand All @@ -1165,6 +1155,7 @@ data "aws_arn" "test" {
}

func testAccAWSProviderConfigIgnoreTagPrefixes2(tagPrefix1, tagPrefix2 string) string {
//lintignore:AT004
return fmt.Sprintf(`
provider "aws" {
ignore_tag_prefixes = [%[1]q, %[2]q]
Expand All @@ -1182,6 +1173,7 @@ data "aws_arn" "test" {
}

func testAccAWSProviderConfigIgnoreTags0() string {
//lintignore:AT004
return fmt.Sprintf(`
provider "aws" {
skip_credentials_validation = true
Expand All @@ -1198,6 +1190,7 @@ data "aws_arn" "test" {
}

func testAccAWSProviderConfigIgnoreTags1(tag1 string) string {
//lintignore:AT004
return fmt.Sprintf(`
provider "aws" {
ignore_tags = [%[1]q]
Expand All @@ -1215,6 +1208,7 @@ data "aws_arn" "test" {
}

func testAccAWSProviderConfigIgnoreTags2(tag1, tag2 string) string {
//lintignore:AT004
return fmt.Sprintf(`
provider "aws" {
ignore_tags = [%[1]q, %[2]q]
Expand All @@ -1232,6 +1226,7 @@ data "aws_arn" "test" {
}

func testAccAWSProviderConfigRegion(region string) string {
//lintignore:AT004
return fmt.Sprintf(`
provider "aws" {
region = %[1]q
Expand All @@ -1256,6 +1251,7 @@ func testAccAssumeRoleARNPreCheck(t *testing.T) {
}

func testAccProviderConfigAssumeRolePolicy(policy string) string {
//lintignore:AT004
return fmt.Sprintf(`
provider "aws" {
assume_role {
Expand Down
31 changes: 24 additions & 7 deletions aws/resource_aws_ami_from_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,33 @@ func testAccCheckAWSAMIFromInstanceDestroy(s *terraform.State) error {

func testAccAWSAMIFromInstanceConfigBase() string {
return fmt.Sprintf(`
provider "aws" {
region = "us-east-1"
data "aws_ec2_instance_type_offering" "available" {
filter {
name = "instance-type"
values = ["t3.micro", "t2.micro"]
}

preferred_instance_types = ["t3.micro", "t2.micro"]
}

resource "aws_instance" "test" {
// This AMI has one block device mapping, so we expect to have
// one snapshot in our created AMI.
ami = "ami-408c7f28"
data "aws_ami" "amzn-ami-minimal-hvm-ebs" {
most_recent = true
owners = ["amazon"]

filter {
name = "name"
values = ["amzn-ami-minimal-hvm-*"]
}

instance_type = "t1.micro"
filter {
name = "root-device-type"
values = ["ebs"]
}
}

resource "aws_instance" "test" {
ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id
instance_type = data.aws_ec2_instance_type_offering.available.instance_type

tags = {
Name = "testAccAWSAMIFromInstanceConfig_TestAMI"
Expand Down
39 changes: 21 additions & 18 deletions aws/resource_aws_codecommit_trigger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,25 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/codecommit"
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
)

func TestAccAWSCodeCommitTrigger_basic(t *testing.T) {
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_codecommit_trigger.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckCodeCommitTriggerDestroy,
Steps: []resource.TestStep{
{
Config: testAccCodeCommitTrigger_basic,
Config: testAccCodeCommitTrigger_basic(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckCodeCommitTriggerExists("aws_codecommit_trigger.test"),
resource.TestCheckResourceAttr(
"aws_codecommit_trigger.test", "trigger.#", "1"),
testAccCheckCodeCommitTriggerExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "trigger.#", "1"),
),
},
},
Expand Down Expand Up @@ -81,24 +84,24 @@ func testAccCheckCodeCommitTriggerExists(name string) resource.TestCheckFunc {
}
}

const testAccCodeCommitTrigger_basic = `
provider "aws" {
region = "us-east-1"
}
func testAccCodeCommitTrigger_basic(rName string) string {
return fmt.Sprintf(`
resource "aws_sns_topic" "test" {
name = "tf-test-topic"
name = %[1]q
}

resource "aws_codecommit_repository" "test" {
repository_name = "tf_test_repository"
description = "This is a test description"
repository_name = %[1]q
}

resource "aws_codecommit_trigger" "test" {
depends_on = ["aws_codecommit_repository.test"]
repository_name = "tf_test_repository"
trigger {
name = "tf-test-trigger"
events = ["all"]
destination_arn = "${aws_sns_topic.test.arn}"
repository_name = aws_codecommit_repository.test.id

trigger {
name = %[1]q
events = ["all"]
destination_arn = aws_sns_topic.test.arn
}
}
`
`, rName)
}
Loading