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

Add Support for Block Labels when using mapstructure-to-hcl2 #193

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

aidan-mundy
Copy link

@aidan-mundy aidan-mundy commented Jun 30, 2023

  • Adds support for Block Labels to mapstructure-to-hcl
    • Any string (or string pointer) field on a struct that also has the "label" option on the `hcl struct tag will be treated as a label, and generated schema include that field as a BlockLabel instead of an Attribute.
      • Example struct tag:'mapstructure:"nameLabel" hcl:",label"' (except with "`" instead of "'")
    • Configuring label field on the root-level Config struct for a component will trigger a crash before the build begins.
      • This happens because labels at that level are managed by another component of Packer. I consider this to be expected behavior because a label is not valid in that location.
  • Updates HCL schema generation to actually use the required:"true" struct tag. Fields including that struct tag that are parsed as Attributes will have Required: true in their AttributeSpec.
    • This is a "breaking change" because the struct tag may be present in some cases where the field is not actually required. It is only used for documentation generation at the moment, so the fix for most users is to remove the label in cases where the field is not actually required.

@aidan-mundy aidan-mundy added the enhancement New feature or request label Jun 30, 2023
@aidan-mundy aidan-mundy requested a review from a team as a code owner June 30, 2023 16:48
@aidan-mundy aidan-mundy force-pushed the aidan-mundy/add-label-support branch from 3e4909a to 53be7d8 Compare June 30, 2023 16:53
Copy link

@JenGoldstrich JenGoldstrich left a comment

Choose a reason for hiding this comment

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

This is looking good to me Aidan! I think this approach makes sense to me, I think we should add testing for this in the existing units, like we talked about in slack I think it'd be good to have an example on your provisioners you're working on since that'd make manual testing of this super easy

We'll likely also want to update https://github.com/hashicorp/packer-plugin-scaffolding the scaffolding to have an example of this, but thats after this is released of course

@aidan-mundy aidan-mundy force-pushed the aidan-mundy/add-label-support branch from 9bd6c6b to b46d9da Compare August 2, 2023 19:49
@aidan-mundy aidan-mundy force-pushed the aidan-mundy/add-label-support branch from 45ddb52 to 5119a50 Compare August 3, 2023 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants