Commit Graph

48 Commits

Author SHA1 Message Date
Adrien Delorme 840e67f775
HCL2: when we see a map generate an attribute spec instead of a block spec (#9035)
* mapstructure-to-hcl2: when we see a map generate an attribute spec and not a block spec

this will alow to do

tags = {
 key = "value"
}

instead of

tags {
  key = "value"
}

This will also enable using variables directly for those tags

* generate code

* update tests
2020-04-14 16:05:13 +02:00
Adrien Delorme 7d5f0c11af add max_retries option to aws builders 2020-02-07 16:36:14 +01:00
Sylvia Moss dc31bad539
Sharing info with post-processors via artifact (#8632) 2020-01-30 11:27:58 +01:00
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
Megan Marsh e9e4c102e5 delete amazon import post-processor intermediary snapshots 2019-11-01 14:17:44 -07:00
Adrien Delorme 078ba7c8c3 commit old code generation tool
for history
2019-10-15 12:56:42 +02:00
Megan Marsh 9e28b2f5cf fix post-processor 2019-09-16 13:45:28 -07:00
Adrien Delorme a81abd297b Merge remote-tracking branch 'origin/master' into context_provisioner 2019-04-08 20:09:01 +02:00
Adrien Delorme e65115a7a0 contextualize post-processor 2019-04-03 15:55:55 +02:00
Megan Marsh 12fc1fa751 default_keep_input_artifact 2019-04-02 16:51:58 -07:00
Matt Stofko ab4382360d Support S3 and AMI encryption 2019-03-11 13:21:47 -07:00
Megan Marsh 3ed9fe6dee remove unused imports
remove HttpClientWithEnvironmentProxy from amazon builders; let access config handle it
2019-03-04 16:42:33 -08:00
Megan Marsh 035c3506ba manually set proxyfromenvironment in default http client for ec2 sessions 2019-01-25 12:33:25 -08:00
Rickard von Essen a02bd23f56
When import task fails show the StatusMessage
This will hopefully tell the user the reason of the failure.
2019-01-17 13:36:44 +01:00
Megan Marsh 042e9ad14b Move logging about aws waiters to the access config prepare() so that it's only spit out once per builder. 2018-12-06 14:37:31 -08:00
Adrien Delorme b113518815
Use switch for readability
Co-Authored-By: c0sco <778087+c0sco@users.noreply.github.com>
2018-10-30 10:06:31 -07:00
Matt Stofko 029819b5d5 Support formats other than OVA. 2018-10-29 14:52:12 -07:00
Megan Marsh ff6a039d5b replace scrubconfig with packer.LogSecretFilter.Set
filter winrm password from logs
Add new root-level packer template option, sensitive-variables, to tell us what user variables to mark sensitive.
2018-08-20 15:35:55 -07:00
Megan Marsh f657ca39c9 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
Megan Marsh bfbe318727 fix the homegrown waiters
fix image import; issue was with wait options not being evaluated
2018-07-11 10:36:21 -07:00
Megan Marsh f49a2d8aed move UI call to before the wait; add context to these steps 2018-07-11 10:36:21 -07:00
Megan Marsh cf63dd10bf replace AMIStateRefreshFunc, InstanceStateRefreshFunc, our spot instance waiter, our chroot volume waiter, and our snapshot waiters with waiters form AWS's SDK. 2018-07-11 10:34:20 -07:00
Matthew Hooker 48e12b6bee
only set role name if it's set. 2018-01-25 10:39:21 -08:00
Brian Terry 380147200c Added role in amazon-import 2018-01-25 10:56:30 -05:00
Matthew Hooker f3dea272d9
Set session in state bag
We can construct connections to arbitrary regions from it
2017-12-19 11:32:33 -08:00
Matthew Hooker f6c401a143
don't pass in accessconfig 2017-12-19 11:32:32 -08:00
Rong Chen 3e92b1374e issue5606: follow the convention to use AccessConfig to create new aws session for step_create_tags etc. 2017-12-19 10:34:12 -08:00
Krzysztof Wilczynski 05327b7524
amazon: Remove Session Token (STS) from being shown in the log.
This commit adds a change which ensures that the Session Token
config struct item is removed from log output.

Signed-off-by: Krzysztof Wilczynski <kw@linux.com>
2017-12-04 22:14:38 +01:00
Matthew Hooker 56c513088b
I think this was the intention 2017-06-09 10:34:49 -07:00
Matthew Hooker a52cd65af8
remove license type from general debugging 2017-06-05 15:27:33 -07:00
Brian Warsing 8cc4558df9 fix bad conditional logic and assignment 2017-05-24 13:22:46 -07:00
Brian Warsing 47df47c73f conform ImportImage LicenseType behaviour
- remove the synthetic default; defaults are established internally by the func
- store ImportImageInput in params var
- only pack the LicenseType into struct if a value has been set
2017-05-24 11:33:21 -07:00
Brian Warsing c5dfe3d503 amazon-import post-processor: support license_type
Implements a new config option for the amazon-import post-processor
allowing users to specify a LicenseType during the import process.

Closes: #4631
2017-05-24 11:30:24 -07:00
Matthew Hooker 81522dced0
move packer to hashicorp 2017-04-04 13:39:01 -07:00
Matthew Hooker 6f27f67346
more fixes from errcheck 2017-03-29 13:38:31 -07:00
Matthew Hooker 230079f73a
spell fixes 2017-03-28 20:36:19 -07:00
Zanetti, David c22b97dd43 Support setting AMI attributes when using amazon-import post-processor
- ami_user and ami_group for launch permissions
- ami_description to set the description attribute

Closes #3981
2016-11-29 16:54:02 +13:00
Matthew Hooker 48bdae93d1 aws-sdk: use session.NewSession 2016-11-01 15:53:04 -07:00
Rickard von Essen 3c8dabba9e Fixed formatting 2016-10-11 23:43:50 +02:00
Ian Duffy 641ae2d837
Allow naming of vm imported AMIs
Signed-off-by: Ian Duffy <ian@ianduffy.ie>
2016-09-29 16:12:57 +01:00
Chris Bednarski 0f319fde08 Add debug logging for the credentials used for S3 in amazon-import 2016-03-10 16:52:16 -08:00
Chris Bednarski 4458de4ea0 Reformat 2016-02-11 23:53:40 -08:00
David Zanetti a3911ad47c Use interpolation on default s3_key_name. Report import errors from AWS.
- Import errors were not very useful messages, obtain the import status
  from the import task as AWS reports it
- Interpolate s3_key_name as per PR comments (rather than hard-code the
  generated parts of the default value)
- Remove descriptions on AWS import job, they are optional anyway.
2015-11-26 14:02:15 +13:00
David Zanetti 873dc89478 Accept any OVA. Fix names for tasks/import/copy. Update docs.
- s3_key_name is now optional, default is equivilent to
  "packer-import-{{timestamp}}"
- Remove restriction on builder used, anything producing an OVA is okay
- Fix task and ova description passed to import API call, correctly
  adds timestamp to both
- Documentation updated
  - Remove VMware-specific text
  - Mark s3_key_name as optional
  - Remove s3_key_name from example now it's optional
  - Explain the import process more clearly in example
2015-11-25 10:06:35 +13:00
David Zanetti 274630bd9c Support adding tags to AMI and snapshots created by amazon-import
- Tags follows the same approach as the amazon-ebs builder
- Clean up some debug messages
- Improve readability by pulling out AMI id into seperate variable

Note: this duplicates the tag creation code in
builder/amazon/common/step_create_tags.go. Maybe this should be a multistep
post-processor instead, and we re-use steps from the builder.
2015-11-24 14:23:19 +13:00
David Zanetti 95b3ea50ae Add more useful messages and clean up after ourselves
- S3 object uploaded removed after import (with disable option)
- Indicate to user when import is complete
- Close the source file uploaded after upload is done
- Each step of import process logs a debug message
2015-11-24 12:08:31 +13:00
David Zanetti 418da16991 Track the import task and report AMIs created from it 2015-11-23 15:55:09 +13:00
David Zanetti 439d1b1788 First cut at amazon ova importer 2015-11-23 12:32:03 +13:00