2021-01-18 09:08:04 -05:00
# This file was autogenerated by the 'packer hcl2_upgrade' command. We
2020-08-25 04:51:43 -04:00
# recommend double checking that everything is correct before going forward. We
# also recommend treating this file as disposable. The HCL2 blocks in this
# file can be moved to other files. For example, the variable blocks could be
# moved to their own 'variables.pkr.hcl' file, etc. Those files need to be
# suffixed with '.pkr.hcl' to be visible to Packer. To use multiple files at
# once they also need to be in the same folder. 'packer inspect folder/'
# will describe to you what is in that folder.
2020-12-09 06:39:54 -05:00
# Avoid mixing go templating calls ( for example ```{{ upper(`string`) }}``` )
2020-11-10 04:46:20 -05:00
# and HCL2 calls (for example '${ var.string_value_example }' ). They won't be
# executed together and the outcome will be unknown.
2021-01-14 17:55:19 -05:00
# See https://www.packer.io/docs/templates/hcl_templates/blocks/packer for more info
2020-11-10 04:46:20 -05:00
packer {
required_version = "> = 1 . 6 . 0 "
}
2020-10-14 15:04:18 -04:00
# All generated input variables will be of 'string' type as this is how Packer JSON
# views them; you can change their type later on. Read the variables type
2020-08-25 04:51:43 -04:00
# constraints documentation
2021-01-14 17:55:19 -05:00
# https://www.packer.io/docs/templates/hcl_templates/variables#type-constraints for more info.
2020-08-25 04:51:43 -04:00
variable "aws_access_key" {
type = string
default = ""
sensitive = true
}
variable "aws_region" {
type = string
}
2020-11-11 14:54:22 -05:00
variable "aws_secondary_region" {
type = string
default = "${env("AWS_DEFAULT_REGION")}"
}
2020-08-25 04:51:43 -04:00
variable "aws_secret_key" {
type = string
default = ""
sensitive = true
}
2020-11-10 04:46:20 -05:00
variable "secret_account" {
type = string
default = "🤷"
sensitive = true
}
2020-08-25 04:51:43 -04:00
# "timestamp" template function replacement
locals { timestamp = regex_replace ( timestamp ( ) , "[- TZ:]", "" ) }
2021-01-19 04:21:39 -05:00
# The amazon-ami data block is generated from your amazon builder source_ami_filter; a data
# from this block can be referenced in source and locals blocks.
# Read the documentation for data blocks here:
# https://www.packer.io/docs/templates/hcl_templates/blocks/data
data "amazon-ami" "autogenerated_1" {
filters = {
name = "ubuntu/images/*/ubuntu-xenial-16.04-amd64-server-*"
root-device-type = "ebs"
virtualization-type = "hvm"
}
most_recent = true
owners = [ "099720109477" ]
}
2020-08-25 04:51:43 -04:00
# source blocks are generated from your builders; a source can be referenced in
2020-10-14 15:04:18 -04:00
# build blocks. A build block runs provisioner and post-processors on a
2020-08-25 04:51:43 -04:00
# source. Read the documentation for source blocks here:
2021-01-14 17:55:19 -05:00
# https://www.packer.io/docs/templates/hcl_templates/blocks/source
2020-08-25 04:51:43 -04:00
source "amazon-ebs" "autogenerated_1" {
access_key = "${var.aws_access_key}"
ami_description = "Ubuntu 16.04 LTS - expand root partition"
ami_name = "ubuntu-16-04-test-${local.timestamp}"
encrypt_boot = true
launch_block_device_mappings {
delete_on_termination = true
device_name = "/dev/sda1"
volume_size = 48
volume_type = "gp2"
}
2021-01-19 04:21:39 -05:00
region = "${var.aws_region}"
secret_key = "${var.aws_secret_key}"
source_ami = "${data.amazon-ami.autogenerated_1.id}"
spot_instance_types = [ "t2.small", "t2.medium", "t2.large" ]
spot_price = "0.0075"
ssh_interface = "session_manager"
ssh_username = "ubuntu"
temporary_iam_instance_profile_policy_document {
Statement {
Action = [ "*" ]
Effect = "Allow"
Resource = [ "*" ]
2020-08-25 04:51:43 -04:00
}
2021-01-19 04:21:39 -05:00
Version = "2012-10-17"
}
}
source "amazon-ebs" "named_builder" {
access_key = "${var.aws_access_key}"
ami_description = "Ubuntu 16.04 LTS - expand root partition"
ami_name = "ubuntu-16-04-test-${local.timestamp}"
encrypt_boot = true
launch_block_device_mappings {
delete_on_termination = true
device_name = "/dev/sda1"
volume_size = 48
volume_type = "gp2"
2020-08-25 04:51:43 -04:00
}
2021-01-19 04:21:39 -05:00
region = "${var.aws_region}"
secret_key = "${var.aws_secret_key}"
source_ami = "${data.amazon-ami.autogenerated_1.id}"
2020-08-25 04:51:43 -04:00
spot_instance_types = [ "t2.small", "t2.medium", "t2.large" ]
spot_price = "0.0075"
ssh_interface = "session_manager"
ssh_username = "ubuntu"
temporary_iam_instance_profile_policy_document {
Statement {
Action = [ "*" ]
Effect = "Allow"
Resource = [ "*" ]
}
Version = "2012-10-17"
}
}
2020-10-14 15:04:18 -04:00
# a build block invokes sources and runs provisioning steps on them. The
2020-08-25 04:51:43 -04:00
# documentation for build blocks can be found here:
2021-01-14 17:55:19 -05:00
# https://www.packer.io/docs/templates/hcl_templates/blocks/build
2020-08-25 04:51:43 -04:00
build {
2021-01-19 04:21:39 -05:00
sources = [ "source.amazon-ebs.autogenerated_1", "source.amazon-ebs.named_builder" ]
2020-08-25 04:51:43 -04:00
provisioner "shell" {
2020-11-10 04:46:20 -05:00
except = [ "amazon-ebs" ]
inline = [ "echo ${var.secret_account}", "echo ${build.ID}", "echo ${build.SSHPublicKey} | head -c 14", "echo ${path.root} is not ${path.cwd}", "echo ${packer.version}", "echo ${uuidv4()}" ]
2020-08-25 04:51:43 -04:00
max_retries = "5"
2020-11-10 04:46:20 -05:00
}
# template: hcl2_upgrade:2:38: executing "hcl2_upgrade" at <clean_resource_name>: error calling clean_resource_name: unhandled "clean_resource_name" call:
# there is no way to automatically upgrade the "clean_resource_name" call.
# Please manually upgrade to use custom validation rules, `replace(string, substring, replacement)` or `regex_replace(string, substring, replacement)`
2021-01-14 17:55:19 -05:00
# Visit https://packer.io/docs/templates/hcl_templates/variables#custom-validation-rules , https://www.packer.io/docs/templates/hcl_templates/functions/string/replace or https://www.packer.io/docs/templates/hcl_templates/functions/string/regex_replace for more infos.
2020-11-10 04:46:20 -05:00
provisioner "shell" {
inline = [ "echo mybuild-{{isotime | clean_resource_name}}" ]
}
# template: hcl2_upgrade:2:35: executing "hcl2_upgrade" at <lower>: error calling lower: unhandled "lower" call:
# there is no way to automatically upgrade the "lower" call.
# Please manually upgrade to `lower(var.example)`
2021-01-14 17:55:19 -05:00
# Visit https://www.packer.io/docs/templates/hcl_templates/functions/string/lower for more infos.
2020-11-10 04:46:20 -05:00
provisioner "shell" {
inline = [ "echo {{ `SOMETHING` | lower }}" ]
}
# template: hcl2_upgrade:2:35: executing "hcl2_upgrade" at <upper>: error calling upper: unhandled "upper" call:
# there is no way to automatically upgrade the "upper" call.
# Please manually upgrade to `upper(var.example)`
2021-01-14 17:55:19 -05:00
# Visit https://www.packer.io/docs/templates/hcl_templates/functions/string/upper for more infos.
2020-11-10 04:46:20 -05:00
provisioner "shell" {
inline = [ "echo {{ `something` | upper }}" ]
}
# template: hcl2_upgrade:2:21: executing "hcl2_upgrade" at <split `some-string` `-` 0>: error calling split: unhandled "split" call:
# there is no way to automatically upgrade the "split" call.
# Please manually upgrade to `split(separator, string)`
2021-01-14 17:55:19 -05:00
# Visit https://www.packer.io/docs/templates/hcl_templates/functions/string/split for more infos.
2020-11-10 04:46:20 -05:00
provisioner "shell" {
inline = [ "echo {{ split `some-string` `-` 0 }}" ]
}
# template: hcl2_upgrade:2:21: executing "hcl2_upgrade" at <replace_all `-` `/` build_name>: error calling replace_all: unhandled "replace_all" call:
# there is no way to automatically upgrade the "replace_all" call.
# Please manually upgrade to `replace(string, substring, replacement)` or `regex_replace(string, substring, replacement)`
2021-01-14 17:55:19 -05:00
# Visit https://www.packer.io/docs/templates/hcl_templates/functions/string/replace or https://www.packer.io/docs/templates/hcl_templates/functions/string/regex_replace for more infos.
2020-11-10 04:46:20 -05:00
provisioner "shell" {
inline = [ "echo {{ replace_all `-` `/` build_name }}" ]
}
# template: hcl2_upgrade:2:21: executing "hcl2_upgrade" at <replace `some-string` `-` `/` 1>: error calling replace: unhandled "replace" call:
# there is no way to automatically upgrade the "replace" call.
# Please manually upgrade to `replace(string, substring, replacement)` or `regex_replace(string, substring, replacement)`
2021-01-14 17:55:19 -05:00
# Visit https://www.packer.io/docs/templates/hcl_templates/functions/string/replace or https://www.packer.io/docs/templates/hcl_templates/functions/string/regex_replace for more infos.
2020-11-10 04:46:20 -05:00
provisioner "shell" {
inline = [ "echo {{ replace `some-string` `-` `/` 1 }}" ]
2020-08-25 04:51:43 -04:00
}
provisioner "shell-local" {
inline = [ "sleep 100000" ]
2020-11-10 04:46:20 -05:00
only = [ "amazon-ebs" ]
2020-08-25 04:51:43 -04:00
timeout = "5s"
}
post - processor "amazon-import" {
format = "vmdk"
license_type = "BYOL"
region = "eu-west-3"
s3_bucket_name = "hashicorp.adrien"
tags = {
Description = "packer amazon-import ${local.timestamp}"
}
}
post - processors {
post - processor "artifice" {
keep_input_artifact = true
files = [ "path/something.ova" ]
name = "very_special_artifice_post-processor"
only = [ "amazon-ebs" ]
}
post - processor "amazon-import" {
except = [ "amazon-ebs" ]
license_type = "BYOL"
s3_bucket_name = "hashicorp.adrien"
tags = {
Description = "packer amazon-import ${local.timestamp}"
}
}
}
}