Commit Graph

162 Commits

Author SHA1 Message Date
Adrien Delorme 88297c796d Merge branch 'master' into hcl2_singular_blocks 2020-03-17 14:47:17 +01:00
Adrien Delorme 911dc5ad95 wip 2020-03-17 11:33:11 +01:00
Adrien Delorme b5e8750f5f Change key/value to name/value to remain consistent with Terraform 2020-03-17 11:23:11 +01:00
Adrien Delorme d532bb376c wip 2020-03-16 17:47:44 +01:00
Adrien Delorme c845436e32 KeyValues.CopyOn: make sure a receiving nil map is set too 2020-03-16 15:46:08 +01:00
Adrien Delorme 87d6b2433f make generate 2020-03-16 15:21:29 +01:00
Adrien Delorme 392afa30cf Update block_device.go 2020-03-16 12:37:36 +01:00
Adrien Delorme 0cbf80dafe wip 2020-03-16 12:26:03 +01:00
Adrien Delorme dab689ce2e WIP 2020-03-16 12:19:34 +01:00
Adrien Delorme 6e6490d688 WIP 2020-03-13 18:04:48 +01:00
r_takaishi f50ff1d270 make generate 2020-03-13 11:29:42 +09:00
Adrien Delorme 7d5f0c11af add max_retries option to aws builders 2020-02-07 16:36:14 +01:00
Megan Marsh d252a24b82 allow user to set winrm_host override like we do ssh_host override 2020-01-30 15:22:22 -08:00
Sylvia Moss dc31bad539
Sharing info with post-processors via artifact (#8632) 2020-01-30 11:27:58 +01:00
Sylvia Moss 0677b02e18
Share SourceImageName with provisioners and manifest post-processor (#8603) 2020-01-16 12:04:03 +01:00
Adrien Delorme 731904d3d2 mapstructure-to-hcl2: use accessor for named types and not named type + go genrate + tests 2020-01-07 11:44:22 +01:00
Adrien Delorme 4b7132c87c Merge remote-tracking branch 'origin/master' into sharing_info 2019-12-17 11:57:09 +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 0f6d1beccf add an extra string array to the Prepare() return values in the builder interfaces; this sets up the ability for builders to give the provisioners custom user-accessible build-time variables. 2019-12-16 21:23:05 -08:00
Oded Priva 5e81c6f44e added the option to skip IAM instance profile validation (#8457) 2019-12-10 09:17:38 +01:00
Bernard Baltrusaitis 8b83cca064 adding temporary instance profile document policy 2019-10-19 20:56:18 +11:00
Megan Marsh 0cbd3ff0f3 make sure amazon builders respect ssh_host option 2019-09-26 12:30:04 -07:00
Adrien Delorme 3fe9d52e3f Merge remote-tracking branch 'origin/master' into scrape_doc_to_builder_struct_config 2019-09-20 11:15:44 +02:00
Adrien Delorme 146b88ba1e Merge remote-tracking branch 'origin/master' into scrape_doc_to_builder_struct_config 2019-09-10 12:44:46 +02:00
Adrien Delorme de9bb26f62
Merge branch 'master' into fix_7959 2019-09-10 12:21:33 +02:00
DanHam bbeb1a3528
Delete any `run_volume_tags` applied to EBS volumes at instance creation
* Allows `run_volume_tags` to be set without requiring a major rewrite
  of the (common) amazon builder code used to start an instance.
  The common start up code tags the instance and *all attached volumes
  at creation*. If `run_volume_tags` are set this means that any volumes
  specified in `ebs_volumes` will *initially* be tagged with the
  `run_volume_tags` rather than the tags set in the `ebs_volumes`
  section
* Once the instance is reported to be 'ready' the step to tag the EBS
  volumes is run. Once complete all volumes should have the tags
  requested by the user:

    * Volumes associated with the source instance should be tagged with
      the tags set in `run_volume_tags` (if any)
    * Each EBS volumes specified in the `ebs_volumes` section of the
      template should only be tagged with its associated tags (if any)
2019-08-30 14:30:25 +01:00
DanHam 61b1605a85
More accurate error description; Add comments; Add output 2019-08-30 14:26:06 +01:00
DanHam 430d41fbf9
Add option to enable tagging of the running instances volumes
* Currently this results in *all* volumes attached to the instance
  being tagged with the `run_volume_tags`. This includes any `ebs_volumes`
  for which the user may have configured other tags.
* This issue will be addressed in a later commit
2019-08-30 14:16:29 +01:00
DanHam 30070ffb30
Sort fields and options alphabetically 2019-08-30 14:16:29 +01:00
Adrien Delorme 239f97471c fix ebs volume tags doc field
Co-Authored-By: Megan Marsh <swampdragons@users.noreply.github.com>
2019-08-27 09:21:29 +02:00
Megan Marsh 1a6adadb89 convert EnableAMIENASupport to trilean in code 2019-08-22 13:18:22 -07:00
Megan Marsh 3c3f7f26ce implement custom data type "trilean" (tri-state-boolean) to track booleans which have a "null" or "unset" state. Previously we used *bool for these template options, but it turns out that those won't work because "unset" will evaluate to "false" if a user is using template variables to set the option that maps to a *bool. 2019-08-22 13:18:15 -07:00
Adrien Delorme 4cb7c30987 Merge remote-tracking branch 'origin/master' into scrape_doc_to_builder_struct_config 2019-08-21 16:44:23 +02:00
Megan Marsh 6ad975f296 Revert "move SSHInterface/SSHIPVersion fields to communitator.Config struct"
This reverts commit b0c09087a2.
2019-07-02 10:46:10 -07:00
Megan Marsh 62120c5c0b
Merge pull request #7813 from hashicorp/stop_calculating_spot_bids
stop calculating spot bids
2019-07-02 10:35:45 -07:00
Megan Marsh d4b6a61445 don't store names of volumes we will be deleting when the instance terminates 2019-07-01 14:44:17 -07:00
Megan Marsh c722afe707 stop calculating spot bids; amazon changed the way spot instances are priced to be stable rather than bid-based, so when user sets auto, we can just default to the ondemand price and know that they'll get the same price as everyone else bidding at that time. 2019-07-01 13:01:41 -07:00
Adrien Delorme 8cea5d409a doc ebsvolume builder using partials 2019-06-19 12:02:12 +02:00
Adrien Delorme dcc22df609 aws: move the OmitFromArtifact field in ebssurrogat where it's being used
also, simplified a bit the usage of block device
2019-06-18 16:04:12 +02:00
Adrien Delorme ff2e0298ba simplify block devices utilisation by removing intermediary types 2019-06-18 12:37:47 +02:00
Adrien Delorme 8e857d64f1 aws: rewrap struct comments for documentation generation 2019-06-06 17:34:17 +02:00
Adrien Delorme 4399684372 make fmt autogenerated docs 2019-06-06 16:29:25 +02:00
Adrien Delorme e6cbb013ba add // go:generate struct-markdown to all previously edited files 2019-06-05 16:42:18 +02:00
Adrien Delorme f1917edd34 generate the comments for config struct of builders scraping doc website 2019-06-05 16:42:17 +02:00
Megan Marsh 708165eaa8 refactoring step_run_spot_instance and swapping out the calls to create a spot instance with a call to create a spot fleet of one, so that we can be more flexible with the instance type when desired 2019-05-24 09:32:54 -07:00
Adrien Delorme c4f3dccc14 rename interpolation context from ctx to ictx and contexts to ctx to avoid conflicts 2019-04-03 15:56:15 +02:00
Adrien Delorme a4bf94dd3c change Builder to be passed a context for cancellation
we have to to give it to our hook
2019-04-03 15:55:55 +02:00
Akshat Mahajan f07e4214cc Addresses issues #5384, #5494: Rename and change `temporary_security_group_source_cidr`
to accept a list of strings (for Amazon builders).

Per this change, `temporary_security_group_source_cidr` in the configuration:

1. Will be renamed to `temporary_security_group_source_cidrs`.
2. Will accept a list of CIDRs.
3. Will have its documentation updated to reflect this change.
4. Will have a fixer attached for newer templates to avail of.
2019-03-30 15:47:03 -07:00
Adrien Delorme 9f82b75e57 Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 12:11:58 +01: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 3704a053d0 move region validation and credential wait into step pre validate 2019-02-05 14:07:04 -08:00
Megan Marsh 035c3506ba manually set proxyfromenvironment in default http client for ec2 sessions 2019-01-25 12:33:25 -08:00
Megan Marsh c03894c05d fix bad interpolation exemption for volume_size 2018-11-29 16:39:43 -08:00
Megan Marsh 9573013d3a
Merge pull request #6872 from aspectcapital/disable-ena-support
Add support to explicitly disable ENA support
2018-10-19 10:54:38 -07:00
Matt Dainty feb8067c7d Convert `ena_support` to a pointer
This means it now has three states, `true`, `false`, & `nil`. The
default state is now `nil` which does nothing instead of `false` which
now will explicitly disable ENA support instead of just not enabling it.
2018-10-19 12:40:43 +01:00
Megan Marsh 57f87f58b9
Merge pull request #6374 from rickard-von-essen/aws-filters
builder/amazon: Add suppport for vpc_filter, subnet_filter, and security_group_filter
2018-10-18 14:34:02 -07:00
Adrien Delorme 22d3e9b5c4 builder/amazon/ebs: pass config as a pointer so values could be populated by a run 2018-09-27 16:27:34 +02:00
Matthew Hooker 9181570bc3
remove stray struct dumps in logs 2018-09-27 00:14:05 -07:00
Megan Marsh 79093da6ad skip region validation in tests that don't care; refactor Prepare func so we can test region validation logic with a mock 2018-09-19 10:30:08 -07:00
Megan Marsh 38cc525ec7 new option allowing user to clean up the ephemeral ssh key from the authorized_keys file 2018-09-14 11:06:38 -07:00
Adrien Delorme 2e73ed8d46 pass Comm instance to fix Spot instance creation 2018-09-11 18:20:14 -07:00
Adrien Delorme e02d0dacc4
Merge branch 'master' into aws-filters 2018-09-07 16:14:00 +02:00
RenaudS 26aab49aaf aws spot instances: add block_duration_minutes option (#6638)
* Add block_duration_minutes option

* int64 cannot be nil

* Update doc

* Fix formating
2018-09-03 08:33:58 +02:00
Adrien Delorme df9e756865 pass the Comm instance to the amazon ebs builders steps 2018-08-30 12:50:29 +02:00
Adrien Delorme b0c09087a2 move SSHInterface/SSHIPVersion fields to communitator.Config struct 2018-08-29 14:51:28 +02:00
Adrien Delorme ef4ca9c48e builder.amazon: use c.Comm for ssh 2018-08-29 14:40:33 +02:00
Adrien Delorme 293c485372 builder.aws: use SSHAgentAuth from Comm 2018-08-29 14:40:33 +02:00
Adrien Delorme ef08c441c9 builder.aws: use Comm field for StepKeyPair & StepGetPassword 2018-08-29 14:40:33 +02:00
Adrien Delorme 51d2aac9f6 SSHPrivateKey => SSHPrivateKeyFile 2018-08-29 14:40:32 +02:00
Matthew Hooker e41e99954d
go 1.11 format rules 2018-08-24 15:56:44 -07:00
Rickard von Essen 533967cb66 builder/amazon: Add suppport for security_group_filter
Allow selecting SG's using a filter. Also some cleanup of vpc_filter and
subnet_filter.
2018-08-24 12:42:38 +02:00
Megan Marsh 340363a649
Merge pull request #6613 from hashicorp/merge_ssh_config_funcs
Merge ssh config funcs from builders
2018-08-23 16:03:36 -07:00
Adrien Delorme 41f6e0334d refactor all copy pasted sshConfig with into communicator.Config.SSHConfigFunc
* still need to append the auth methods into an array for gracefullness
2018-08-22 17:02:23 +02: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
Mark Meyer 3dbf1cb371 Enable tagging of spot requests
This adds a new parameter to the EBS builders named `spot_tags'. This
parameter accepts a map of tags, much like `tags'. These tags will be
applied to a spot request that is created.

Improve visibility.
2018-07-07 16:06:51 +02:00
DanHam d5304a25e9
Pass T2 Unlimited settings to run instance step for appropriate EC2 builders 2018-05-15 12:25:06 +01:00
Megan Marsh 3afb243f11 use build name to ensure that winrm password and other shared state is not overwritten if two builders need the password in the same packer run. 2018-04-16 13:41:17 -07:00
ADO 507b3619e7 Expose more source ami data in the template 2018-03-30 10:47:11 +02:00
Matthew Hooker 21812fa17f
Add volume and run tags if in us-gov/china
We can't tag on instance creation when we're in "restricted" regions,
so let's add the tags after the resources have been created.

Adds methods to AccessConfig to detect if we're in China or US Gov
regions (i.e. "restricted").

Also turns tag:tag maps into a type, and moves methods around validating
and converting them to ec2Tags to methods of the type.
2018-02-05 16:39:20 -08:00
Matthew Hooker 7a189a83a1
fix imports
`find . -type f -name '*.go' -not -path "./vendor/*" -exec goimports -w {} \;`
2018-01-24 17:09:17 -08:00
Matthew Hooker a831d522be
change run signatures
Run now takes a context as well as a statebag. We'll assign the context
to the blank identifier to prevent namespace collisions. We'll let the
step authors opt-in to using the context.

`find . -iname "step_*.go" -exec gsed -i'' 's/func \(.*\)Run(/func \1Run(_ context.Context, /' {} \;`
2018-01-24 17:09:17 -08:00
Matthew Hooker 366dc3da0a
move multistep imports to helper.
gomvpkg -from "github.com/mitchellh/multistep" -to "github.com/hashicorp/packer/helper/multistep"
2018-01-24 17:09:15 -08:00
Matthew Hooker cea2ab8c6d
move kms/encrypted validation to block devices 2018-01-12 15:10:51 -08:00
Matthew Hooker e968f9d6cc
spelling/style fixes 2018-01-12 14:26:56 -08:00
Jason Wieringa f6772f06be builder/amazon: Raise error when ebsvolume kms_key_id is without encrypted = true 2018-01-11 20:27:38 -08:00
Rickard von Essen 63f791570a
Merge pull request #5665 from kwilczynski/remove-sts-token-from-logging
amazon: Remove Session Token (STS) from being shown in the log.
2017-12-10 06:50:42 +01:00
Matthew Hooker f216330ba3
spot instance ena/sriov checking for all other builders 2017-12-08 14:56:19 -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
John Davies-Colley 707ec675b2 ssh interface for amazon builders 🔨 2017-11-22 15:49:38 +13:00
Matthew Hooker 95e4ae251e
WIP 2017-11-02 09:03:44 -07:00
Mark Meyer 309bf61257 Add missing blockdevices to ebsvolume builder 2017-10-23 22:33:16 +02:00
Mark Meyer 1cc9b3f1e3 Bring back volume tagging to ebsvolume
Related to #5486
2017-10-23 22:09:04 +02:00
Matthew Hooker f7e269945e
add cidr validation and rename option 2017-10-12 17:05:56 -07:00
Matthew Hooker c74be87187 Merge pull request #5384 from dave2/sg-source-cidr
[WIP] Allow temporary security group to have source CIDR block explicit
2017-10-12 17:05:45 -07:00
Mark Meyer dbb3c76032 Remove redundant step and its usage
StepTagEBSVolumes is no longer needed, since this functionality is now
taken over by StepRunSourceInstance and StepRunSpotInstance. So remove
this functionality from the codebase.
2017-10-12 21:40:21 +02:00
Mark Meyer 2661fd7869 Move building of spot instances into its own step 2017-10-04 12:38:21 +02:00
Zanetti, David 8a8b51be97 Allow temporary security group to have source CIDR block explicitly provided 2017-09-26 00:57:56 +00:00
Megan Marsh 2d4bc70d7b use ami prefix to make it clear that these variables are amazon specific
add fixer, fixer tests
2017-08-28 11:21:27 -07:00
Megan Marsh 9e2e467b31 Allow granular modification of sriov and ena enhanced networking options in amazon amis. Maintain old functionality. 2017-08-25 14:49:53 -07:00
Matthew Hooker 56c513088b
I think this was the intention 2017-06-09 10:34:49 -07:00