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

Replace build interface uses #12862

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

Conversation

lbajolet-hashicorp
Copy link
Contributor

In Packer's run interfaces, the builds we construct from the configurations (HCL2 or legacy JSON) are initialised as a list of Build from the SDK (an interface itself).
This is not necessary as we are controlling the types passed around, and they're always a CoreBuild pointer.

Therefore, typing with interface in those cases, while not necessarily wrong, is a bit limiting, especially since we are already casting the builds to CoreBuild in some places of the code.

This PR changes this so we don't type with interfaces anymore, but instead use CoreBuilds in the code, so we don't need to cast those values anymore.

The GetBuilds function, available on both HCL2 and legacy JSON
configuration objects, used to return the Build interface.
This typing by interface is not useful in this instance, since all the
uses of `GetBuilds' are self-contained within Packer, and we're never
using any other implementation for it than `*CoreBuild`.

We've been relying on the dynamic type for all the builds being
*CoreBuild in some places of the code, so to avoid potential surprises
in the future, we'll change the signature now so it returns only
concrete types.
As the rest of the build process was updated to remove references to the
Build interface exposed by the SDK, we change the usage of such types in
the hcp internal package, so they are typed with *CoreBuild too.
@lbajolet-hashicorp lbajolet-hashicorp requested a review from a team as a code owner March 1, 2024 18:59
@nywilken nywilken added stage/needs-discussion core Core components of Packer labels Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core components of Packer stage/needs-discussion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants