-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for packer init with multiple .hcl files #1271
Add support for packer init with multiple .hcl files #1271
Comments
ExampleCreate the packer configuration.
build {
sources = [
"source.amazon-ebs.ubuntu"
]
provisioner "shell" {
inline = [
"cloud-init status --wait",
]
}
provisioner "shell" {
inline = [
"sudo apt-get update",
"sudo apt-get install -y apache2",
"echo \"<html><body><h1>Hello World!</h1></body></html>\" | sudo tee /var/www/html/index.html",
"sudo systemctl restart apache2"
]
}
}
locals {
name = "ubuntu-${formatdate("YYYY-MM-DD-hh-mm", timestamp())}"
}
data "amazon-ami" "ubuntu" {
most_recent = true
filters = {
name = "ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"
virtualization-type = "hvm"
}
owners = ["099720109477"] # Canonical
}
source "amazon-ebs" "ubuntu" {
ami_name = "${local.name}"
ami_description = "Managed by Packer"
ami_virtualization_type = "hvm"
source_ami = data.amazon-ami.ubuntu.id
instance_type = "t3.micro"
communicator = "ssh"
ssh_username = "ubuntu"
snapshot_tags = {
Name = "${local.name}-snapshot"
}
tags = {
"Name" = "${local.name}"
}
} Create a test file based on terraform_packer_example_test.go and make the following edit:
// omitted...
packerOptions := &packer.Options{
Template: ".",
WorkingDir: workingDir,
}
// omitted... Then run terratest. go test -v ./packer_test.go
<omitted output>
TestMultipleStagesExample 2023-04-22T15:33:15+01:00 logger.go:66: Running Packer to generate a custom artifact for template .
TestMultipleStagesExample 2023-04-22T15:33:15+01:00 logger.go:66: Creating a temporary directory for Packer plugins
TestMultipleStagesExample 2023-04-22T15:33:15+01:00 logger.go:66: Running command packer with args [-version]
TestMultipleStagesExample 2023-04-22T15:33:15+01:00 logger.go:66: 1.8.6
TestMultipleStagesExample 2023-04-22T15:33:16+01:00 logger.go:66: Skipping 'packer init' because it is only supported for HCL2 templates
<ommited output> You can see in the console output that Proposed SolutionIf there isn't an option I've missed in the docs. I'd like to propose defaulting to initialising packer if packerOptions := &packer.Options{
WorkingDir: workingDir,
} I believe this solution would still be backwards compatible because a user could still provide an argument for |
When the packer configuration is separated across multiple .hcl files, Terratest does not initialise packer when
Template
in the packer.Options is set to"."
. To get Terratest to initialise packer, I have to setTemplate
to the path of a .hcl file.Is there an additional setting I am missing from my packer options? Or, is a modification to terratest required?
The text was updated successfully, but these errors were encountered: