Skip to content

fix: use pointer handle null values#679

Merged
tenthirtyam merged 1 commit intomainfrom
fix/output-config-dir-perm-nullable
Mar 13, 2026
Merged

fix: use pointer handle null values#679
tenthirtyam merged 1 commit intomainfrom
fix/output-config-dir-perm-nullable

Conversation

@tenthirtyam
Copy link
Copy Markdown
Collaborator

Summary

Important

Required after the update to hashicorp/packer-plugin-sdk v0.6.6 in #675.

Change DirPerm in OutputConfig from os.FileMode to *os.FileMode so that HCL2 can correctly represent the field as optional/nullable.

When directory_permission is not set in a onfiguration, the packer-sdc generated flat struct receives a cty null value for the field. Assigning a cty null to a non-pointer os.FileMode causes a runtime panic: "null value is not allowed". Using a pointer type allows the field to be nil when omitted, which is handled in Prepare() by falling back to the default permission of 0750.

The corresponding generated hcl2spec.go files (output_config and step_export) are updated to mirror the pointer type. Because the pointer is now declared in the source struct, future runs of make generate will regenerate these files with *os.FileMode.

Fixes:

  • Runtime error: null value is not allowed [directory_permission]
  • Build error: cannot use DirPerm (type *os.FileMode) as os.FileMode

Type

  • fix: Bug Fix
  • feat: Feature or Enhancement
  • docs: Documentation
  • refactor: Refactoring
  • chore: Build, Dependencies, Workflows, etc.
  • other: Other (Please describe.)

Breaking Changes?

  • Yes, there are breaking changes.
  • No, there are no breaking changes.

Tests

  • Tests have been added or updated.
  • Tests have been completed.

Output:

Documentation

  • Documentation has been added or updated.

Issue References

Ref: #675

Release Note

Additional Information

@tenthirtyam tenthirtyam added this to the v2.1.2 milestone Mar 13, 2026
@tenthirtyam tenthirtyam self-assigned this Mar 13, 2026
@tenthirtyam tenthirtyam added the refactor Refactor label Mar 13, 2026
@github-actions github-actions bot added needs-review Needs Review size/xs Relative Sizing: Extra-Small labels Mar 13, 2026
@tenthirtyam tenthirtyam force-pushed the fix/output-config-dir-perm-nullable branch 2 times, most recently from dcf2973 to 20c3201 Compare March 13, 2026 17:59
@github-actions github-actions bot added the documentation Documentation label Mar 13, 2026
@tenthirtyam tenthirtyam force-pushed the fix/output-config-dir-perm-nullable branch from 20c3201 to 37525d7 Compare March 13, 2026 18:02
@github-actions github-actions bot added the size/s Relative Sizing: Small label Mar 13, 2026
Note: Required after the update to `hashicorp/packer-plugin-sdk` v0.6.6.

Change `DirPerm` in `OutputConfig` from `os.FileMode` to `*os.FileMode`
so that HCL2 can correctly represent the field as optional/nullable.

When `directory_permission` is not set in a onfiguration, the packer-sdc generated flat struct receives a cty null value for the field. Assigning a cty null to a non-pointer `os.FileMode` causes a runtime panic: "null value is not allowed". Using a pointer type allows the field to be nil when omitted, which is handled in `Prepare()` by falling back to the default permission of `0750`.

The corresponding generated `hcl2spec.go` files (`output_config` and `step_export`) are updated to mirror the pointer type. Because the pointer is now declared in the source struct, future runs of `make generate` will regenerate these files with `*os.FileMode`.

Fixes:
- Runtime error: null value is not allowed [directory_permission]
- Build error: cannot use DirPerm (type *os.FileMode) as os.FileMode

Ref: #675

Signed-off-by: Ryan Johnson <ryan.johnson@broadcom.com>
@tenthirtyam tenthirtyam force-pushed the fix/output-config-dir-perm-nullable branch from 37525d7 to 4d7cefd Compare March 13, 2026 18:28
@vmware vmware locked and limited conversation to collaborators Mar 13, 2026
@tenthirtyam tenthirtyam marked this pull request as ready for review March 13, 2026 18:50
@tenthirtyam tenthirtyam requested a review from a team as a code owner March 13, 2026 18:50
Copilot AI review requested due to automatic review settings March 13, 2026 18:50
@tenthirtyam tenthirtyam merged commit 8e44a17 into main Mar 13, 2026
11 checks passed
@tenthirtyam tenthirtyam deleted the fix/output-config-dir-perm-nullable branch March 13, 2026 18:50
@tenthirtyam tenthirtyam removed the needs-review Needs Review label Mar 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

documentation Documentation refactor Refactor size/s Relative Sizing: Small size/xs Relative Sizing: Extra-Small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant