Skip to content

Commit

Permalink
Merge pull request #1664 from snyk/acc-tests-always-retry-cleanup
Browse files Browse the repository at this point in the history
[CTX-601] chore: always retry terraform-destroy
  • Loading branch information
craigfurman authored Jun 1, 2023
2 parents fb08fd4 + d0cc3aa commit 098c94c
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 37 deletions.
5 changes: 0 additions & 5 deletions pkg/resource/aws/aws_eip_association_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package aws_test

import (
"testing"
"time"

"github.com/snyk/driftctl/test"
"github.com/snyk/driftctl/test/acceptance"
Expand All @@ -13,10 +12,6 @@ func TestAcc_Aws_EipAssociation(t *testing.T) {
TerraformVersion: "0.15.5",
Paths: []string{"./testdata/acc/aws_eip_association"},
Args: []string{"scan", "--deep"},
RetryDestroy: acceptance.RetryConfig{
Attempts: 3,
Delay: 5 * time.Second,
},
Checks: []acceptance.AccCheck{
{
Env: map[string]string{
Expand Down
4 changes: 0 additions & 4 deletions pkg/resource/aws/aws_eip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ func TestAcc_Aws_Eip(t *testing.T) {
TerraformVersion: "0.15.5",
Paths: []string{"./testdata/acc/aws_eip"},
Args: []string{"scan", "--deep"},
RetryDestroy: acceptance.RetryConfig{
Attempts: 3,
Delay: 5 * time.Second,
},
Checks: []acceptance.AccCheck{
{
Env: map[string]string{
Expand Down
4 changes: 0 additions & 4 deletions pkg/resource/aws/aws_internet_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ func TestAcc_Aws_InternetGateway(t *testing.T) {
TerraformVersion: "0.15.5",
Paths: []string{"./testdata/acc/aws_internet_gateway"},
Args: []string{"scan", "--deep"},
RetryDestroy: acceptance.RetryConfig{
Attempts: 3,
Delay: 5 * time.Second,
},
Checks: []acceptance.AccCheck{
{
Env: map[string]string{
Expand Down
5 changes: 0 additions & 5 deletions pkg/resource/aws/aws_route_table_association_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package aws_test

import (
"testing"
"time"

"github.com/snyk/driftctl/test"
"github.com/snyk/driftctl/test/acceptance"
Expand All @@ -13,10 +12,6 @@ func TestAcc_Aws_RouteTableAssociation(t *testing.T) {
TerraformVersion: "0.15.5",
Paths: []string{"./testdata/acc/aws_route_table_association"},
Args: []string{"scan", "--deep"},
RetryDestroy: acceptance.RetryConfig{
Attempts: 3,
Delay: 5 * time.Second,
},
Checks: []acceptance.AccCheck{
{
Env: map[string]string{
Expand Down
8 changes: 0 additions & 8 deletions pkg/resource/aws/aws_route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ func TestAcc_Aws_Route(t *testing.T) {
TerraformVersion: "0.15.5",
Paths: []string{"./testdata/acc/aws_route"},
Args: []string{"scan", "--deep"},
RetryDestroy: acceptance.RetryConfig{
Attempts: 3,
Delay: 5 * time.Second,
},
Checks: []acceptance.AccCheck{
{
Env: map[string]string{
Expand All @@ -41,10 +37,6 @@ func TestAcc_Aws_Route_With_PrefixListId(t *testing.T) {
TerraformVersion: "0.15.5",
Paths: []string{"./testdata/acc/aws_route_with_prefix_list_id"},
Args: []string{"scan", "--deep"},
RetryDestroy: acceptance.RetryConfig{
Attempts: 3,
Delay: 5 * time.Second,
},
Checks: []acceptance.AccCheck{
{
Env: map[string]string{
Expand Down
12 changes: 1 addition & 11 deletions test/acceptance/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ type AccCheck struct {
Check func(result *test.ScanResult, stdout string, err error)
}

type RetryConfig struct {
Attempts uint8
Delay time.Duration
}

type AccTestCase struct {
DoNotRunTerraform bool
TerraformVersion string
Expand All @@ -60,7 +55,6 @@ type AccTestCase struct {
originalEnv []string
tf map[string]*tfexec.Terraform
ShouldRefreshBeforeDestroy bool
RetryDestroy RetryConfig
}

func (c *AccTestCase) initTerraformExecutor() error {
Expand Down Expand Up @@ -214,11 +208,7 @@ func (c *AccTestCase) terraformApply() error {
}

func (c *AccTestCase) terraformDestroy() error {
if c.RetryDestroy.Attempts == 0 {
return c.doDestroy()
}
r := retrier.New(retrier.ConstantBackoff(int(c.RetryDestroy.Attempts), c.RetryDestroy.Delay), nil)

r := retrier.New(retrier.ExponentialBackoff(10, time.Second*5), nil)
return r.Run(c.doDestroy)

}
Expand Down

0 comments on commit 098c94c

Please sign in to comment.