Hi Folks,
I've taken over a project that has been using Packer JSON files and I have
converted them to HCL. I am not new to HCL as I use it for Terraform etc...
I would like to understand if there is a better way to define my sources, I
am building both AWS and Azure Images with Packer.
At the moment there are repeated definitions for each source, and the only
difference is the name, the provisioner is use to pass in the configuration
differences.
```
source "amazon-ebs" "aws-100" {
access_key = "${var.aws_access_key}"
ami_name = "Name 100 ${local.timestamp}"
instance_type = "${var.aws_instance_type}"
launch_block_device_mappings {
delete_on_termination = "${var.ec2_os_volume_delete_on_termination}"
device_name = "${var.ec2_os_volume_device_name}"
volume_size = "${var.ec2_os_volume_size}"
volume_type = "${var.ec2_os_volume_type}"
}
launch_block_device_mappings {
delete_on_termination =
"${var.ec2_additional_volume_delete_on_termination}"
device_name = "${var.ec2_additional_volume_device_name}"
volume_size = "${var.ec2_additional_volume_size}"
volume_type = "${var.ec2_additional_volume_type}"
}
region = "${var.aws_region}"
secret_key = "${var.aws_secret_key}"
source_ami = "${var.aws_src_ami}"
ssh_pty = true
ssh_username = "${var.aws_ssh_user}"
subnet_id = "${var.aws_subnet}"
vpc_id = "${var.aws_vpc}"
}
source "amazon-ebs" "aws-1000" {
access_key = "${var.aws_access_key}"
ami_name = "Name 1000 ${local.timestamp}"
instance_type = "${var.aws_instance_type}"
launch_block_device_mappings {
delete_on_termination = "${var.ec2_os_volume_delete_on_termination}"
device_name = "${var.ec2_os_volume_device_name}"
volume_size = "${var.ec2_os_volume_size}"
volume_type = "${var.ec2_os_volume_type}"
}
launch_block_device_mappings {
delete_on_termination =
"${var.ec2_additional_volume_delete_on_termination}"
device_name = "${var.ec2_additional_volume_device_name}"
volume_size = "${var.ec2_additional_volume_size}"
volume_type = "${var.ec2_additional_volume_type}"
}
region = "${var.aws_region}"
secret_key = "${var.aws_secret_key}"
source_ami = "${var.aws_src_ami}"
ssh_pty = true
ssh_username = "${var.aws_ssh_user}"
subnet_id = "${var.aws_subnet}"
vpc_id = "${var.aws_vpc}"
}
```
I'm certain there must be a more succinct way to achieve this, any tips?
Would be interested to see how I can keep these DRY and more succinct
Thanks
--
This mailing list is governed under the HashiCorp Community Guidelines -
https://www.hashicorp.com/community-guidelines.html. Behavior in violation of
those guidelines may result in your removal from this mailing list.
GitHub Issues: https://github.com/hashicorp/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups
"Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/packer-tool/099ca3e8-cd2b-4293-b499-7e7ebf12c465n%40googlegroups.com.