2020-04-03 12:17:09 -04:00
|
|
|
package amazon_acc
|
|
|
|
|
|
|
|
// This is the code necessary for running the provisioner acceptance tests.
|
|
|
|
// It provides the builder config and cleans up created resource.
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
2020-04-06 10:14:14 -04:00
|
|
|
amazonebsbuilder "github.com/hashicorp/packer/builder/amazon/ebs"
|
|
|
|
|
2020-04-03 12:17:09 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
|
|
|
|
|
|
|
testshelper "github.com/hashicorp/packer/helper/tests"
|
|
|
|
)
|
|
|
|
|
|
|
|
type AmazonEBSAccTest struct{}
|
|
|
|
|
|
|
|
func (s *AmazonEBSAccTest) GetConfigs() (map[string]string, error) {
|
2020-04-03 14:53:32 -04:00
|
|
|
fixtures := map[string]string{
|
|
|
|
"linux": "amazon-ebs.txt",
|
|
|
|
"windows": "amazon-ebs_windows.txt",
|
2020-04-03 12:17:09 -04:00
|
|
|
}
|
|
|
|
|
2020-04-03 14:53:32 -04:00
|
|
|
configs := make(map[string]string)
|
|
|
|
|
|
|
|
for distro, fixture := range fixtures {
|
|
|
|
fileName := fixture
|
|
|
|
filePath := filepath.Join("../../builder/amazon/ebs/acceptance/test-fixtures/", fileName)
|
|
|
|
config, err := os.Open(filePath)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Expected to find %s", filePath)
|
|
|
|
}
|
|
|
|
defer config.Close()
|
|
|
|
|
|
|
|
file, err := ioutil.ReadAll(config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Unable to read %s", filePath)
|
|
|
|
}
|
|
|
|
|
|
|
|
configs[distro] = string(file)
|
|
|
|
|
2020-04-03 12:17:09 -04:00
|
|
|
}
|
2020-04-03 14:53:32 -04:00
|
|
|
return configs, nil
|
2020-04-03 12:17:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *AmazonEBSAccTest) CleanUp() error {
|
|
|
|
helper := testshelper.AWSHelper{
|
|
|
|
Region: "us-east-1",
|
|
|
|
AMIName: "packer-acc-test",
|
|
|
|
}
|
|
|
|
return helper.CleanUpAmi()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *AmazonEBSAccTest) GetBuilderStore() packer.MapOfBuilder {
|
|
|
|
return packer.MapOfBuilder{
|
2020-04-06 10:14:14 -04:00
|
|
|
"amazon-ebs": func() (packer.Builder, error) { return &amazonebsbuilder.Builder{}, nil },
|
2020-04-03 12:17:09 -04:00
|
|
|
}
|
|
|
|
}
|