Commit Graph

38 Commits

Author SHA1 Message Date
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 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 82367a88f8 reorganize placeholder data call to live with provisioner implementation; force users to use the generated function, therefore forcing validation, for all variables except winrmpassword, by doing a simple string check against the placeholder data. 2019-12-14 03:32:38 -08:00
Megan Marsh 39fd462b56 change all provision func signatures to use map[string]interface{} 2019-12-12 15:38:32 -08:00
Megan Marsh 7616fbcf3f skip shell local for now 2019-12-11 15:43:38 -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 a8ffa60b46 remove the already-included packer config from top level struct 2019-11-25 11:24:00 -08:00
Megan Marsh 7d4353864f use shell struct in shell-local provisioner and post-processor. 2019-11-21 16:47:29 -08:00
Adrien Delorme 078ba7c8c3 commit old code generation tool
for history
2019-10-15 12:56:42 +02:00
Adrien Delorme 7be94f41a6 common.shell-local: unexport Ctx field
so that it doesn't temper with hcl2 generation
2019-10-15 12:56:42 +02:00
Christian Muehlhaeuser 216afbaa8b
Fixed various typos
Just a bunch of nit-picky typo fixes.
2019-07-25 06:49:51 +02:00
Megan Marsh a2c3de9396 remove outdated logline 2019-01-09 11:16:48 -08:00
Megan Marsh f9ceaee4f1 fix variable casing convention 2018-10-22 14:34:50 -07:00
Joel Vasallo 5d17b3de84 fix: config validator output 2018-10-19 19:52:11 -05:00
Joel Vasallo 23ad90f2c4 fix: condensed and simplified os check logic and added validate output 2018-10-19 13:48:30 -05:00
Joel Vasallo d408c9e69c fix: moved os check to entry of func 2018-10-19 01:38:51 -05:00
Joel Vasallo 0912adea34 fix: converted onlyon param to only_on and added validation step 2018-10-19 00:51:25 -05:00
Joel Vasallo 25c0b98363 feat: ability to specify runtime OSs where shell-local should run 2018-10-18 15:10:04 -05:00
Megan Marsh a0edaf6c46 Going to revert this change for now, becuase of potential issues that arise from calling Prepare() twice
Revert "use statebag instead of SetSharedState for winRM password"

This reverts commit b35acbd879.
2018-09-10 16:48:42 -07:00
Megan Marsh 8309f36176
Merge pull request #6626 from hashicorp/fix_6620
make reasonable tempfile default on windows
2018-08-27 09:43:04 -07:00
Megan Marsh b35acbd879 use statebag instead of SetSharedState for winRM password 2018-08-24 13:51:16 -07:00
Megan Marsh f5355a0693 make reasonable tempfile default on windows 2018-08-24 09:44:50 -07:00
Megan Marsh 4a7953f93a found a config validation bug where packer crashes instead of throwing a validation error if a windows-style path is provided to a provisioner on linux 2018-06-22 13:49:39 -07:00
Megan Marsh 846f94c964 implement template variable for accessing WinRM password in either environemnt variables or directly in execute_command or inline commands. 2018-05-23 16:00:43 -07:00
Megan Marsh 969201a2d4 handle minor shell-local PR suggestions and corrections 2018-05-21 14:56:44 -07:00
Megan Marsh 1bea658e16 fix command and inline calls on windows 2018-05-07 15:10:10 -07:00
Megan Marsh fabd1a6517 windows cmd env vars 2018-05-07 15:10:10 -07:00
Megan Marsh dd183f22d9 update docs and add warnings around WSL limitations 2018-05-07 15:10:10 -07:00
Megan Marsh 51bcc7aa13 add new feature for telling shell-local whether to use linux pathing on windows; update docs with some examples. 2018-05-07 15:10:10 -07:00
Megan Marsh e983a94a88 fix default windows bash call for shell-local provisioner and move chmod command from the execute_command array into the portion of code where we actually generate inline scripts, sparing users the need to think about this modification which Packer should really handle on its own
make bash call work on windows
2018-05-07 15:10:10 -07:00
Megan Marsh 854d6fb141 add tests making sure post-processor has backwards compatability 2018-05-07 15:10:10 -07:00
Megan Marsh f799003b66 tighten up shell-local config validation 2018-05-07 15:10:10 -07:00
Megan Marsh 479d36734d consolidate shell-local defaulting of InlineShebang and ExecuteCommand to the config validation 2018-05-07 15:10:10 -07:00
Megan Marsh d304234725 fix tests 2018-05-07 15:10:10 -07:00
Megan Marsh c7c66bedcb set inline to an empty array, rather than nil 2018-05-07 15:10:09 -07:00
Megan Marsh 926327beba deduplicate all validation and interpolation of the shell-local config, sharing options between shell-local provisioner and post-processor. Maintain backwards compatibility with shell-local provisioner. 2018-05-07 15:10:09 -07:00