Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the use of build.name for naming provisioners and post-processors #11432

Merged
merged 1 commit into from
Dec 7, 2021

Conversation

nywilken
Copy link
Member

@nywilken nywilken commented Dec 6, 2021

This changes makes the builder variable build.name avialable at parsing so that it can be used to name provisioners and post-processors.

source "null" "pizza" {
    communicator = "none"
}

build {
    name = "pineapple"
    sources = [
        "sources.null.pizza",
    ]

    provisioner "shell-local" {
        name = "${build.name}"
        inline = [
            "echo '' > ${build.name}.txt"
        ]
    }
    post-processor "shell-local" {
        name = "${build.name}"
        inline = [
            "echo '' > ${build.name}-pps.txt"
        ]
    }
}

Closes #11411

@nywilken nywilken requested a review from a team as a code owner December 6, 2021 15:37
@nywilken nywilken force-pushed the wilken/post_processor-variable-interpolation branch from 83f0536 to 73e3a29 Compare December 6, 2021 15:41
* Add basic post-processor test

Closes #11411
@nywilken nywilken force-pushed the wilken/post_processor-variable-interpolation branch from 73e3a29 to cc56959 Compare December 6, 2021 15:59
Comment on lines +110 to +113
ectx := cfg.EvalContext(BuildContext, nil)
ectx.Variables[buildAccessor] = cty.ObjectVal(map[string]cty.Value{
"name": cty.StringVal(b.Name),
})
Copy link
Member

Choose a reason for hiding this comment

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

You could have also passed the extra variables as argument here, like:

Suggested change
ectx := cfg.EvalContext(BuildContext, nil)
ectx.Variables[buildAccessor] = cty.ObjectVal(map[string]cty.Value{
"name": cty.StringVal(b.Name),
})
variables := map[string]cty.Value{
buildAccessor: cty.ObjectVal(map[string]cty.Value{
"name": cty.StringVal(b.Name),
}),
}
ectx := cfg.EvalContext(BuildContext, variables)

It looks bigger, just another possibility. Don't feel pressured to accept the changes. Yours looks great!

Copy link
Member

@sylviamoss sylviamoss left a comment

Choose a reason for hiding this comment

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

LGTM 👍🏼

Copy link
Contributor

@azr azr left a comment

Choose a reason for hiding this comment

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

LGTM, good catch !

@azr azr merged commit 760169b into master Dec 7, 2021
@azr azr deleted the wilken/post_processor-variable-interpolation branch December 7, 2021 11:24
@github-actions
Copy link

github-actions bot commented Jan 7, 2022

I'm going to lock this pull request 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 related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow to use build variables as post processor name
3 participants