forked from gruntwork-io/terratest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpacker_basic_example_test.go
35 lines (26 loc) · 963 Bytes
/
packer_basic_example_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
package test
import (
"testing"
"github.com/gruntwork-io/terratest/modules/aws"
"github.com/gruntwork-io/terratest/modules/packer"
)
// An example of how to test the Packer template in examples/packer-basic-example using Terratest.
func TestPackerBasicExample(t *testing.T) {
t.Parallel()
// Pick a random AWS region to test in. This helps ensure your code works in all regions.
awsRegion := aws.GetRandomRegion(t, nil, nil)
packerOptions := &packer.Options{
// The path to where the Packer template is located
Template: "../examples/packer-basic-example/build.json",
// Variables to pass to our Packer build using -var options
Vars: map[string]string{
"aws_region": awsRegion,
},
// Only build the AWS AMI
Only: "amazon-ebs",
}
// Make sure the Packer build completes successfully
amiID := packer.BuildArtifact(t, packerOptions)
// Clean up the AMI after we're done
defer aws.DeleteAmiAndAllSnapshots(t, awsRegion, amiID)
}