packer-cn/builder/amazon/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
..
access_config.go builder/amazon: Add helper function for checking against AWSError 2019-11-12 15:27:47 -05:00
access_config.hcl2spec.go build using HCL2 (#8423) 2019-12-17 11:25:56 +01:00
access_config_test.go make ValidateRegion a member of *AccessConfig and make it variadic 2018-10-24 11:26:53 +02:00
ami_config.go Update builder/amazon/common/ami_config.go 2019-10-30 09:41:23 -07:00
ami_config_test.go builder/amazon/common: remove nil check on slice, len() on nil slices is zero 2019-10-31 12:09:32 -07:00
artifact.go delete amazon import post-processor intermediary snapshots 2019-11-01 14:17:44 -07:00
artifact_test.go Natural order of AMI artifacts 2017-08-24 20:57:12 +02:00
block_device.go amazon docs: update block-device-configuration docs (#8395) 2019-11-25 11:58:30 +01:00
block_device.hcl2spec.go build using HCL2 (#8423) 2019-12-17 11:25:56 +01:00
block_device_test.go fix test 2019-09-20 15:28:43 +02:00
build_filter.go need to initialize variables scoped to the individual loop, because the address of k,v stay the same and that means we overwrite previous variables when assigning them to the struct directly. 2019-10-28 14:31:13 -07:00
build_filter_test.go add test to catch this case 2019-10-29 11:28:56 -07:00
errors.go builder/amazon/common: remove nil check on slice, len() on nil slices is zero 2019-10-31 12:09:32 -07:00
errors_test.go use a UI wrapper to auto-decode error messages 2018-09-11 16:05:43 -07:00
helper_funcs.go builder/amazon: Add helper function for checking against AWSError 2019-11-12 15:27:47 -05:00
interpolate_build_info.go Expose more source ami data in the template 2018-03-30 10:47:11 +02:00
interpolate_build_info_test.go Add interpolate_build_info_test tests 2018-03-30 16:46:35 +02:00
regions.go aws: document ValidateRegion better 2019-02-27 11:17:08 +01:00
run_config.go added the option to skip IAM instance profile validation (#8457) 2019-12-10 09:17:38 +01:00
run_config.hcl2spec.go build using HCL2 (#8423) 2019-12-17 11:25:56 +01:00
run_config_test.go builder.amazon.common: remove pointer (*) from []*string and map[*string]*string types 2019-10-15 12:56:41 +02:00
ssh.go make sure amazon builders respect ssh_host option 2019-09-26 12:30:04 -07:00
ssh_test.go updates tests to validate that ssh_host value supplied in the template overrides all else 2019-09-27 09:19:23 -07:00
state.go make error messaging around ResourceNotReady better, update docs with other possible issues (#8349) 2019-11-08 11:15:24 +01:00
state_test.go refactored env var code and tests so that I don't have to set env vars during tests to check logic 2018-07-11 10:36:21 -07:00
step_ami_region_copy.go delete amazon import post-processor intermediary snapshots 2019-11-01 14:17:44 -07:00
step_ami_region_copy_test.go use trilean initializers in test where missing 2019-08-23 11:17:45 +02:00
step_cleanup_volumes.go make error messaging around ResourceNotReady better, update docs with other possible issues (#8349) 2019-11-08 11:15:24 +01:00
step_create_tags.go builder/amazon: Add helper function for checking against AWSError 2019-11-12 15:27:47 -05:00
step_deregister_ami.go rename interpolation context from ctx to ictx and contexts to ctx to avoid conflicts 2019-04-03 15:56:15 +02:00
step_get_password.go adding ctx makes the cancel channel redundant 2019-09-13 14:32:13 -07:00
step_iam_instance_profile.go build using HCL2 (#8423) 2019-12-17 11:25:56 +01:00
step_key_pair.go refactor: replace the maxBackoff from 30 nanosecond to 30 seconds 2019-06-11 16:01:03 +05:30
step_modify_ami_attributes.go rename interpolation context from ctx to ictx and contexts to ctx to avoid conflicts 2019-04-03 15:56:15 +02:00
step_modify_ebs_instance.go amazon-ebssurrogate: allow enabling ena/sr-iov on spot instances 2019-11-21 11:13:32 +01:00
step_network_info.go builder.amazon.common: remove pointer (*) from []*string and map[*string]*string types 2019-10-15 12:56:41 +02:00
step_pre_validate.go builder/amazon/common/step_pre_validate: Return DescribeVpcs errors 2019-11-19 20:18:53 +00:00
step_pre_validate_test.go test/builder/amazon/common/step_pre_validate: Update DescribeVpcs mock 2019-11-19 14:48:07 -05:00
step_run_source_instance.go Fix request retry mechanism to run aws instance 2019-11-29 18:11:10 +01:00
step_run_spot_instance.go enable no_ephemeral for spot devices, clean up ranging behavior, update docs 2019-11-21 12:46:31 -08:00
step_run_spot_instance_test.go builder/amazon/common: remove dead test type and function mockEC2ConnSpot.DescribeSpotPriceHistory() 2019-10-31 12:34:11 -07:00
step_security_group.go make error messaging around ResourceNotReady better, update docs with other possible issues (#8349) 2019-11-08 11:15:24 +01:00
step_source_ami_info.go builder.amazon.common: remove pointer (*) from []*string and map[*string]*string types 2019-10-15 12:56:41 +02:00
step_source_ami_info_test.go change Builder to be passed a context for cancellation 2019-04-03 15:55:55 +02:00
step_stop_ebs_instance.go builder/amazon: Add helper function for checking against AWSError 2019-11-12 15:27:47 -05:00
tags.go rename interpolation context from ctx to ictx and contexts to ctx to avoid conflicts 2019-04-03 15:56:15 +02:00
template_funcs.go Revert "fix template imports" 2019-11-04 14:29:00 -08:00
template_funcs_test.go Fix not allowed comma, add all allowed special characters 2015-10-19 13:41:30 +03:00