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 use_internal_ip and omit_external_ip fields to export post-processor #211

Conversation

cmgsj
Copy link

@cmgsj cmgsj commented Mar 1, 2024

After trying to use the googlecompute-export post-processor, it fails when provisioning the exporter instance because it violates the organization policy constraints/compute.vmExternalIpAccess.

This is the packer code used:

source "googlecompute" "vm" {
  // ...
}

build {
  name = "main"
  sources = ["sources.googlecompute.vm"]
  // ...
  post-processor "googlecompute-export" {
    paths = [
      "gs://$BUCKET_NAME/$IMAGE_NAME.tar.gz",
    ]
    keep_input_artifact = true
  }
}

and a fragment of the build logs:

==> main.googlecompute.vm: Running post-processor: (type googlecompute-export)
==> main.googlecompute.vm (googlecompute-export): Exporting image $IMAGE_NAME to destination: [gs://$BUCKET_NAME/$IMAGE_NAME.tar.gz]
==> main.googlecompute.vm (googlecompute-export): Creating temporary RSA SSH key for instance...
==> main.googlecompute.vm (googlecompute-export): Using image: debian-9-worker-v20200616
==> main.googlecompute.vm (googlecompute-export): Creating instance...
    main.googlecompute.vm (googlecompute-export): Loading zone: $ZONE
    main.googlecompute.vm (googlecompute-export): Loading machine type: n1-highcpu-4
    main.googlecompute.vm (googlecompute-export): Requesting instance creation...
==> main.googlecompute.vm (googlecompute-export): Error creating instance: googleapi: Error 412: Constraint constraints/compute.vmExternalIpAccess violated for project $PROJECT_NUMBER. Add instance projects/$PROJECT_ID/zones/$ZONE/instances/$IMAGE_NAME-exporter to the constraint to use external IP with it., conditionNotMet

This happens because the provisioned export instance always has the fields omit_external_ip and use_internal_ip set to false, with no way to overwrite them.

This PR attempts to change that behavior, by exposing the aforementioned fields in the googlecompute-export post-processor config and then using them in the googlecompute.Config of the export instance.

Example:

source "googlecompute" "vm" {
  // ...
}

build {
  name = "main"
  sources = ["sources.googlecompute.vm"]
  // ...
  post-processor "googlecompute-export" {
    paths = [
      "gs://$BUCKET_NAME/$IMAGE_NAME.tar.gz",
    ]
    keep_input_artifact = true
    omit_external_ip    = true
    use_internal_ip     = true
  }
}

Please let me know if a way to circumvent this issue already exists. Any other feedback is welcome as well 🙂!

@cmgsj cmgsj requested a review from a team as a code owner March 1, 2024 03:19
@hashicorp-cla
Copy link

hashicorp-cla commented Mar 1, 2024

CLA assistant check
All committers have signed the CLA.

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.

Hi there apologies for the delayed review here. Our focus has been on Packer itself trying to resolve issues with plugin loading. Looking at the changes and reference issue I can understand the need for this feature.

I left a few suggestions on the change based on my understanding on how Omit and Use internal are working. Please let me know if you have any questions or if my understanding is off.

@cmgsj cmgsj changed the title add omit_external_ip and use_internal_ip fields to export post-processor add use_internal_ip field to export post-processor Mar 19, 2024
@cmgsj cmgsj force-pushed the feature/googlecompute-export-internal-ip branch from eb0bc8c to 97d43c0 Compare March 19, 2024 22:32
@cmgsj
Copy link
Author

cmgsj commented Mar 19, 2024

@nywilken thank you so much for taking the time to review!

I initially thought of adding both fields use_internal_ip and omit_external_ip in order to be consistent with the fields the googlecompute source exposes.

I have identified three possible successful combinations of the above fields according to the following truth table:

case use_internal_ip omit_external_ip result
1 true true ✅ internal IP is used, instance does not have an external IP
2 true false ✅ internal IP is used, instance has an external IP
3 false true ❌ cannot use external IP because instance does not have one
4 false false ✅ external IP is used, instance has an external IP

All the statements you made above are true except the following two, which are indeed possible, but not necessary:

  • When UseInternalIP is true OmitExternalIP must be True.
  • OmitExternalIP can not be false when UseInternal is True.

I think you might not have taken case 2 into account.

Having said that, I do think that your suggestion is very reasonable and will prevent any potential "build-time" errors from case 3, although it would also prevent case 2.

In the end I think the disjunction is between allowing all cases (with a the potential error case 3), or allowing only cases 1 and 4 (without the potential success case 2).

Please let me know if you agree, and/or what your suggestion would be, thanks in advance!

@cmgsj cmgsj changed the title add use_internal_ip field to export post-processor add use_internal_ip and omit_external_ip fields to export post-processor Mar 19, 2024
@cmgsj cmgsj requested a review from nywilken March 19, 2024 23:08
@cmgsj
Copy link
Author

cmgsj commented May 22, 2024

@nywilken whenever you have some time, please let me know if my comment above makes more sense, or if you think it would be better to go forward with the changes you had originally suggested.

Thanks.

@cmgsj cmgsj force-pushed the feature/googlecompute-export-internal-ip branch from 97d43c0 to 4fa2ddf Compare December 20, 2024 05:26
@cmgsj
Copy link
Author

cmgsj commented Dec 20, 2024

@nywilken I pushed a commit for adding a validation error on case #3 in my comment above.

Please review it when you have the time. Thanks.

@nywilken
Copy link
Contributor

@cmgsj Im no longer working on these PRs. Pinging @lbajolet-hashicorp to continue pushing this forward. Please keep in mind that his response may be slow as they work on different priorities.

@cmgsj
Copy link
Author

cmgsj commented Dec 24, 2024

Hi @lbajolet-hashicorp,

I've submitted this PR with some enhancements to the googlecompute-export post-processor, and I'd appreciate it if you could take a look whenever you have a moment.

Let me know if you have any questions or need additional context. Thanks in advance for your time!

Copy link
Contributor

@lbajolet-hashicorp lbajolet-hashicorp left a comment

Choose a reason for hiding this comment

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

Hi @cmgsj,

Sorry for the delay in the review here, I was busy working on other things, we're planning a release for the GCE plugin this week, so I'm going through the opened PRs now to see what we can include in it.

Regarding your change, while I understand the reason to add OmitExternalIP to the googlecompute-export post-processor here, as it's used by the step that creates the temporary instance, the UseInternalIP seems superfluous here.

UseInternalIP is only used by StepInstanceInfo, which while used in the builder for GCE for populating the instance's IP address to use for the remainder of the build steps. It is not used in the export post-processor at all since there's not a lot done in there, so I would think you can remove it, remove the extra check for both attributes set, and amend the comment so that OmitExternalIP is the only attribute added here.

Of course I might be missing something so please let me know if that's the case.

Marking as request changes for now, but hopefully this can be quickly resolved, thanks!

@lbajolet-hashicorp
Copy link
Contributor

lbajolet-hashicorp commented Feb 11, 2025

Oh, on another note, I see the CLA has not been accepted by your Github account yet, which means we cannot accept the contribution until this is done. Could you do this at the same time so we aren't blocked if/when it comes to merging this PR?

Edit: it seems there are more than one commit, which means that all commits must be linked to a Github account which has accepted the CLA, you can probably rebase and squash those together using the same email address as your account if you have already signed them.

@cmgsj cmgsj force-pushed the feature/googlecompute-export-internal-ip branch from 7689d9e to 8ac85dc Compare February 11, 2025 16:41
@cmgsj cmgsj force-pushed the feature/googlecompute-export-internal-ip branch from b6d0cea to 11f85ad Compare February 11, 2025 16:41
@cmgsj
Copy link
Author

cmgsj commented Feb 11, 2025

@lbajolet-hashicorp thanks for the review!

The changes you suggested make much more sense, I have implemented them.
I realize that UseInternalIP is only used by the builder's StepInstanceInfo.

I also fixed the CLA issue.

Copy link
Contributor

@lbajolet-hashicorp lbajolet-hashicorp left a comment

Choose a reason for hiding this comment

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

Hey again @cmgsj,

Looks much simpler indeed :)

With that it seems good to me, we can merge it right away, thanks for the quick reroll, much appreciated!

@lbajolet-hashicorp lbajolet-hashicorp merged commit bc30896 into hashicorp:main Feb 11, 2025
12 checks passed
@cmgsj cmgsj deleted the feature/googlecompute-export-internal-ip branch February 11, 2025 19:00
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.

4 participants