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

builder: allow specifying hostId for placement #397

Merged
merged 1 commit into from
Oct 17, 2023
Merged

builder: allow specifying hostId for placement #397

merged 1 commit into from
Oct 17, 2023

Conversation

amaxine
Copy link
Contributor

@amaxine amaxine commented Jun 7, 2023

This PR adds support for specifying an exact dedicated host ID in the placement block. We were originally running this when mac2.metal instances weren't publicly available and AWS API behaviour around them was weird enough that Packer couldn't see them in responses that didn't query a specific ID.

This addresses a specific issue we experience - since by default, the source will grab whatever the first available host is, we occasionally find ourselves with the problem of Packer "stealing" from the wrong pool because for various lifecycle reasons, another host was available. With this change, an end user can instead provide a specific host ID (e.g. via a variable, from the response of an external call to the AWS API creating a new dedicated host resource), ensuring that the correct host is used for a Packer build for resources that aren't possible to fully manage on demand - ideal for Mac type instances in AWS.

This should potentially be exclusive with HostResourceGroupArn but I'm not sure how to appropriately model that in a Packer plugin, or whether it's at all necessary.

@amaxine amaxine requested a review from a team as a code owner June 7, 2023 10:49
@hashicorp-cla
Copy link

hashicorp-cla commented Jun 7, 2023

CLA assistant check
All committers have signed the CLA.

@nywilken
Copy link
Contributor

Hi @amaxine thank you for the contribution. I've add this change to our board so we can work to prioritize the review. So far it looks good I just want to validate your question around exclusivity for other attributes to provide a quality review.

@lbajolet-hashicorp
Copy link
Contributor

Hi @amaxine,

I've walked through the AWS docs, and AFAICT, they do not explicitely state that the two are mutually exclusive. That being said, since host groups are an abstraction over dedicated hosts, it would make sense that if the group ARN is set, the host ID should not be, and vice versa. I did not see anything that points to a valid use-case in specifying both, and I haven't tested what happens with for example awscli if both are specified at once, but I presume either argument has precedence silently (not great), or it errors if they have a check for that.

In any case, I think it would make sense for both to be mutually exclusive, and for the plugin to return an error if both are specified at once.
To implement such a logic, I would look into the Prepare functions, since this is where we walk on the configs and look for inconsistencies, before actually performing the build's steps.

Come to think of it, I would think it'd make sense to also check for the Tenancy at the same time, for consistency with the arguments specified (i.e. it should be host if either the host_id or host_resource_group_arn are specified, and freeform-ish outside of that), but this can be a later improvement, no need to trouble yourself with that if you don't want to.

Let me know if you need help with that, I can take a look if need be.

Besides that I second @nywilken, the code looks good to me, once we add the logic to check for mutual-exclusiveness, this can be merged imho.

@lbajolet-hashicorp
Copy link
Contributor

Hi @amaxine,

FYI, I pushed some changes on your branch to add the extra checks we mentioned in our last review, I also added some tests to make sure the Prepare step works as intended.

@nywilken when you have time could you review those? If you're OK with this reroll, we can merge that PR.

@amaxine
Copy link
Contributor Author

amaxine commented Oct 16, 2023

Thank you for the feedback and the pointers on how to implement mutually exclusive options, and thank you also for picking up the work to finish my PR. Unfortunately in the context of the BSL relicense I have no interest in completing this work, but as I've signed the CLA I'm happy to see the feature get completed.

Copy link
Contributor

@nywilken nywilken left a comment

Choose a reason for hiding this comment

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

Thanks for adding the addition checks. This looks good to me.

@lbajolet-hashicorp lbajolet-hashicorp merged commit 3f79b33 into hashicorp:main Oct 17, 2023
11 checks passed
@nywilken
Copy link
Contributor

Thank you for the feedback and the pointers on how to implement mutually exclusive options, and thank you also for picking up the work to finish my PR. Unfortunately in the context of the BSL relicense I have no interest in completing this work, but as I've signed the CLA I'm happy to see the feature get completed.

@amaxine Thanks for opening up this change. If it’s any consolation the plugins will remain as MPL2. But I completely understand.

Don’t hesitate to reach out if you run into any issues with the plugin. 💙

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants