Commit Graph

41 Commits

Author SHA1 Message Date
Adrien Delorme 40947c2bf6
HCL2: generate hcl tags with go-cty tags too (#9306)
This will allow to generate the config files:

```go
package main

import (
	"fmt"

	"github.com/hashicorp/hcl/v2/gohcl"
	"github.com/hashicorp/hcl/v2/hclwrite"
	"github.com/hashicorp/packer/builder/alicloud/ecs"
)

func main() {
	name := "name"
	app := ecs.FlatConfig{
		AlicloudImageName: &name,
		ECSSystemDiskMapping: &ecs.FlatAlicloudDiskDevice{
			DiskName: &name,
		},
	}

	f := hclwrite.NewEmptyFile()
	block := gohcl.EncodeAsBlock(&app, `source "something" "something"`)
	f.Body().AppendBlock(block)
	fmt.Printf("%s", f.Bytes())
}

```

Will output:

```
source "something" "something" {
  packer_user_variables      = null
  packer_sensitive_variables = null
  image_name                 = "name"
  image_share_account        = null
  image_unshare_account      = null
  image_copy_regions         = null
  image_copy_names           = null
  tags                       = null
  tag                        = null
  system_disk_mapping        = { disk_category = null, disk_delete_with_instance = null, disk_descri
ption = null, disk_device = null, disk_encrypted = null, disk_name = "name", disk_size = null, disk_
snapshot_id = null }
  image_disk_mappings        = null
  ssh_remote_tunnels         = null
  ssh_local_tunnels          = null
  ssh_public_key             = null
  ssh_private_key            = null
}
```

This is a good first step for #9015 and #9282 

fix #9304
2020-05-28 11:19:00 +02:00
Megan Marsh b982d987a7 Add Artifice postprocessor ID to valid artifacts for postprocessors that perform artifact type validation 2020-05-15 13:13:43 -07:00
Joshua Foster 00d0632f4a add vsphere builder's artifact to vsphere-template's supported types 2020-05-01 11:17:31 -04:00
Adrien Delorme 840e67f775
HCL2: when we see a map generate an attribute spec instead of a block spec (#9035)
* mapstructure-to-hcl2: when we see a map generate an attribute spec and not a block spec

this will alow to do

tags = {
 key = "value"
}

instead of

tags {
  key = "value"
}

This will also enable using variables directly for those tags

* generate code

* update tests
2020-04-14 16:05:13 +02:00
Tommy McNeely e469140678 workaround for mapstructure-to-hcl2 and booleans 2020-01-07 16:58:40 -07:00
Tommy McNeely 7f7b54ea31 Use vm.MarkAsTemplate, optionally reregister 2020-01-06 15:34:50 -07: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
Adrien Delorme 078ba7c8c3 commit old code generation tool
for history
2019-10-15 12:56:42 +02:00
Adrien Delorme a81abd297b Merge remote-tracking branch 'origin/master' into context_provisioner 2019-04-08 20:09:01 +02: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 e65115a7a0 contextualize post-processor 2019-04-03 15:55:55 +02:00
Megan Marsh 12fc1fa751 default_keep_input_artifact 2019-04-02 16:51:58 -07:00
Julio Tain Sueiras 51053efad2 Docs changes & Removed memory and quiesce options from vsphere-template 2018-11-28 11:25:01 -05:00
Julio Tain Sueiras 7f7fee3e2b Added Creation of Snapshot to vSphere Template 2018-11-07 23:59:12 -05:00
Megan Marsh 290f4a7c4c cleanup to make it actually build after that monstrous rebase 2018-10-25 14:17:35 -07:00
Megan Marsh 8f1eb5a61b fix crash caused by invalid datacenter url 2018-07-23 16:12:21 -07:00
Megan Marsh 2cecd73aad add clarity to error message in vsphere-template postprocessor 2018-03-20 11:32:01 -07:00
Matthew Hooker 975b50005b
Merge branch 'master' into local-vsphere-template 2018-02-09 11:18:13 -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
Megan Marsh 487ceac784 fix Vet error. 2017-11-13 11:45:31 -08:00
bugbuilder b754b71519 return vsphere artifact to can build template 2017-11-10 22:57:39 -03:00
bugbuilder da54bf8e73 using only remoteFolder as parameter 2017-11-10 14:03:15 -03:00
bugbuilder 23f4d187e2 validating keep_registered and fixing skip_export issues 2017-11-08 15:57:34 -03:00
bugbuilder 5ccba2caaa using virtual disk device to create datastorePath 2017-11-06 02:57:41 -03:00
bugbuilder 75a4ca7351 adding artifact testing and using builder id 2017-09-23 15:43:57 -03:00
bugbuilder f1773a57f8 using vmx extension as default 2017-09-23 03:01:35 -03:00
bugbuilder 99dd19ccfd Adding correct reference to VM remote path 2017-09-22 23:37:27 -03:00
bugbuilder 24a8fddf03 showing artifact info in packer UI 2017-09-22 13:54:11 -03:00
bugbuilder 644ac5b367 enable vsphere-template to work with local builders 2017-09-20 22:50:37 -03:00
bugbuilder 6590dfaf82 using runner with pause func 2017-09-01 00:33:40 -03:00
bugbuilder f09a9c4653 using artifact ID 2017-08-30 18:19:54 -03:00
bugbuilder fc4bee4598 VMware typo 2017-08-24 22:46:35 -03:00
bugbuilder 81272d1427 Updated mark as template to be able to use --force 2017-08-14 23:00:19 -03:00
bugbuilder 5e1d241db4 Close govmomi session 2017-07-31 10:30:13 -04:00
bugbuilder 786d3c0a9d updated documentation, vm_name mandatory and cleaning code 2017-07-31 00:26:58 -04:00
bugbuilder 08c6139da4 Create folder using the invotory path 2017-07-27 16:55:47 -04:00
bugbuilder fb52c42b3d Only add the folder when the error is NotFoundError 2017-07-25 23:14:59 -04:00
bugbuilder 7274bbb63d commends, documentation and var names updates 2017-07-19 00:44:18 -04:00
bugbuilder fa10616f57 Changes requested applied 2017-07-18 23:10:05 -04:00
bugbuilder 3cc9f204ac Moving vsphere-tpl to vsphere-template, fixed root folder creation and updated docs 2017-07-10 20:52:48 -04:00