From 1fc2e358102e6f6672dc3884c0bd2fbc9af5ff10 Mon Sep 17 00:00:00 2001 From: William Beuil Date: Tue, 25 Jan 2022 15:29:57 +0100 Subject: [PATCH 1/2] chore: renamed TestAcc_Aws* to TestAcc_Aws_* and added missing AWS_REGION env --- pkg/resource/aws/aws_dynamodb_table_test.go | 2 +- pkg/resource/aws/aws_ecr_repository_test.go | 2 +- pkg/resource/aws/aws_iam_policy_attachment_test.go | 5 ++++- pkg/resource/aws/aws_instance_test.go | 4 ++-- pkg/resource/aws/aws_internet_gateway_test.go | 2 +- pkg/resource/aws/aws_lambda_event_source_mapping_test.go | 2 +- pkg/resource/aws/aws_launch_configuration_test.go | 2 +- pkg/resource/aws/aws_launch_template_test.go | 2 +- pkg/resource/aws/aws_nat_gateway_test.go | 2 +- pkg/resource/aws/aws_route53_health_check_test.go | 2 +- pkg/resource/aws/aws_route53_record_test.go | 7 +++++-- pkg/resource/aws/aws_route_table_association_test.go | 2 +- pkg/resource/aws/aws_route_table_test.go | 2 +- pkg/resource/aws/aws_route_test.go | 2 +- pkg/resource/aws/aws_s3_bucket_test.go | 2 +- pkg/resource/aws/aws_security_group_test.go | 2 +- pkg/resource/aws/aws_sns_topic_policy_test.go | 2 +- pkg/resource/aws/aws_sns_topic_subscription_test.go | 2 +- pkg/resource/aws/aws_sns_topic_test.go | 2 +- pkg/resource/aws/aws_sqs_queue_policy_test.go | 2 +- pkg/resource/aws/aws_sqs_queue_test.go | 2 +- pkg/resource/aws/aws_subnet_test.go | 2 +- pkg/resource/aws/aws_vpc_test.go | 2 +- 23 files changed, 31 insertions(+), 25 deletions(-) diff --git a/pkg/resource/aws/aws_dynamodb_table_test.go b/pkg/resource/aws/aws_dynamodb_table_test.go index 46ad17fe..3706b193 100644 --- a/pkg/resource/aws/aws_dynamodb_table_test.go +++ b/pkg/resource/aws/aws_dynamodb_table_test.go @@ -7,7 +7,7 @@ import ( "github.com/snyk/driftctl/test/acceptance" ) -func TestAcc_AwsDynamoDBTable(t *testing.T) { +func TestAcc_Aws_DynamoDBTable(t *testing.T) { acceptance.Run(t, acceptance.AccTestCase{ TerraformVersion: "0.15.5", Paths: []string{"./testdata/acc/aws_dynamodb_table"}, diff --git a/pkg/resource/aws/aws_ecr_repository_test.go b/pkg/resource/aws/aws_ecr_repository_test.go index d88dce5f..d2afd53b 100644 --- a/pkg/resource/aws/aws_ecr_repository_test.go +++ b/pkg/resource/aws/aws_ecr_repository_test.go @@ -15,7 +15,7 @@ import ( "github.com/snyk/driftctl/test/acceptance/awsutils" ) -func TestAcc_AwsECRRepository(t *testing.T) { +func TestAcc_Aws_ECRRepository(t *testing.T) { var mutatedRepositoryID string acceptance.Run(t, acceptance.AccTestCase{ TerraformVersion: "0.15.5", diff --git a/pkg/resource/aws/aws_iam_policy_attachment_test.go b/pkg/resource/aws/aws_iam_policy_attachment_test.go index 70a07128..45cd7a52 100644 --- a/pkg/resource/aws/aws_iam_policy_attachment_test.go +++ b/pkg/resource/aws/aws_iam_policy_attachment_test.go @@ -7,13 +7,16 @@ import ( "github.com/snyk/driftctl/test/acceptance" ) -func TestAcc_AwsIamPolicyAttachment_WithGroupsUsers(t *testing.T) { +func TestAcc_Aws_IamPolicyAttachment_WithGroupsUsers(t *testing.T) { acceptance.Run(t, acceptance.AccTestCase{ TerraformVersion: "0.15.5", Paths: []string{"./testdata/acc/aws_iam_policy_attachment"}, Args: []string{"scan", "--deep"}, Checks: []acceptance.AccCheck{ { + Env: map[string]string{ + "AWS_REGION": "us-east-1", + }, Check: func(result *test.ScanResult, stdout string, err error) { if err != nil { t.Fatal(err) diff --git a/pkg/resource/aws/aws_instance_test.go b/pkg/resource/aws/aws_instance_test.go index 9ca01e52..6f658f02 100644 --- a/pkg/resource/aws/aws_instance_test.go +++ b/pkg/resource/aws/aws_instance_test.go @@ -14,7 +14,7 @@ import ( "github.com/snyk/driftctl/test/acceptance/awsutils" ) -func TestAcc_AwsInstance(t *testing.T) { +func TestAcc_Aws_Instance(t *testing.T) { acceptance.Run(t, acceptance.AccTestCase{ TerraformVersion: "0.15.5", Paths: []string{"./testdata/acc/aws_instance_default"}, @@ -39,7 +39,7 @@ func TestAcc_AwsInstance(t *testing.T) { }) } -func TestAcc_AwsInstance_WithBlockDevices(t *testing.T) { +func TestAcc_Aws_Instance_WithBlockDevices(t *testing.T) { var mutatedInstanceId string acceptance.Run(t, acceptance.AccTestCase{ TerraformVersion: "0.15.5", diff --git a/pkg/resource/aws/aws_internet_gateway_test.go b/pkg/resource/aws/aws_internet_gateway_test.go index 197192d4..1b97e1ed 100644 --- a/pkg/resource/aws/aws_internet_gateway_test.go +++ b/pkg/resource/aws/aws_internet_gateway_test.go @@ -8,7 +8,7 @@ import ( "github.com/snyk/driftctl/test/acceptance" ) -func TestAcc_AwsInternetGateway(t *testing.T) { +func TestAcc_Aws_InternetGateway(t *testing.T) { acceptance.Run(t, acceptance.AccTestCase{ TerraformVersion: "0.15.5", Paths: []string{"./testdata/acc/aws_internet_gateway"}, diff --git a/pkg/resource/aws/aws_lambda_event_source_mapping_test.go b/pkg/resource/aws/aws_lambda_event_source_mapping_test.go index 832504d0..fd046a76 100644 --- a/pkg/resource/aws/aws_lambda_event_source_mapping_test.go +++ b/pkg/resource/aws/aws_lambda_event_source_mapping_test.go @@ -10,7 +10,7 @@ import ( // aws lambda list-event-source-mappings to list all event source mappings // aws lambda delete-event-source-mapping --uuid xxx to delete a specific event source mapping -func TestAcc_AwsLambdaEventSourceMapping(t *testing.T) { +func TestAcc_Aws_LambdaEventSourceMapping(t *testing.T) { acceptance.Run(t, acceptance.AccTestCase{ TerraformVersion: "0.15.5", Paths: []string{"./testdata/acc/aws_lambda_event_source_mapping"}, diff --git a/pkg/resource/aws/aws_launch_configuration_test.go b/pkg/resource/aws/aws_launch_configuration_test.go index fbdd24c3..c258b866 100644 --- a/pkg/resource/aws/aws_launch_configuration_test.go +++ b/pkg/resource/aws/aws_launch_configuration_test.go @@ -7,7 +7,7 @@ import ( "github.com/snyk/driftctl/test/acceptance" ) -func TestAcc_AwsLaunchConfiguration(t *testing.T) { +func TestAcc_Aws_LaunchConfiguration(t *testing.T) { acceptance.Run(t, acceptance.AccTestCase{ TerraformVersion: "0.15.5", Paths: []string{"./testdata/acc/aws_launch_configuration"}, diff --git a/pkg/resource/aws/aws_launch_template_test.go b/pkg/resource/aws/aws_launch_template_test.go index ce5660a7..ee564092 100644 --- a/pkg/resource/aws/aws_launch_template_test.go +++ b/pkg/resource/aws/aws_launch_template_test.go @@ -7,7 +7,7 @@ import ( "github.com/snyk/driftctl/test/acceptance" ) -func TestAcc_AwsLaunchTemplate(t *testing.T) { +func TestAcc_Aws_LaunchTemplate(t *testing.T) { acceptance.Run(t, acceptance.AccTestCase{ TerraformVersion: "0.15.5", Paths: []string{"./testdata/acc/aws_launch_template"}, diff --git a/pkg/resource/aws/aws_nat_gateway_test.go b/pkg/resource/aws/aws_nat_gateway_test.go index ad73c184..9ea13cf0 100644 --- a/pkg/resource/aws/aws_nat_gateway_test.go +++ b/pkg/resource/aws/aws_nat_gateway_test.go @@ -7,7 +7,7 @@ import ( "github.com/snyk/driftctl/test/acceptance" ) -func TestAcc_AwsNATGateway(t *testing.T) { +func TestAcc_Aws_NATGateway(t *testing.T) { acceptance.Run(t, acceptance.AccTestCase{ TerraformVersion: "0.15.5", Paths: []string{"./testdata/acc/aws_nat_gateway"}, diff --git a/pkg/resource/aws/aws_route53_health_check_test.go b/pkg/resource/aws/aws_route53_health_check_test.go index 41175c13..45a60334 100644 --- a/pkg/resource/aws/aws_route53_health_check_test.go +++ b/pkg/resource/aws/aws_route53_health_check_test.go @@ -14,7 +14,7 @@ import ( "github.com/snyk/driftctl/test/acceptance/awsutils" ) -func TestAcc_AwsRoute53HealthCheck(t *testing.T) { +func TestAcc_Aws_Route53HealthCheck(t *testing.T) { var mutatedHealthCheckID string acceptance.Run(t, acceptance.AccTestCase{ TerraformVersion: "0.15.5", diff --git a/pkg/resource/aws/aws_route53_record_test.go b/pkg/resource/aws/aws_route53_record_test.go index 0f4cc04b..138cd21c 100644 --- a/pkg/resource/aws/aws_route53_record_test.go +++ b/pkg/resource/aws/aws_route53_record_test.go @@ -7,7 +7,7 @@ import ( "github.com/snyk/driftctl/test/acceptance" ) -func TestAcc_AwsRoute53Record_WithFQDNAsId(t *testing.T) { +func TestAcc_Aws_Route53Record_WithFQDNAsId(t *testing.T) { acceptance.Run(t, acceptance.AccTestCase{ TerraformVersion: "0.15.5", Paths: []string{"./testdata/acc/aws_route53_record"}, @@ -30,13 +30,16 @@ func TestAcc_AwsRoute53Record_WithFQDNAsId(t *testing.T) { }) } -func TestAcc_AwsRoute53Record_WithAlias(t *testing.T) { +func TestAcc_Aws_Route53Record_WithAlias(t *testing.T) { acceptance.Run(t, acceptance.AccTestCase{ TerraformVersion: "0.15.5", Paths: []string{"./testdata/acc/aws_route53_record_with_alias"}, Args: []string{"scan", "--deep"}, Checks: []acceptance.AccCheck{ { + Env: map[string]string{ + "AWS_REGION": "us-east-1", + }, Check: func(result *test.ScanResult, stdout string, err error) { if err != nil { t.Fatal(err) diff --git a/pkg/resource/aws/aws_route_table_association_test.go b/pkg/resource/aws/aws_route_table_association_test.go index c6b126c4..cda6868c 100644 --- a/pkg/resource/aws/aws_route_table_association_test.go +++ b/pkg/resource/aws/aws_route_table_association_test.go @@ -8,7 +8,7 @@ import ( "github.com/snyk/driftctl/test/acceptance" ) -func TestAcc_AwsRouteTableAssociation(t *testing.T) { +func TestAcc_Aws_RouteTableAssociation(t *testing.T) { acceptance.Run(t, acceptance.AccTestCase{ TerraformVersion: "0.15.5", Paths: []string{"./testdata/acc/aws_route_table_association"}, diff --git a/pkg/resource/aws/aws_route_table_test.go b/pkg/resource/aws/aws_route_table_test.go index 01dedf2f..705de4b4 100644 --- a/pkg/resource/aws/aws_route_table_test.go +++ b/pkg/resource/aws/aws_route_table_test.go @@ -7,7 +7,7 @@ import ( "github.com/snyk/driftctl/test/acceptance" ) -func TestAcc_AwsRouteTable(t *testing.T) { +func TestAcc_Aws_RouteTable(t *testing.T) { acceptance.Run(t, acceptance.AccTestCase{ TerraformVersion: "0.15.5", Paths: []string{"./testdata/acc/aws_route_table"}, diff --git a/pkg/resource/aws/aws_route_test.go b/pkg/resource/aws/aws_route_test.go index 6563f797..4f556e9f 100644 --- a/pkg/resource/aws/aws_route_test.go +++ b/pkg/resource/aws/aws_route_test.go @@ -8,7 +8,7 @@ import ( "github.com/snyk/driftctl/test/acceptance" ) -func TestAcc_AwsRoute(t *testing.T) { +func TestAcc_Aws_Route(t *testing.T) { acceptance.Run(t, acceptance.AccTestCase{ TerraformVersion: "0.15.5", Paths: []string{"./testdata/acc/aws_route"}, diff --git a/pkg/resource/aws/aws_s3_bucket_test.go b/pkg/resource/aws/aws_s3_bucket_test.go index 976193a1..f9d478d2 100644 --- a/pkg/resource/aws/aws_s3_bucket_test.go +++ b/pkg/resource/aws/aws_s3_bucket_test.go @@ -7,7 +7,7 @@ import ( "github.com/snyk/driftctl/test/acceptance" ) -func TestAcc_AwsS3Bucket_BucketInUsEast1(t *testing.T) { +func TestAcc_Aws_S3Bucket_BucketInUsEast1(t *testing.T) { acceptance.Run(t, acceptance.AccTestCase{ TerraformVersion: "0.15.5", Paths: []string{"./testdata/acc/aws_s3_bucket"}, diff --git a/pkg/resource/aws/aws_security_group_test.go b/pkg/resource/aws/aws_security_group_test.go index 0bea0219..d7f0b002 100644 --- a/pkg/resource/aws/aws_security_group_test.go +++ b/pkg/resource/aws/aws_security_group_test.go @@ -7,7 +7,7 @@ import ( "github.com/snyk/driftctl/test/acceptance" ) -func TestAcc_AwsSecurityGroup(t *testing.T) { +func TestAcc_Aws_SecurityGroup(t *testing.T) { acceptance.Run(t, acceptance.AccTestCase{ TerraformVersion: "0.15.5", Paths: []string{"./testdata/acc/aws_security_group"}, diff --git a/pkg/resource/aws/aws_sns_topic_policy_test.go b/pkg/resource/aws/aws_sns_topic_policy_test.go index d17a8ca8..0f96334d 100644 --- a/pkg/resource/aws/aws_sns_topic_policy_test.go +++ b/pkg/resource/aws/aws_sns_topic_policy_test.go @@ -12,7 +12,7 @@ import ( "github.com/snyk/driftctl/test/acceptance/awsutils" ) -func TestAcc_AwsSNSTopicPolicy(t *testing.T) { +func TestAcc_Aws_SNSTopicPolicy(t *testing.T) { acceptance.Run(t, acceptance.AccTestCase{ TerraformVersion: "0.15.5", Paths: []string{"./testdata/acc/aws_sns_topic_policy"}, diff --git a/pkg/resource/aws/aws_sns_topic_subscription_test.go b/pkg/resource/aws/aws_sns_topic_subscription_test.go index 45161770..fcd4acb4 100644 --- a/pkg/resource/aws/aws_sns_topic_subscription_test.go +++ b/pkg/resource/aws/aws_sns_topic_subscription_test.go @@ -12,7 +12,7 @@ import ( "github.com/snyk/driftctl/test/acceptance/awsutils" ) -func TestAcc_AwsSNSTopicSubscription(t *testing.T) { +func TestAcc_Aws_SNSTopicSubscription(t *testing.T) { acceptance.Run(t, acceptance.AccTestCase{ TerraformVersion: "0.15.5", Paths: []string{"./testdata/acc/aws_sns_topic_subscription"}, diff --git a/pkg/resource/aws/aws_sns_topic_test.go b/pkg/resource/aws/aws_sns_topic_test.go index b4a8149e..cf45ddd8 100644 --- a/pkg/resource/aws/aws_sns_topic_test.go +++ b/pkg/resource/aws/aws_sns_topic_test.go @@ -21,7 +21,7 @@ import ( "github.com/snyk/driftctl/test/acceptance/awsutils" ) -func TestAcc_AwsSNSTopic(t *testing.T) { +func TestAcc_Aws_SNSTopic(t *testing.T) { var mutatedTopicArn string acceptance.Run(t, acceptance.AccTestCase{ TerraformVersion: "0.15.5", diff --git a/pkg/resource/aws/aws_sqs_queue_policy_test.go b/pkg/resource/aws/aws_sqs_queue_policy_test.go index f31cc305..56a29506 100644 --- a/pkg/resource/aws/aws_sqs_queue_policy_test.go +++ b/pkg/resource/aws/aws_sqs_queue_policy_test.go @@ -12,7 +12,7 @@ import ( "github.com/snyk/driftctl/test/acceptance" ) -func TestAcc_AwsSQSQueuePolicy(t *testing.T) { +func TestAcc_Aws_SQSQueuePolicy(t *testing.T) { acceptance.Run(t, acceptance.AccTestCase{ TerraformVersion: "0.15.5", Paths: []string{"./testdata/acc/aws_sqs_queue_policy"}, diff --git a/pkg/resource/aws/aws_sqs_queue_test.go b/pkg/resource/aws/aws_sqs_queue_test.go index 9205d24b..6ace4749 100644 --- a/pkg/resource/aws/aws_sqs_queue_test.go +++ b/pkg/resource/aws/aws_sqs_queue_test.go @@ -19,7 +19,7 @@ import ( "github.com/snyk/driftctl/test/acceptance/awsutils" ) -func TestAcc_AwsSQSQueue(t *testing.T) { +func TestAcc_Aws_SQSQueue(t *testing.T) { var mutatedQueue string acceptance.Run(t, acceptance.AccTestCase{ TerraformVersion: "0.15.5", diff --git a/pkg/resource/aws/aws_subnet_test.go b/pkg/resource/aws/aws_subnet_test.go index 870fc992..596ee533 100644 --- a/pkg/resource/aws/aws_subnet_test.go +++ b/pkg/resource/aws/aws_subnet_test.go @@ -7,7 +7,7 @@ import ( "github.com/snyk/driftctl/test/acceptance" ) -func TestAcc_AwsSubnet(t *testing.T) { +func TestAcc_Aws_Subnet(t *testing.T) { acceptance.Run(t, acceptance.AccTestCase{ TerraformVersion: "0.15.5", Paths: []string{"./testdata/acc/aws_subnet"}, diff --git a/pkg/resource/aws/aws_vpc_test.go b/pkg/resource/aws/aws_vpc_test.go index f690c73c..1ef902b2 100644 --- a/pkg/resource/aws/aws_vpc_test.go +++ b/pkg/resource/aws/aws_vpc_test.go @@ -8,7 +8,7 @@ import ( "github.com/snyk/driftctl/test/acceptance" ) -func TestAcc_AwsVPC(t *testing.T) { +func TestAcc_Aws_VPC(t *testing.T) { acceptance.Run(t, acceptance.AccTestCase{ TerraformVersion: "0.15.5", Paths: []string{"./testdata/acc/aws_vpc"}, From f801244453955672f5038636a25e3e9b8eb38741 Mon Sep 17 00:00:00 2001 From: William Beuil Date: Tue, 1 Feb 2022 11:16:11 +0100 Subject: [PATCH 2/2] chore: add retries on flaky acc tests --- pkg/resource/aws/aws_eip_test.go | 11 +++++++++++ pkg/resource/aws/aws_internet_gateway_test.go | 11 +++++++++++ pkg/resource/aws/aws_network_acl_test.go | 12 ++++++++++++ 3 files changed, 34 insertions(+) diff --git a/pkg/resource/aws/aws_eip_test.go b/pkg/resource/aws/aws_eip_test.go index 1f16ad5f..01293acb 100644 --- a/pkg/resource/aws/aws_eip_test.go +++ b/pkg/resource/aws/aws_eip_test.go @@ -22,6 +22,17 @@ func TestAcc_Aws_Eip(t *testing.T) { Env: map[string]string{ "AWS_REGION": "us-east-1", }, + // New resources are not visible immediately through AWS API after an apply operation + // (e.g. error attaching EC2 Internet Gateway) + // Logic below retries driftctl scan using a back-off strategy of retrying 'n' times + // and doubling the amount of time waited after each one. + ShouldRetry: func(result *test.ScanResult, retryDuration time.Duration, retryCount uint8) bool { + if result.IsSync() || retryDuration > 10*time.Minute { + return false + } + time.Sleep((2 * time.Duration(retryCount)) * time.Minute) + return true + }, Check: func(result *test.ScanResult, stdout string, err error) { if err != nil { t.Fatal(err) diff --git a/pkg/resource/aws/aws_internet_gateway_test.go b/pkg/resource/aws/aws_internet_gateway_test.go index 1b97e1ed..b7915ae7 100644 --- a/pkg/resource/aws/aws_internet_gateway_test.go +++ b/pkg/resource/aws/aws_internet_gateway_test.go @@ -22,6 +22,17 @@ func TestAcc_Aws_InternetGateway(t *testing.T) { Env: map[string]string{ "AWS_REGION": "us-east-1", }, + // New resources are not visible immediately through AWS API after an apply operation + // (e.g. InvalidVpcID.NotFound) + // Logic below retries driftctl scan using a back-off strategy of retrying 'n' times + // and doubling the amount of time waited after each one. + ShouldRetry: func(result *test.ScanResult, retryDuration time.Duration, retryCount uint8) bool { + if result.IsSync() || retryDuration > 10*time.Minute { + return false + } + time.Sleep((2 * time.Duration(retryCount)) * time.Minute) + return true + }, Check: func(result *test.ScanResult, stdout string, err error) { if err != nil { t.Fatal(err) diff --git a/pkg/resource/aws/aws_network_acl_test.go b/pkg/resource/aws/aws_network_acl_test.go index 8a23e3d0..1b81e3f7 100644 --- a/pkg/resource/aws/aws_network_acl_test.go +++ b/pkg/resource/aws/aws_network_acl_test.go @@ -2,6 +2,7 @@ package aws_test import ( "testing" + "time" "github.com/snyk/driftctl/test" "github.com/snyk/driftctl/test/acceptance" @@ -41,6 +42,17 @@ func TestAcc_Aws_NetworkAcl_NonDeep(t *testing.T) { Env: map[string]string{ "AWS_REGION": "us-east-1", }, + // New resources are not visible immediately through AWS API after an apply operation + // (e.g. InvalidNetworkAclID.NotFound) + // Logic below retries driftctl scan using a back-off strategy of retrying 'n' times + // and doubling the amount of time waited after each one. + ShouldRetry: func(result *test.ScanResult, retryDuration time.Duration, retryCount uint8) bool { + if result.IsSync() || retryDuration > 10*time.Minute { + return false + } + time.Sleep((2 * time.Duration(retryCount)) * time.Minute) + return true + }, Check: func(result *test.ScanResult, stdout string, err error) { if err != nil { t.Fatal(err)