Commit Graph

1201 Commits

Author SHA1 Message Date
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
Adrien Delorme 078ba7c8c3 commit old code generation tool
for history
2019-10-15 12:56:42 +02:00
Adrien Delorme 221e72e9c3 builder.amazon.common: remove pointer (*) from []*string and map[*string]*string types
because they make hcl2/cty decoding panic
2019-10-15 12:56:41 +02:00
Adrien Delorme 8b8c2fc138 builder.amazon.chroot: remove specific BlockDevice definition
because the common one already has a KmsKeyId field
2019-10-15 12:56:41 +02:00
Megan Marsh f05fd3969f
Merge pull request #8212 from hashicorp/fix_8204
Fix 8204
2019-10-14 14:40:17 -07:00
Megan Marsh 2e20facc8b fix tests 2019-10-14 14:13:21 -07:00
Megan Marsh 0e70e0e5a4 fix template imports 2019-10-14 13:22:06 -07:00
Megan Marsh 44f91c9afc Revert "remove clean_ami_name and clean_image_name; complete the deprecation for these functions in favor of clean_resource_name"
This reverts commit 0026792d2f.
2019-10-14 13:08:15 -07:00
Megan Marsh 4bc381183d make aws instsance builder work with recent changes for volume copy 2019-10-09 16:59:51 -07:00
Megan Marsh e283023d9b make sure step_register_ami in chroot builder respects encryption and ami skip build retion values once the copy happens 2019-10-09 16:52:41 -07:00
Megan Marsh 469af8e592 ebssurrogate builds didn't keep up with recent optimizations to region encryption in the ebs builder, and that was causing bugs with the common ami region copy step 2019-10-09 16:02:37 -07:00
Adrien Delorme d4600a7716 fix go imports 2019-10-04 11:19:45 +02:00
Megan Marsh 0026792d2f remove clean_ami_name and clean_image_name; complete the deprecation for these functions in favor of clean_resource_name 2019-10-03 15:49:01 -07:00
Megan Marsh e16fb19bfc don't abort on a single error if another availability zone was able to create the instance 2019-10-02 14:17:00 -07:00
Megan Marsh eccf0fb51d update docs 2019-09-27 09:51:18 -07:00
Megan Marsh e047b97bf7
Merge pull request #8162 from hashicorp/fix_8154
make sure amazon builders respect ssh_host option
2019-09-27 09:34:49 -07:00
Megan Marsh ac6e7a4800 updates tests to validate that ssh_host value supplied in the template overrides all else 2019-09-27 09:19:23 -07:00
Adrien Delorme 941dc394f0 Update step_run_spot_instance.go 2019-09-27 13:04:52 +02:00
Adrien Delorme d049284120
Update builder/amazon/common/step_run_spot_instance.go
remove unused code that might induce errors
2019-09-27 13:00:53 +02:00
Adrien Delorme 07e97e26de
step_run_source_instance.go: make sure we use the right ShouldRetry error 2019-09-27 12:57:55 +02:00
Megan Marsh c722009159 we only need one describeInstances call, not 3, and it should be wrapped in a retry 2019-09-26 15:47:01 -07:00
Megan Marsh e47059aaca put retry around describeinstances call in amazon 2019-09-26 14:49:28 -07:00
Megan Marsh 31bb1e818f fix tests 2019-09-26 13:02:11 -07:00
Megan Marsh 0cbd3ff0f3 make sure amazon builders respect ssh_host option 2019-09-26 12:30:04 -07:00
Megan Marsh 72d393c95a update docs to show a use case for block device mappings 2019-09-25 16:48:04 -07:00
Adrien Delorme 4fb05e5bc4 fix test 2019-09-20 15:28:43 +02:00
Adrien Delorme 792f61a4ad fmt 2019-09-20 15:18:48 +02:00
Adrien Delorme 849de792da re-apply doc changes of master 2019-09-20 15:04:01 +02: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 4d4bd38afa
Merge pull request #8087 from hashicorp/fix_8048
add retry wrapper to query so it handles rate limiting
2019-09-16 10:25:12 +02:00
Megan Marsh 9503802814 adding ctx makes the cancel channel redundant 2019-09-13 14:32:13 -07:00