diff --git a/Makefile b/Makefile index 2202881..3ab06cb 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ test: deps .PHONY: testacc testacc: deps - TEST_ACC=1 go test -count=1 ./... + TEST_ACC=1 go test -count=1 -failfast ./... .PHONY: check check: lint vet test build diff --git a/docker-compose.yml b/docker-compose.yml index 000513f..cff314a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,6 +10,9 @@ services: environment: CGO_ENABLED: 0 # disable cgo for go test LOCALSTACK_ENDPOINT: "http://localstack:4566" + # Use the same filesystem to avoid a checksum mismatch error + # or a file busy error caused by asynchronous IO. + TF_PLUGIN_CACHE_DIR: "/tmp/plugin-cache" depends_on: - localstack diff --git a/tfexec/test_helper.go b/tfexec/test_helper.go index 23d8569..258e58e 100644 --- a/tfexec/test_helper.go +++ b/tfexec/test_helper.go @@ -299,6 +299,14 @@ func SetupTestAccWithApply(t *testing.T, source string) TerraformCLI { t.Fatalf("failed to run terraform apply: %s", err) } + // destroy resources after each test not to have any state. + t.Cleanup(func() { + err := tf.Destroy(ctx, "", "-input=false", "-no-color", "-auto-approve") + if err != nil { + t.Fatalf("failed to run terraform destroy: %s", err) + } + }) + return tf } diff --git a/tfmigrate/state_import_action_test.go b/tfmigrate/state_import_action_test.go index 9931a29..2477ffd 100644 --- a/tfmigrate/state_import_action_test.go +++ b/tfmigrate/state_import_action_test.go @@ -49,4 +49,9 @@ resource "aws_iam_user" "baz" { if err != nil { t.Fatalf("failed to run migrator plan: %s", err) } + + err = m.Apply(ctx) + if err != nil { + t.Fatalf("failed to run migrator apply: %s", err) + } }