hashicorp / packer-plugin-googlecompute

Packer plugin for Google Compute Builder
https://www.packer.io/docs/builders/googlecompute
Mozilla Public License 2.0
23 stars 53 forks source link

Added support for node affinity labels #94

Closed rosmo closed 2 years ago

rosmo commented 2 years ago

Adds support for node_affinity field in googlecompute source. Example:

  node_affinity { 
    key = "workload"
    operator = "IN"
    values = ["packer"]
  }
  node_affinity { 
    key = "workload"
    operator = "NOT_IN"
    values = ["notpacker"]
  }

I put WIP in the title because the test are giving me a panic which seems to be unrelated to my changes. However, I tested building images with and without node_affinity configs. Also I'm not sure what parts get autogenerated and I shouldn't be including in my PR.

The PR also touches the waitForState mechanism, because if a sole-tenant node is not available the operation state becomes DONE but there is a precondition failed error emitted, which is flagged as a retryable error and will keep the function spinning until timeout. I'm also fine with taking that out, in case you think it's too much.

Closes #93

rosmo commented 2 years ago

Removing WIP, since make testacc gives a full PASS. make test works too - figured out it really needs to be run on GCE (looks to be OS Login related).

rosmo commented 2 years ago

re: OS Login - I think the test suite was making an assumption about some username (testing@packer.io) where mine was different. Not a big deal, as it's completely unrelated to this.

I added a link to the Sole Tenancy (aka node affinity labels) to the documentation - the feature is mainly for a) compliance purposes, and/or b) building Windows images using BYOL (as per licensing terms BYOL licenses are not allowed to run on shared tenancy infrastructure).