-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstance_basic_test.go
49 lines (41 loc) · 1.46 KB
/
instance_basic_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
package test
import (
"testing"
"github.com/gruntwork-io/terratest/modules/terraform"
"github.com/stretchr/testify/assert"
"path/filepath"
"github.com/hadenlabs/terraform-aws-ec2-instance/config"
"github.com/hadenlabs/terraform-aws-ec2-instance/internal/app/external/faker"
"github.com/hadenlabs/terraform-aws-ec2-instance/internal/testutil"
)
func TestBasicSuccess(t *testing.T) {
t.Parallel()
conf := config.Initialize()
tags := map[string]interface{}{
"tag1": "tags1",
}
namespace := testutil.Company
stage := testutil.Stage
name := faker.Server().Name()
publicKey := filepath.Join(conf.App.RootPath, string(testutil.PublicKey))
privateKey := filepath.Join(conf.App.RootPath, string(testutil.PrivateKey))
terraformOptions := &terraform.Options{
// The path to where your Terraform code is located
TerraformDir: "instance-basic",
Upgrade: true,
Vars: map[string]interface{}{
"namespace": namespace,
"stage": stage,
"name": name,
"tags": tags,
"public_key": publicKey,
"private_key": privateKey,
},
}
// At the end of the test, run `terraform destroy` to clean up any resources that were created
defer terraform.Destroy(t, terraformOptions)
// This will run `terraform init` and `terraform apply` and fail the test if there are any errors
terraform.InitAndApply(t, terraformOptions)
outputInstance := terraform.Output(t, terraformOptions, "instance")
assert.NotEmpty(t, outputInstance, outputInstance)
}