Commit Graph

1231 Commits

Author SHA1 Message Date
Adrien Delorme 392afa30cf Update block_device.go 2020-03-16 12:37:36 +01:00
Adrien Delorme fc837e3698 Update run_config.go 2020-03-16 12:36:20 +01:00
Adrien Delorme ce8d3d3747 wip 2020-03-16 12:35:25 +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 dbb4981d66 WIP 2020-03-16 12:13:05 +01:00
Megan Marsh 6008f911fd
Merge pull request #8847 from takaishi/support-keyboard-interactive
communicator/ssh: support keyboard-interactive auth to connect bastion
2020-03-13 11:48:12 -07:00
Adrien Delorme 6f2f17c400 WIP 2020-03-13 18:07:55 +01:00
Adrien Delorme 6e6490d688 WIP 2020-03-13 18:04:48 +01:00
Adrien Delorme 260dc59500 use the hcl2template.KVFilter where we can 2020-03-13 17:17:46 +01:00
Adrien Delorme b4efd13a4d aws: use the empty func when possible 2020-03-13 17:17:24 +01:00
r_takaishi f50ff1d270 make generate 2020-03-13 11:29:42 +09:00
Wilken Rivera 7b705545d9
docs: Various doc clean-ups to fix code block formatting and syntax highlighting (#8868) 2020-03-12 15:05:08 +01:00
Megan Marsh 4133acbdf3 update spot price docs 2020-03-09 08:46:30 -07:00
Wilken Rivera e1a46ec293
Fix gosimple S1025 linting errors (#8838)
Remove unneeded use of fmt.Sprintf for variables that are already strings.
2020-03-04 15:31:30 -05:00
Megan Marsh dde74232f2
Clearly document all template-engine-enabled options (#8770) 2020-02-20 11:05:27 +01:00
Wilken Rivera 9ec8b67392
Add golangci-lint to project (#8686)
* Add golangci-lint as linting tool

* Disable failing staticchecks to start; GitHub issue to handle coming soon

* Run `goimports -w` to repair all source files that have improperly
formatted imports

* makefile: Add ci-lint target to run on travis

This change adds a new make target for running golangci-lint on newly
added Go files only. This target is expected to run during Packer ci builds.

* .github/contributing: Add code linting instructions

* travis: Update job configuration to run parallel builds
2020-02-14 11:42:29 -05:00
Adrien Delorme 7d5f0c11af add max_retries option to aws builders 2020-02-07 16:36:14 +01:00
Wilken Rivera a1d9ba0e32
Merge pull request #8699 from fly1028/fix-instance-running-timeout
Instance Running waiter not aware of global waiter settings
2020-02-06 17:18:59 -05:00
Patrick Ng e5e5fd1198 Instance Running waiter not aware of global waiter settings 2020-02-05 15:09:09 -08:00
Sylvia Moss 08b0bd1d2c
Fix HCL2 code generation for slices within another slice (#8669) 2020-02-03 17:03:28 +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
nywilken d2a9e6b32e Format code with `gofmt -s -w` 2020-01-28 16:52:50 -05:00
Wilken Rivera 111bab86d9
Merge pull request #8622 from datalot/pre-validate-with-filters
Allow aws builder pre validation to pass when subnet filters are present
2020-01-22 15:00:44 -05:00
Sylvia Moss 0b7251a4bb
Share .Device and .MountPath between builders, provisioners and post-processors (#8621) 2020-01-20 16:29:38 +01:00
Rich Cavanaugh 4fb0de5256 allow validation to pass when subnet filters are present 2020-01-17 11:57:42 -05:00
Sylvia Moss 39c25b2c66
Add retry mechanism to amazon DeleteSnapshot (#8614) 2020-01-16 14:38:46 +01:00
Sylvia Moss 0677b02e18
Share SourceImageName with provisioners and manifest post-processor (#8603) 2020-01-16 12:04:03 +01:00
Sylvia Moss 0e177915f8
Add retry mechanism to DeregisterImage from awsec2 (#8598) 2020-01-15 10:28:14 +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
Megan Marsh b7ee807cf1
Merge pull request #8571 from hashicorp/fix_8565
fix ssh interface docs for amazon builders
2020-01-06 14:34:40 -08:00
Megan Marsh 6655f93b59 fix typo and regenerate code 2020-01-06 14:12:29 -08:00
Megan Marsh 76251e5fd2 fix ssh interface docs for amazon builders 2020-01-06 12:01:30 -08:00
Trevor Pounds 47e48ebc24 Add source AMI owner ID/name to build template. 2019-12-30 14:04:49 -05: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
Megan Marsh 84063d2132 implement ID and Type values in the provisioner template info sharing 2019-12-13 11:57:01 -08:00
Megan Marsh 6f418d0e54 get data sharing to a working state with the powershell provisioner 2019-12-11 15:43:38 -08:00
Megan Marsh 601007e3e2 pas data into provisioners well 2019-12-11 15:43:38 -08:00
Oded Priva 5e81c6f44e added the option to skip IAM instance profile validation (#8457) 2019-12-10 09:17:38 +01:00
deisenzimmer 2b3935778e amazon-ebssurrogate plugin: StepSnapshotVolumes: Added mutex to synchronise map access across threads. (#8432) 2019-12-04 15:13:07 +01:00
Megan Marsh de9f391a1c
Merge pull request #8430 from hashicorp/fix_8359
Fix request retry mechanism  to launch aws instance
2019-12-03 16:03:03 -08:00
Megan Marsh fcda07ee6a clarify docs by removing unclear string (#8439)
the docs generator from code PR #7724  mis scrapped it
2019-12-03 10:07:46 +01:00
Moss 28c720bd3a Organize imports 2019-12-02 10:17:36 +01:00
Moss 250643d54b Remove 5 sec sleep after adding iam instance profile 2019-12-02 10:13:26 +01:00
Moss 4516978555 Fix request retry mechanism to run aws instance 2019-11-29 18:11:10 +01:00
Jon Allie c31bbcf4cf builder/amazon: AmiFilterOptions.GetOwners: avoid taking the address of a loop iterator var (#8417)
GetOwners() always returned a slice of pointers to the last value. Because slice ranging reuses the same local variable.
2019-11-27 12:28:07 +01:00
Mike Dziedziela 7c3e032fb7 amazon docs: update block-device-configuration docs (#8395)
So that it works for all builders as some use it with the following field names: launch_block_device_mappings, ami_block_device_mappings or ebs_volumes. the refactored docs weird being to specific.
2019-11-25 11:58:30 +01:00
Megan Marsh 59e6e1d4d5
Merge pull request #8393 from hashicorp/fix_8362
Add no_ephemeral template option to nuke ephemeral drives from launch mappings
2019-11-21 16:08:50 -08:00
Megan Marsh 818d9bb087 send to step run spot instance 2019-11-21 13:21:56 -08:00
Megan Marsh 67c3373107 enable no_ephemeral for spot devices, clean up ranging behavior, update docs 2019-11-21 12:46:31 -08:00
Anthony Dong 2e989088e5 amazon-ebssurrogate: allow enabling ena/sr-iov on spot instances 2019-11-21 11:13:32 +01:00
Megan Marsh 08e97ba4d8 generate code for no_ephemeral option 2019-11-20 13:49:04 -08:00
Megan Marsh 0e2bdc8be6 forcibly prevent ephemeral drives from being created in the amazon-ebs builder, when no_ephemeral is set 2019-11-20 13:42:14 -08:00
DanHam b40e5d90b6
builder/amazon/common/step_pre_validate: Return DescribeVpcs errors 2019-11-19 20:18:53 +00:00
nywilken afb880c134 test/builder/amazon/common/step_pre_validate: Update DescribeVpcs mock
* Update condition to check for a empty VpcId
2019-11-19 14:48:07 -05:00
DanHam 074be9942d
Only validate the user has provided a subnet_id when vpc_id has been set 2019-11-19 14:09:58 +00:00
nywilken f9f4726eff builder/amazon/step_pre_validate: Add check for non-default VPCs
Subnet information is only really needed when the specified `vpc_id` is
not the default VPC for the region where the builder is being executed.
This change uses the AWS API to determine if the VPC provided is a
non-default VPC and only validates the existence of a `subnet_id` if a
user has provided a non-default `vpc_id`.

Tests after change
```
> make test TEST=./builder/amazon/... TESTARGS='-count=1 -v -run=TestStepPreValidate_checkVpc'
...

=== RUN   TestStepPreValidate_checkVpc
=== RUN   TestStepPreValidate_checkVpc/DefaultVpc
=== RUN   TestStepPreValidate_checkVpc/NonDefaultVpcNoSubnet
=== RUN   TestStepPreValidate_checkVpc/NonDefaultVpcWithSubnet
=== RUN   TestStepPreValidate_checkVpc/SubnetWithNoVpc
=== RUN   TestStepPreValidate_checkVpc/NoVpcInformation
--- PASS: TestStepPreValidate_checkVpc (0.00s)
    --- PASS: TestStepPreValidate_checkVpc/DefaultVpc (0.00s)
    --- PASS: TestStepPreValidate_checkVpc/NonDefaultVpcNoSubnet (0.00s)
    --- PASS: TestStepPreValidate_checkVpc/NonDefaultVpcWithSubnet (0.00s)
    --- PASS: TestStepPreValidate_checkVpc/SubnetWithNoVpc (0.00s)
    --- PASS: TestStepPreValidate_checkVpc/NoVpcInformation (0.00s)
PASS

...
```
2019-11-18 16:44:09 -05:00
Megan Marsh dfa134cd98 ditch else statement for improved clarity 2019-11-18 10:11:59 +01:00
Megan Marsh ce8bca349f Update builder/amazon/ebs/step_create_ami.go
Co-Authored-By: Adrien Delorme <azr@users.noreply.github.com>
2019-11-18 10:11:59 +01:00
Megan Marsh a35ac0127e fix bug in step_region_copy 2019-11-18 10:11:59 +01:00
nywilken 488e539f63 builder/amazon: Add helper function for checking against AWSError
Replace all straight forward occurrences of `if err, ok := err.(awserr.Error)` with the `isAWSErr` helper function
2019-11-12 15:27:47 -05:00
Megan Marsh 6e2456d028 make error messaging around ResourceNotReady better, update docs with other possible issues (#8349) 2019-11-08 11:15:24 +01:00
cove 2898d66812
retry runinstances aws api that wasn't retried and could fail 2019-11-06 14:06:35 -08:00
Megan Marsh 6c704f7046 Revert "fix template imports"
This reverts commit 0e70e0e5a4.
2019-11-04 14:29:00 -08:00
Megan Marsh 517834d528 Revert "Revert "remove clean_ami_name and clean_image_name; complete the deprecation for these functions in favor of clean_resource_name""
This reverts commit 44f91c9afc.
2019-11-04 14:28:40 -08:00
Megan Marsh fcb65ee422
Merge pull request #8307 from hashicorp/fix_8116
delete amazon import post-processor intermediary snapshots
2019-11-01 14:55:22 -07:00
Megan Marsh e9e4c102e5 delete amazon import post-processor intermediary snapshots 2019-11-01 14:17:44 -07:00
Adrien Delorme 1b7ef252d2
Merge pull request #8303 from alrs/amazon-builder-cleanup
Cleanup builder/amazon/common
2019-11-01 11:06:06 +01:00
Lars Lehtonen d072079899
builder/amazon/common: remove dead test type and function mockEC2Conn_Modify_EBS.ModifyInstanceAttribute() 2019-10-31 12:38:32 -07:00
Lars Lehtonen 953be1603b
builder/amazon/common: remove dead test type and function mockEC2ConnSpot.DescribeSpotPriceHistory() 2019-10-31 12:34:11 -07:00
Lars Lehtonen 7a09f9c678
builder/amazon/common: remove dead test function fakeModifyEBSBackedInstanceState() 2019-10-31 12:22:10 -07:00
Lars Lehtonen 0a13b620d6
builder/amazon/common: remove dead test function StepModifyEBSBackedInstance_EnableAMIENASupport() 2019-10-31 12:19:28 -07:00
Lars Lehtonen c74df8b652
builder/amazon/common: remove dead test function getMockConnSpot() 2019-10-31 12:15:53 -07:00
Lars Lehtonen e5e2bfa83f
builder/amazon/common: remove nil check on slice, len() on nil slices is zero 2019-10-31 12:09:32 -07:00
Adrien Delorme 819329228a Change back to make sure all durations are a time.Duration
It is simply the best/simplest solution and trying to prevent users from passing and integer here would be like opening a can of worms. Because:

* we cannot make mapstructure validate our duration string ( with an UnmarshalJSON func etc.)
* we cannot make mapstructure spit a string instead of a duration and packer will decode-encode-decode config.
* the hcl2 generated code asks for a string, so this will be enforced by default.
2019-10-31 16:12:07 +01:00
Adrien Delorme bf3d9841c6 Force durations to be passed a strings
Before this commit it was possible to set a duration using an integer or a float. Go's time.Duration is an int64 internally an mapstructure will take advantage of this and load the number as a int64 but `1` means one ns which is unexpected/confusing. To avoid confusion and enforce readability this forces users to pass a string with a unit for a duration; ex "56s".
2019-10-31 11:47:19 +01:00
Megan Marsh 6191b9c8c6
Merge pull request #8288 from hashicorp/fix_8271
add some extra layers of validation to make sure that people don't tr…
2019-10-30 10:41:52 -07:00
Megan Marsh d084cd1895 Update builder/amazon/common/ami_config.go 2019-10-30 09:41:23 -07:00
Megan Marsh e9f02e44cb add test to catch this case 2019-10-29 11:28:56 -07:00
Megan Marsh 7cf47fc463 add some extra layers of validation to make sure that people don't trip over magical encrypt_boot settings later in the build 2019-10-29 11:26:22 -07:00
Megan Marsh e2283445f2 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
Megan Marsh a783a09ea3
Merge pull request #8269 from paulmey/paulmey/generalize-chroot
[amazon/chroot] Move common/generic chroot builder steps to common directory
2019-10-24 14:32:01 -07:00
Megan Marsh 7928b5b045 fix transcription error from when we moved to generated docs 2019-10-24 10:19:03 -07:00
Paul Meyer 3be7d81ce2 Move common steps together 2019-10-24 04:21:46 +00:00
Paul Meyer e6dfe301ac Move CommandWrapper & ShellCommand to common 2019-10-24 04:06:29 +00:00
Megan Marsh b9245a402d add structure to its own struct to make generated code stop complaining 2019-10-23 10:46:42 -07:00
Megan Marsh 5614f307fb regerate code
generate flat FlatPolicyDocument
add PolicyDocument to generate command
2019-10-23 10:46:07 -07:00
Megan Marsh d15f43e4eb
Merge pull request #8232 from hashicorp/artifact-tree
HCL2 configs - part one
2019-10-22 11:54:34 -07:00
Bernard Baltrusaitis ec1d70dc44 adding required changes 2019-10-22 21:40:18 +11:00
Bernard Baltrusaitis 65d1447b64 adding formatting 2019-10-19 21:33:58 +11:00
Bernard Baltrusaitis 6e2146324f Merge branch 'master' of github.com:b-b3rn4rd/packer 2019-10-19 20:56:49 +11:00
Bernard Baltrusaitis 8b83cca064 adding temporary instance profile document policy 2019-10-19 20:56:18 +11:00
Adrien Delorme cf1555bf17 Merge remote-tracking branch 'origin/master' into artifact-tree 2019-10-16 10:22:56 +02:00
Paul Meyer 977ca5be1c Add StepCopyFiles and StepChrootProvision 2019-10-15 21:13:37 +00:00
Paul Meyer 9a3e6661b1 Add StepMountExtra 2019-10-15 21:13:37 +00:00
Paul Meyer addbdedea9 Add StepPostMountCommands 2019-10-15 21:13:37 +00:00
Paul Meyer 4d750ddefa Reuse amazon/chroot/step_pre_mount_commands.go 2019-10-15 21:13:37 +00:00