packer/builder/hyperv/common
Adrien Delorme 0785c2f6fc
build using HCL2 (#8423)
This follows #8232 which added the code to generate the code required to parse
HCL files for each packer component.

All old config files of packer will keep on working the same. Packer takes one
argument. When a directory is passed, all files in the folder with a name
ending with  “.pkr.hcl” or “.pkr.json” will be parsed using the HCL2 format.
When a file ending with “.pkr.hcl” or “.pkr.json” is passed it will be parsed
using the HCL2 format. For every other case; the old packer style will be used.

## 1. the hcl2template pkg can create a packer.Build from a set of HCL (v2) files

I had to make the packer.coreBuild (which is our one and only packer.Build ) a public struct with public fields

## 2. Components interfaces get a new ConfigSpec Method to read a file from an HCL file.

  This is a breaking change for packer plugins.

a packer component can be a: builder/provisioner/post-processor

each component interface now gets a `ConfigSpec() hcldec.ObjectSpec`
which allows packer to tell what is the layout of the hcl2 config meant
to configure that specific component.

This ObjectSpec is sent through the wire (RPC) and a cty.Value is now
sent through the already existing configuration entrypoints:

 Provisioner.Prepare(raws ...interface{}) error
 Builder.Prepare(raws ...interface{}) ([]string, error)
 PostProcessor.Configure(raws ...interface{}) error

close #1768


Example hcl files:

```hcl
// file amazon-ebs-kms-key/run.pkr.hcl
build {
    sources = [
        "source.amazon-ebs.first",
    ]

    provisioner "shell" {
        inline = [
            "sleep 5"
        ]
    }

    post-processor "shell-local" {
        inline = [
            "sleep 5"
        ]
    }
}

// amazon-ebs-kms-key/source.pkr.hcl

source "amazon-ebs" "first" {

    ami_name = "hcl2-test"
    region = "us-east-1"
    instance_type = "t2.micro"

    kms_key_id = "c729958f-c6ba-44cd-ab39-35ab68ce0a6c"
    encrypt_boot = true
    source_ami_filter {
        filters {
          virtualization-type = "hvm"
          name =  "amzn-ami-hvm-????.??.?.????????-x86_64-gp2"
          root-device-type = "ebs"
        }
        most_recent = true
        owners = ["amazon"]
    }
    launch_block_device_mappings {
        device_name = "/dev/xvda"
        volume_size = 20
        volume_type = "gp2"
        delete_on_termination = "true"
    }
    launch_block_device_mappings {
        device_name = "/dev/xvdf"
        volume_size = 500
        volume_type = "gp2"
        delete_on_termination = true
        encrypted = true
    }

    ami_regions = ["eu-central-1"]
    run_tags {
        Name = "packer-solr-something"
        stack-name = "DevOps Tools"
    }
    
    communicator = "ssh"
    ssh_pty = true
    ssh_username = "ec2-user"
    associate_public_ip_address = true
}
```
2019-12-17 11:25:56 +01:00
..
artifact.go move packer to hashicorp 2017-04-04 13:39:01 -07:00
artifact_test.go move packer to hashicorp 2017-04-04 13:39:01 -07:00
config.go regenerated things 2019-10-21 14:21:15 -07:00
driver.go check to make sure a vm-name isn't already in use before trying to launch a vm with said name. 2019-06-13 14:09:45 -07:00
driver_mock.go check to make sure a vm-name isn't already in use before trying to launch a vm with said name. 2019-06-13 14:09:45 -07:00
driver_ps_4.go check to make sure a vm-name isn't already in use before trying to launch a vm with said name. 2019-06-13 14:09:45 -07:00
output_config.go commit old code generation tool 2019-10-15 12:56:42 +02:00
output_config.hcl2spec.go build using HCL2 (#8423) 2019-12-17 11:25:56 +01:00
output_config_test.go use interpolate.NewContext() instead of testConfigTemplate(t) 2019-06-14 12:17:28 +02:00
ssh.go Added comment regarding use of host param. 2018-12-27 03:34:08 -06:00
ssh_config.go move packer to hashicorp 2017-04-04 13:39:01 -07:00
step_clone_vm.go refactir hyperv builders to remove duplicated config and prepare code 2019-10-21 13:29:56 -07:00
step_collate_artifacts.go rename interpolation context from ctx to ictx and contexts to ctx to avoid conflicts 2019-04-03 15:56:15 +02:00
step_collate_artifacts_test.go Change variable/statebag key name to better convey purpose 2018-07-20 02:12:45 +01:00
step_compact_disk.go rename interpolation context from ctx to ictx and contexts to ctx to avoid conflicts 2019-04-03 15:56:15 +02:00
step_compact_disk_test.go Change variable/statebag key name to better convey purpose 2018-07-20 02:12:45 +01:00
step_configure_ip.go rename interpolation context from ctx to ictx and contexts to ctx to avoid conflicts 2019-04-03 15:56:15 +02:00
step_configure_vlan.go rename interpolation context from ctx to ictx and contexts to ctx to avoid conflicts 2019-04-03 15:56:15 +02:00
step_create_build_dir.go rename interpolation context from ctx to ictx and contexts to ctx to avoid conflicts 2019-04-03 15:56:15 +02:00
step_create_build_dir_test.go Add tmp package that offers Dir & File funcs 2018-12-12 16:35:57 +01:00
step_create_external_switch.go Remove explicit err var declaration 2019-10-09 13:17:43 +02:00
step_create_switch.go rename interpolation context from ctx to ictx and contexts to ctx to avoid conflicts 2019-04-03 15:56:15 +02:00
step_create_vm.go check to make sure a vm-name isn't already in use before trying to launch a vm with said name. 2019-06-13 14:09:45 -07:00
step_create_vm_test.go add tests 2019-06-13 14:29:22 -07:00
step_disable_vlan.go rename interpolation context from ctx to ictx and contexts to ctx to avoid conflicts 2019-04-03 15:56:15 +02:00
step_enable_integration_service.go rename interpolation context from ctx to ictx and contexts to ctx to avoid conflicts 2019-04-03 15:56:15 +02:00
step_export_vm.go rename interpolation context from ctx to ictx and contexts to ctx to avoid conflicts 2019-04-03 15:56:15 +02:00
step_export_vm_test.go Fix up tests. Ensure export step stores the export path in state 2018-07-20 02:12:44 +01:00
step_mount_dvddrive.go rename interpolation context from ctx to ictx and contexts to ctx to avoid conflicts 2019-04-03 15:56:15 +02:00
step_mount_floppydrive.go rename interpolation context from ctx to ictx and contexts to ctx to avoid conflicts 2019-04-03 15:56:15 +02:00
step_mount_guest_additions.go rename interpolation context from ctx to ictx and contexts to ctx to avoid conflicts 2019-04-03 15:56:15 +02:00
step_mount_secondary_dvd_images.go rename interpolation context from ctx to ictx and contexts to ctx to avoid conflicts 2019-04-03 15:56:15 +02:00
step_polling_installation.go rename interpolation context from ctx to ictx and contexts to ctx to avoid conflicts 2019-04-03 15:56:15 +02:00
step_reboot_vm.go rename interpolation context from ctx to ictx and contexts to ctx to avoid conflicts 2019-04-03 15:56:15 +02:00
step_run.go Move hyper-v host ip determination earlier in steps, connect to Hyper-V vm prior to issuing the start operation. 2019-08-19 11:45:41 -07:00
step_shutdown.go allow a provisioner to timeout 2019-04-08 20:09:21 +02:00
step_sleep.go rename interpolation context from ctx to ictx and contexts to ctx to avoid conflicts 2019-04-03 15:56:15 +02:00
step_test.go Tests for step to create build directory 2018-07-20 02:12:45 +01:00
step_type_boot_command.go Move hyper-v host ip determination earlier in steps, connect to Hyper-V vm prior to issuing the start operation. 2019-08-19 11:45:41 -07:00
step_unmount_dvddrive.go rename interpolation context from ctx to ictx and contexts to ctx to avoid conflicts 2019-04-03 15:56:15 +02:00
step_unmount_floppydrive.go rename interpolation context from ctx to ictx and contexts to ctx to avoid conflicts 2019-04-03 15:56:15 +02:00
step_unmount_guest_additions.go rename interpolation context from ctx to ictx and contexts to ctx to avoid conflicts 2019-04-03 15:56:15 +02:00
step_unmount_secondary_dvd_images.go rename interpolation context from ctx to ictx and contexts to ctx to avoid conflicts 2019-04-03 15:56:15 +02:00
step_wait_for_install_to_complete.go rename interpolation context from ctx to ictx and contexts to ctx to avoid conflicts 2019-04-03 15:56:15 +02:00