github.com/hashicorp/packer@v1.14.3/command/test-fixtures/hcl2_upgrade/complete/expected.pkr.hcl (about)

     1  # This file was autogenerated by the 'packer hcl2_upgrade' command. We
     2  # recommend double checking that everything is correct before going forward. We
     3  # also recommend treating this file as disposable. The HCL2 blocks in this
     4  # file can be moved to other files. For example, the variable blocks could be
     5  # moved to their own 'variables.pkr.hcl' file, etc. Those files need to be
     6  # suffixed with '.pkr.hcl' to be visible to Packer. To use multiple files at
     7  # once they also need to be in the same folder. 'packer inspect folder/'
     8  # will describe to you what is in that folder.
     9  
    10  # Avoid mixing go templating calls ( for example ```{{ upper(`string`) }}``` )
    11  # and HCL2 calls (for example '${ var.string_value_example }' ). They won't be
    12  # executed together and the outcome will be unknown.
    13  
    14  # See https://www.packer.io/docs/templates/hcl_templates/blocks/packer for more info
    15  packer {
    16    required_version = ">= 1.6.0"
    17    required_plugins {
    18      amazon = {
    19        source  = "github.com/hashicorp/amazon"
    20        version = "~> 1"
    21      }
    22    }
    23  }
    24  
    25  # All generated input variables will be of 'string' type as this is how Packer JSON
    26  # views them; you can change their type later on. Read the variables type
    27  # constraints documentation
    28  # https://www.packer.io/docs/templates/hcl_templates/variables#type-constraints for more info.
    29  variable "aws_access_key" {
    30    type      = string
    31    default   = ""
    32    sensitive = true
    33  }
    34  
    35  variable "aws_region" {
    36    type = string
    37  }
    38  
    39  variable "aws_secondary_region" {
    40    type    = string
    41    default = "${env("AWS_DEFAULT_REGION")}"
    42  }
    43  
    44  variable "aws_secret_key" {
    45    type      = string
    46    default   = ""
    47    sensitive = true
    48  }
    49  
    50  variable "secret_account" {
    51    type      = string
    52    default   = "🤷"
    53    sensitive = true
    54  }
    55  
    56  # The amazon-secretsmanager data block is generated from your aws_secretsmanager template function; a data
    57  # from this block can be referenced in source and locals blocks.
    58  # Read the documentation for data blocks here:
    59  # https://www.packer.io/docs/templates/hcl_templates/blocks/data
    60  # Read the documentation for the Amazon Secrets Manager Data Source here:
    61  # https://www.packer.io/plugins/datasources/amazon/secretsmanager
    62  data "amazon-secretsmanager" "autogenerated_1" {
    63    name = "sample/app/password"
    64  }
    65  
    66  data "amazon-secretsmanager" "autogenerated_2" {
    67    key  = "api_key"
    68    name = "sample/app/passwords"
    69  }
    70  
    71  data "amazon-secretsmanager" "autogenerated_3" {
    72    name = "some_secret"
    73  }
    74  
    75  data "amazon-secretsmanager" "autogenerated_4" {
    76    key  = "with_key"
    77    name = "some_secret"
    78  }
    79  
    80  # The amazon-ami data block is generated from your amazon builder source_ami_filter; a data
    81  # from this block can be referenced in source and locals blocks.
    82  # Read the documentation for data blocks here:
    83  # https://www.packer.io/docs/templates/hcl_templates/blocks/data
    84  # Read the documentation for the Amazon AMI Data Source here:
    85  # https://www.packer.io/plugins/datasources/amazon/ami
    86  data "amazon-ami" "autogenerated_1" {
    87    access_key = "${var.aws_access_key}"
    88    filters = {
    89      name                = "ubuntu/images/*/ubuntu-xenial-16.04-amd64-server-*"
    90      root-device-type    = "ebs"
    91      virtualization-type = "hvm"
    92    }
    93    most_recent = true
    94    owners      = ["099720109477"]
    95    region      = "${var.aws_region}"
    96    secret_key  = "${var.aws_secret_key}"
    97  }
    98  
    99  # "timestamp" template function replacement
   100  locals { timestamp = regex_replace(timestamp(), "[- TZ:]", "") }
   101  
   102  # All locals variables are generated from variables that uses expressions
   103  # that are not allowed in HCL2 variables.
   104  # Read the documentation for locals blocks here:
   105  # https://www.packer.io/docs/templates/hcl_templates/blocks/locals
   106  local "password" {
   107    sensitive  = true
   108    expression = "${data.amazon-secretsmanager.autogenerated_1.value}"
   109  }
   110  
   111  locals {
   112    password_key = "MY_KEY_${data.amazon-secretsmanager.autogenerated_2.value}"
   113  }
   114  
   115  # source blocks are generated from your builders; a source can be referenced in
   116  # build blocks. A build block runs provisioner and post-processors on a
   117  # source. Read the documentation for source blocks here:
   118  # https://www.packer.io/docs/templates/hcl_templates/blocks/source
   119  source "amazon-ebs" "autogenerated_1" {
   120    access_key      = "${var.aws_access_key}"
   121    ami_description = "Ubuntu 16.04 LTS - expand root partition"
   122    ami_name        = "ubuntu-16-04-test-${local.timestamp}"
   123    encrypt_boot    = true
   124    launch_block_device_mappings {
   125      delete_on_termination = true
   126      device_name           = "/dev/sda1"
   127      volume_size           = 48
   128      volume_type           = "gp2"
   129    }
   130    region              = "${var.aws_region}"
   131    secret_key          = "${var.aws_secret_key}"
   132    source_ami          = "${data.amazon-ami.autogenerated_1.id}"
   133    spot_instance_types = ["t2.small", "t2.medium", "t2.large"]
   134    spot_price          = "0.0075"
   135    ssh_interface       = "session_manager"
   136    ssh_username        = "ubuntu"
   137    temporary_iam_instance_profile_policy_document {
   138      Statement {
   139        Action   = ["*"]
   140        Effect   = "Allow"
   141        Resource = ["*"]
   142      }
   143      Version = "2012-10-17"
   144    }
   145  }
   146  
   147  source "amazon-ebs" "named_builder" {
   148    access_key      = "${var.aws_access_key}"
   149    ami_description = "Ubuntu 16.04 LTS - expand root partition"
   150    ami_name        = "ubuntu-16-04-test-${local.timestamp}"
   151    encrypt_boot    = true
   152    launch_block_device_mappings {
   153      delete_on_termination = true
   154      device_name           = "/dev/sda1"
   155      volume_size           = 48
   156      volume_type           = "gp2"
   157    }
   158    region              = "${var.aws_region}"
   159    secret_key          = "${var.aws_secret_key}"
   160    source_ami          = "${data.amazon-ami.autogenerated_1.id}"
   161    spot_instance_types = ["t2.small", "t2.medium", "t2.large"]
   162    spot_price          = "0.0075"
   163    ssh_interface       = "session_manager"
   164    ssh_username        = "ubuntu"
   165    temporary_iam_instance_profile_policy_document {
   166      Statement {
   167        Action   = ["*"]
   168        Effect   = "Allow"
   169        Resource = ["*"]
   170      }
   171      Version = "2012-10-17"
   172    }
   173  }
   174  
   175  # a build block invokes sources and runs provisioning steps on them. The
   176  # documentation for build blocks can be found here:
   177  # https://www.packer.io/docs/templates/hcl_templates/blocks/build
   178  build {
   179    sources = ["source.amazon-ebs.autogenerated_1", "source.amazon-ebs.named_builder"]
   180  
   181    provisioner "breakpoint" {
   182      only         = ["amazon-ebs"]
   183      pause_before = "5s"
   184    }
   185  
   186    provisioner "shell" {
   187      except      = ["amazon-ebs"]
   188      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()}"]
   189      max_retries = "5"
   190    }
   191  
   192    provisioner "shell" {
   193      inline = ["echo ${local.password}", "echo ${data.amazon-secretsmanager.autogenerated_1.value}", "echo ${local.password_key}", "echo ${data.amazon-secretsmanager.autogenerated_2.value}"]
   194    }
   195  
   196    provisioner "shell" {
   197      inline = ["echo ${data.amazon-secretsmanager.autogenerated_3.value}", "echo ${data.amazon-secretsmanager.autogenerated_4.value}"]
   198    }
   199  
   200  
   201    # 1 error occurred upgrading the following block:
   202    # unhandled "clean_resource_name" call:
   203    # there is no way to automatically upgrade the "clean_resource_name" call.
   204    # Please manually upgrade to use custom validation rules, `replace(string, substring, replacement)` or `regex_replace(string, substring, replacement)`
   205    # 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.
   206    provisioner "shell" {
   207      inline = ["echo mybuild-{{ clean_resource_name `${timestamp()}` }}"]
   208    }
   209  
   210  
   211    # 1 error occurred upgrading the following block:
   212    # unhandled "lower" call:
   213    # there is no way to automatically upgrade the "lower" call.
   214    # Please manually upgrade to `lower(var.example)`
   215    # Visit https://www.packer.io/docs/templates/hcl_templates/functions/string/lower for more infos.
   216    provisioner "shell" {
   217      inline = ["echo {{ lower `SOMETHING` }}"]
   218    }
   219  
   220  
   221    # 1 error occurred upgrading the following block:
   222    # unhandled "upper" call:
   223    # there is no way to automatically upgrade the "upper" call.
   224    # Please manually upgrade to `upper(var.example)`
   225    # Visit https://www.packer.io/docs/templates/hcl_templates/functions/string/upper for more infos.
   226    provisioner "shell" {
   227      inline = ["echo {{ upper `something` }}"]
   228    }
   229  
   230  
   231    # 1 error occurred upgrading the following block:
   232    # unhandled "split" call:
   233    # there is no way to automatically upgrade the "split" call.
   234    # Please manually upgrade to `split(separator, string)`
   235    # Visit https://www.packer.io/docs/templates/hcl_templates/functions/string/split for more infos.
   236    provisioner "shell" {
   237      inline = ["echo {{ split `some-string` `-` 0 }}"]
   238    }
   239  
   240  
   241    # 1 error occurred upgrading the following block:
   242    # unhandled "replace_all" call:
   243    # there is no way to automatically upgrade the "replace_all" call.
   244    # Please manually upgrade to `replace(string, substring, replacement)` or `regex_replace(string, substring, replacement)`
   245    # 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.
   246    provisioner "shell" {
   247      inline = ["echo {{ replace_all `-` `/` `${build.name}` }}"]
   248    }
   249  
   250  
   251    # 1 error occurred upgrading the following block:
   252    # unhandled "replace" call:
   253    # there is no way to automatically upgrade the "replace" call.
   254    # Please manually upgrade to `replace(string, substring, replacement)` or `regex_replace(string, substring, replacement)`
   255    # 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.
   256    provisioner "shell" {
   257      inline = ["echo {{ replace `some-string` `-` `/` 1 }}"]
   258    }
   259  
   260    provisioner "shell-local" {
   261      inline       = ["sleep 100000"]
   262      only         = ["amazon-ebs"]
   263      pause_before = "5s"
   264      timeout      = "5s"
   265    }
   266  
   267    post-processor "amazon-import" {
   268      format         = "vmdk"
   269      license_type   = "BYOL"
   270      region         = "eu-west-3"
   271      s3_bucket_name = "hashicorp.adrien"
   272      tags = {
   273        Description = "packer amazon-import ${local.timestamp}"
   274      }
   275    }
   276    post-processors {
   277      post-processor "artifice" {
   278        keep_input_artifact = true
   279        files               = ["path/something.ova"]
   280        name                = "very_special_artifice_post-processor"
   281        only                = ["amazon-ebs"]
   282      }
   283      post-processor "amazon-import" {
   284        except         = ["amazon-ebs"]
   285        license_type   = "BYOL"
   286        s3_bucket_name = "hashicorp.adrien"
   287        tags = {
   288          Description = "packer amazon-import ${local.timestamp}"
   289        }
   290      }
   291      post-processor "compress" {
   292      }
   293    }
   294  }