Skip to content

HCL2: pass on builder type and name#8956

Merged
azr merged 1 commit intomasterfrom
source_var
Apr 9, 2020
Merged

HCL2: pass on builder type and name#8956
azr merged 1 commit intomasterfrom
source_var

Conversation

@azr
Copy link
Copy Markdown
Contributor

@azr azr commented Mar 26, 2020

Howdy ! This :

  • sets packer_build_name and packer_builder_type variables for builder provisioners and post-processors in HCL2
  • allows to use the new ${source.type} and ${source.name} variables in HCL2 [ this is not required but this was the route I first took in order to test this and this has helped me a little, so I decided to leave it, please tell me if you think this is a bad idea ]
  • fixes LXD build fails when using HCL syntax #8932

Note that the common.PackerConfig is used everywhere and was not set for HCL2, this had some implications:

For #8932 you can see the issue here:

if c.ContainerName == "" {
c.ContainerName = fmt.Sprintf("packer-%s", c.PackerBuildName)
}

More random examples of where this could cause an issue :

extraArgs := fmt.Sprintf(" --extra-vars \"packer_build_name=%s packer_builder_type=%s packer_http_addr=%s -o IdentitiesOnly=yes\" ",
p.config.PackerBuildName, p.config.PackerBuilderType, common.GetHTTPAddr())

&awscommon.StepKeyPair{
Debug: b.config.PackerDebug,
Comm: &b.config.RunConfig.Comm,
DebugKeyPath: fmt.Sprintf("ec2_%s.pem", b.config.PackerBuildName),
},

}

generatedVars, warning, err := builder.Prepare(decoded)
generatedVars, warning, err := builder.Prepare(source.builderVariables(), decoded)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we use the properties of mapstructure to first pass on the builder variables then set the decoded values from an hcl config file. This allows to not have to manually default this for every builder/provisioner/post-processor

Comment on lines +114 to +116
if p.config.StripTime {
artifact.BuildTime = 0
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows to make my test based on the content of the manifest.json file. Without this build_time changes all the time.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 26, 2020

Codecov Report

Merging #8956 into master will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted Files Coverage Δ
hcl2template/parser.go 83.46% <100.00%> (ø)
hcl2template/types.build.post-processor.go 41.50% <100.00%> (ø)
hcl2template/types.build.provisioners.go 38.18% <100.00%> (ø)
hcl2template/types.packer_config.go 81.95% <100.00%> (+1.84%) ⬆️
hcl2template/types.source.go 78.43% <100.00%> (+2.34%) ⬆️
packer/communicator.go 74.46% <0.00%> (-2.13%) ⬇️
builder/azure/arm/tempname.go 84.37% <0.00%> (+6.25%) ⬆️

@azr azr marked this pull request as ready for review March 27, 2020 13:25
@azr azr requested a review from a team as a code owner March 27, 2020 13:25
@azr azr added hcl2 core Core components of Packer bug enhancement labels Mar 27, 2020
@SwampDragons
Copy link
Copy Markdown
Contributor

Is all the website stuff failing because you need to rebase?

@azr
Copy link
Copy Markdown
Contributor Author

azr commented Apr 9, 2020

I think so yes; rebasing now

@azr
Copy link
Copy Markdown
Contributor Author

azr commented Apr 9, 2020

Okay it's all green, I think this can be merged.

@azr azr merged commit 2af40c7 into master Apr 9, 2020
@azr azr deleted the source_var branch April 9, 2020 09:14
@azr azr added this to the 1.5.6 milestone Apr 9, 2020
@azr azr mentioned this pull request May 7, 2020
34 tasks
@ghost
Copy link
Copy Markdown

ghost commented May 10, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators May 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bug core Core components of Packer enhancement hcl2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LXD build fails when using HCL syntax

3 participants