-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
awsnuke_test.go
57 lines (46 loc) · 1.67 KB
/
awsnuke_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//go:build integration
package awsnuke
import (
"fmt"
"os"
"strings"
"testing"
"github.com/gruntwork-io/terratest/modules/aws"
"github.com/gruntwork-io/terratest/modules/random"
"github.com/gruntwork-io/terratest/modules/terraform"
testStructure "github.com/gruntwork-io/terratest/modules/test-structure"
"github.com/stretchr/testify/assert"
)
const testRegion string = "us-east-2"
const terratestTagName string = "CreatedByTerratestRun"
func TestAwsNuke(t *testing.T) {
t.Parallel()
randID := strings.ToLower(random.UniqueId())
rootFolder := "../../"
terraformFolderRelativeToRoot := "examples/awsnuke-example"
tempTestFolder := testStructure.CopyTerraformFolderToTemp(t, rootFolder, terraformFolderRelativeToRoot)
defer os.RemoveAll(tempTestFolder)
terraformOptions := &terraform.Options{
TerraformDir: tempTestFolder,
Upgrade: true,
VarFiles: []string{fmt.Sprintf("fixtures.%s.tfvars", testRegion)},
Vars: map[string]interface{}{
"attributes": []string{randID},
"default_tags": map[string]string{
terratestTagName: randID,
},
},
}
defer terraform.Destroy(t, terraformOptions)
terraform.InitAndApply(t, terraformOptions)
// Assert that the bucket has been created
bucket, err := aws.FindS3BucketWithTagE(t, testRegion, terratestTagName, randID)
assert.NoError(t, err)
assert.Equal(t, bucket, fmt.Sprintf("eg-test-s3-bucket-test-%s", randID))
// Nuke the account with our config
NukeTestAccountByTag(t, terratestTagName, randID, []string{testRegion}, false)
// Assert that the bucket doesn't exist anymore
bucket, err = aws.FindS3BucketWithTagE(t, testRegion, terratestTagName, randID)
assert.NoError(t, err)
assert.Empty(t, bucket)
}