Commit Graph

362 Commits

Author SHA1 Message Date
Adrien Delorme 9a74ce60d5 Update config.go 2020-03-16 15:12:13 +01:00
Adrien Delorme 45695608b5 WIP 2020-03-16 12:21:46 +01:00
Adrien Delorme dab689ce2e WIP 2020-03-16 12:19:34 +01:00
Adrien Delorme 6e6490d688 WIP 2020-03-13 18:04:48 +01:00
Megan Marsh aeedc9af7a
Merge pull request #8879 from mbrancato/specify_keyvault_sku
Add support for configurable KeyVault SKU
2020-03-12 13:47:51 -07: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
Mike Brancato ebb161ae41 Fix config documentation 2020-03-11 21:43:37 -04:00
Mike Brancato 892622987c Add KeyVault parameter and fix whitespace 2020-03-11 21:13:10 -04:00
Mike Brancato 0f09638f7a Add HCL2 spec for KeyVault SKU 2020-03-11 20:48:34 -04:00
Mike Brancato 3c6b248bd5 Fix formatting 2020-03-11 20:45:44 -04:00
Mike Brancato 926e3ac2e4 Add support for configurable KeyVault SKU 2020-03-11 20:33:57 -04:00
Wilken Rivera 66ad6f3483
builders: Fix gosimple S1007 linting issue (#8871)
Results before change
```
⇶  golangci-lint run ./... --disable-all --enable=gosimple | grep 1007
builder/alicloud/ecs/image_config.go:208:9: S1007: should use raw string
post-processor/vsphere-template/step_mark_as_template.go:130:8: S1007: shape twice (gosimple)
builder/azure/arm/config.go:58:27: S1007: should use raw string (`...`)
builder/azure/arm/config.go:59:27: S1007: should use raw string (`...`)
builder/qemu/driver.go:192:15: S1007: should use raw string (`...`)
```

Results after change
```
⇶  golangci-lint run ./... --disable-all --enable=gosimple | grep 1007
```
2020-03-11 10:29:22 +01:00
Sylvia Moss ce674ff272
Add exclude mapstructure tag to exclude from hcl2spec struct (#8785) 2020-03-03 17:13:39 +01:00
Wilken Rivera c99dc56544 Update Azure ARM documentation
* Change generated documentation to indicate what image selection
options are required, and when.

* Refactor the structure of the documentation to highlight required
options for different types of builds
2020-02-10 21:14:11 -05:00
Megan Marsh 2181f10e79 fix statebag setup; simplify conditional 2020-02-06 16:54:07 -08:00
Megan Marsh 7dd1fa44db regenerate code 2020-02-06 16:41:28 -08:00
Megan Marsh 9643ad35f1 add tests 2020-02-06 16:41:28 -08:00
Megan Marsh 6d6b94d515 Add ability to use custom keyvault into azure builds 2020-02-06 16:41:28 -08:00
Wilken Rivera 561f02cc2f
builder/azure-arm: Update logic for setting subscriptionID (#8685)
* builder/azure-arm: Update logic for setting subscriptionID

Previously, when using managed identities, the Azure builder would set the SubscriptionID in the Prepare method. But would not update it after getting the updated SubscriptionID from the metadata server. This change updates the Run method to ensure a valid subscriptionID is saved to the statebag before continuing with an image build.

Co-authored-by: Paul Meyer <paul.meyer@outlook.com>
2020-02-04 10:54:58 -05:00
Sylvia Moss 08b0bd1d2c
Fix HCL2 code generation for slices within another slice (#8669) 2020-02-03 17:03:28 +01:00
nywilken 654cc4c4d5 builder/azure-arm: Set WinRMPassword on the communicator config
Build results before change
```
azure-arm: output will be in this color.

==> azure-arm: Running builder ...
azure-arm:
==> azure-arm: Provisioning with Powershell...
==> azure-arm: Provisioning with powershell script:
/tmp/powershell-provisioner922851060
==> azure-arm: Exception calling "RegisterTaskDefinition" with "7" argument(s): "(38,4):Task:"
==> azure-arm: At C:\Windows\Temp\packer-elevated-shell-5e320d29-bdbd-b619-9e64-0c8a301b9d1d.p
==> azure-arm: s1:60 char:1 ==> azure-arm: + $f.RegisterTaskDefinition($name, $t, 6,
"packer", $password, $logon_type,
==> azure-arm: $null) ...
==> azure-arm: +
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
==> azure-arm: ~~~
==> azure-arm:     + CategoryInfo          : NotSpecified:
(:) [], MethodInvocationException
==> azure-arm:     + FullyQualifiedErrorId :
ComMethodTargetInvocation
==> azure-arm:
==> azure-arm: Exception calling "GetTask" with "1"
argument(s): "The system cannot find the
==> azure-arm: file specified. (Exception from HRESULT:
0x80070002)"
==> azure-arm: At
C:\Windows\Temp\packer-elevated-shell-5e320d29-bdbd-b619-9e64-0c8a301b9d1d.p
==> azure-arm: s1:61 char:1
==> azure-arm: + $t = $f.GetTask("\$name")
==> azure-arm: + ~~~~~~~~~~~~~~~~~~~~~~~~~
==> azure-arm:     + CategoryInfo          : NotSpecified:
(:) [], MethodInvocationException
==> azure-arm:     + FullyQualifiedErrorId :
ComMethodTargetInvocation
==> azure-arm:
==> azure-arm: Method invocation failed because
[System.__ComObject] does not contain a
==> azure-arm: method named 'Run'.
==> azure-arm: At
C:\Windows\Temp\packer-elevated-shell-5e320d29-bdbd-b619-9e64-0c8a301b9d1d.p
==> azure-arm: s1:62 char:1
==> azure-arm: + $t.Run($null) | Out-Null
==> azure-arm: + ~~~~~~~~~~~~~~~~~~~~~~~~
==> azure-arm:     + CategoryInfo          :
InvalidOperation: (Run:String) [], RuntimeExcept
==> azure-arm:    ion
==> azure-arm:     + FullyQualifiedErrorId : MethodNotFound
==> azure-arm:
Cancelling build after receiving interrupt
==> azure-arm: Removing the created Deployment object:
'pkrdp087bb80ibj'
==> azure-arm: Removing the created Deployment object:
'kvpkrdp087bb80ibj'
==> azure-arm:
==> azure-arm: Cleanup requested, deleting resource group
...
==> azure-arm: Resource group has been deleted.
Build 'azure-arm' errored: Build was cancelled.
Cleanly cancelled builds after being interrupted.
```

Build results after change
```
azure-arm: WinRM connected.
==> azure-arm: <Objs Version="1.1.0.1"
xmlns="http://schemas.microsoft.com/powershell/2004/04"><Obj S="progress" RefId="0"><TN RefId="0"><T>System.Management.Automation.PSCustomObject</T><T>System.Object</T></TN><MS><I64
N="SourceId">1</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj><Obj S="progress" RefId="1"><TNRef RefId="0" /><MS><I64 N="SourceId">2</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj><Obj S="progress" RefId="2"><TNRef RefId="0" /><MS><I64 N="SourceId">3</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj></Objs>
==> azure-arm: Connected to WinRM!
==> azure-arm: Running local shell script:
/tmp/packer-shell091779215 azure-arm: 022xUtbwAH3DdqIoRCOh9caZi8tOYqcY
==> azure-arm: Provisioning with Powershell...
==> azure-arm: Provisioning with powershell script: /tmp/powershell-provisioner469853889
azure-arm: HELLO NEW USER; automatically generated aws password is: 022xUtbwAH3DdqIoRCOh9caZi8tOYqcY
==> azure-arm: Querying the machine's properties ...
```
2020-01-30 12:07:48 -05:00
Sylvia Moss dc31bad539
Sharing info with post-processors via artifact (#8632) 2020-01-30 11:27:58 +01:00
Megan Marsh b0b10f6939
Merge pull request #8496 from ryanhartje/delete_arm_deployment_on_cleanup
attempting to resolve deployment quota issue due to non-cleanup
2020-01-23 09:48:20 -08:00
Ryan Hartje c4a9715e50 updated the deleteTemplate invocation to a defer at the start of cleanup 2020-01-22 16:58:26 -06:00
Aishwarya Thangappa 9f24869e36 Update the error handling for end-of-life-date parsing 2020-01-06 22:58:26 -08:00
Aishwarya Thangappa 9569d35d14 Set expiry for image versions in SIG
Updates azure builder to support setting end-of-life-date for
image versions in shared image gallery. In addition, this change adds
the ability to set the global replica count for the image version
and allows the vms deployed from the latest version of the Image
Definition to exclude this Image Version.
2020-01-06 22:58:26 -08:00
Megan Marsh dca2c03cdb
Merge pull request #7866 from hashicorp/sharing_info
Add new struct to Provision() method signature, allowing us to share connection and credential info generated at build time with provisioners.
2019-12-17 14:55:20 -08:00
Ryan Hartje bfc3b72050 attempting to resolve deployment quota issue due to non-cleanup 2019-12-17 09:57:57 -06:00
nywilken 1eb55c2ae3 builder/azure: Remove double override of GalleryImageVersionsClient.PollDuration
This change fixes an issues where custom timeouts set for the
GalleryImagesVersionClient was being over written by the default client
poll duration.
2019-12-17 10:47:32 -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
Kris Hicks 40357e2534 docs/builder/azure-arm: Remove errant html comment (#8484)
* Remove errant html comment from source

* make generate
2019-12-13 10:35:24 -05:00
Megan Marsh 3389d843f0 update all provisioners that used the winrmpassword tooling to use the new generateddata option 2019-12-12 16:42:53 -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 df031db9da builder/azure/common/template: remove unused TemplateBuilder.getResourceByType2() (#8419)
builder/azure/common/template: remove unused TemplateBuilder.toKeyVaultID()
2019-12-02 18:09:42 +01:00
Megan Marsh d5ba530b26 make it clear we expect pem format not some other formate (#8344) 2019-11-07 10:30:51 +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
Lars Lehtonen 6862e3534f
builder/azure/chroot: fix dropped error 2019-10-30 11:14:32 -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
Paul Meyer b54a2ee09d Set correct user agent for Azure clientset 2019-10-23 11:31:29 -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
Megan Marsh 836aaafaa3
Merge pull request #8203 from sumit-kalra/master
Azure-ARM builder: Deploy NSG if list of IP addresses is provided in config
2019-10-21 11:10:58 -07:00
Adrien Delorme 8b76453e7f make generate 2019-10-16 10:50:45 +02:00
Adrien Delorme 4542666e25 fix func calls after master merge 2019-10-16 10:40:25 +02:00
Adrien Delorme cf1555bf17 Merge remote-tracking branch 'origin/master' into artifact-tree 2019-10-16 10:22:56 +02:00