Commit Graph

265 Commits

Author SHA1 Message Date
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 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
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
Lars Lehtonen 3571c585bb builder/googlecompute: fix dropped error (#8385) 2019-11-19 11:41:39 +01: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
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
Adrien Delorme 078ba7c8c3 commit old code generation tool
for history
2019-10-15 12:56:42 +02:00
Adrien Delorme 17c069baa5 builder.google:
* make CustomerEncryptionKey our own type so that it can be hcl2 generated
* make Account setting unexported so that it doesn't temper with HCL2 generation ( the field is set a bit later after processing )
2019-10-15 12:56:41 +02: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
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
Lars Lehtonen ad860bf1a8
builder: remove deprecated context usage 2019-09-30 11:33:53 -07:00
Megan Marsh 3c14c50aba Allow user to real oauth token from properly configured Vault instance 2019-09-23 13:26:03 -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
Megan Marsh 35357616e0
Merge pull request #8112 from milescrabill/packer-googlecompute-validate-imagename
googlecompute: fail fast when image name is invalid, replace unusable characters w/ -'s
2019-09-17 10:00:33 -07:00
Miles Crabill 2bff60bac8
address review feedback 2019-09-16 13:50:43 -07:00
Miles Crabill 328baced05
add some test cases for image names 2019-09-16 10:18:22 -07:00
Miles Crabill c11a444f77
googlecompute: fail fast when image name is invalid, replace unusable characters w/ -'s 2019-09-16 10:10:41 -07:00
Megan Marsh a6e263adb6 don't fall for nil pointer dereference in account file 2019-09-13 16:37:19 -07:00
Adrien Delorme 2db109d55b Merge branch 'master' into scrape_doc_to_builder_struct_config 2019-08-23 17:37:53 +02:00
Megan Marsh fcef7e2d85 this timeout regularly flakes on Travis, I suspect because the instances running the tests are brutally underpowered. Increase the fudge factor. 2019-08-21 16:36:42 -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
Mason, Elliot ee484f2dd9 Updated public gcp cloud images 2019-07-31 11:38:35 -05:00
Megan Marsh 7c93a5c51e code changed recently so that sometimes the conf is nil. 2019-07-29 13:19:43 -07:00
Megan Marsh a87ce366b3
Merge pull request #7835 from hashicorp/google_oauth
replace some bespoke google auth code with code from golang's oauth2 …
2019-07-08 09:48:27 -07:00
Megan Marsh 617fd18255 supply complete dummy data for googlecompute tests 2019-07-03 15:58:08 -07:00
Megan Marsh 0dfb3cc56f replace some bespoke google auth code with code from golang's oauth2 library 2019-07-03 14:27:33 -07:00
Megan Marsh c03c3f4410 replace duplicate commHost functions with a single communicator helper that checks for ssh_host and does a statebag lookup for a given key 2019-07-03 13:30:29 -07:00
Megan Marsh eb8c74bf85 allow ssh_host config option to override host logic for all builders 2019-07-02 13:56:28 -07:00
Megan Marsh ad8a88e366 allow ssh_host to override the host ip gathered from the instance for GCP builder 2019-07-02 13:01:41 -07:00
Adrien Delorme a3e3c313a9 docs: use partials in googlecompute after master merge 2019-06-12 15:18:39 +02:00
Adrien Delorme 6e3dc1aa9a Merge remote-tracking branch 'origin/master' into scrape_doc_to_builder_struct_config 2019-06-12 14:28:11 +02:00
Pratyush singhal 92af5847a7 refactor: replace *packer.MultiError from type signature of createInstanceMetadata with generic error interface
Signed-off-by: Pratyush singhal <psinghal20@gmail.com>
2019-06-11 21:01:26 +05:30
Pratyush singhal 6ce6bd8ad3 refactor: add multiError in createInstanceMetadata method to capture multiple errors
Signed-off-by: Pratyush singhal <psinghal20@gmail.com>
2019-06-11 20:09:14 +05:30
Pratyush singhal 4a369b4ef1 chore: add test for MetadataFiles option
Signed-off-by: Pratyush singhal <psinghal20@gmail.com>
2019-06-11 17:45:30 +05:30
Pratyush singhal 99a3e9cf0a chore: update tests for createInstaceMetadata
Signed-off-by: Pratyush singhal <psinghal20@gmail.com>
2019-06-11 16:47:16 +05:30
Pratyush singhal 529dff0abb refactor: add error handling in createInstanceMetadata method
Signed-off-by: Pratyush singhal <psinghal20@gmail.com>
2019-06-11 16:36:16 +05:30
Adrien Delorme 4399684372 make fmt autogenerated docs 2019-06-06 16:29:25 +02:00
Pratyush singhal 1e1af35341 refactor: replace userdata_files with generic metadata_files map
Signed-off-by: Pratyush singhal <psinghal20@gmail.com>
2019-06-06 16:14:57 +05:30
Pratyush singhal 3845186c4c feat: add feature to import user-data from a file
Signed-off-by: Pratyush singhal <psinghal20@gmail.com>
2019-06-06 11:28:59 +05:30
Adrien Delorme e6cbb013ba add // go:generate struct-markdown to all previously edited files 2019-06-05 16:42:18 +02:00