hashicorp / hashicorp/packer-plugin-googlecompute
builder `googlecompute` uses hostname instead of instance name to set instance metadata
- Dominant language
- Go
- Stars
- 33
- Forks
- 72
- Avg merge
- 6h 47m
- Merged PRs (30d)
- 3
Description
_This issue was originally opened by @alexfouche as hashicorp/packer#7789. It was migrated here as a result of the [Packer plugin split](https://github.com/hashicorp/packer/issues/8610#issuecomment-770034737). The original body of the issue is below._
- Packer version 1.4.1
- Host Linux Centos 7
This issue applies to the `googlecompute` builder
The issue appears **when the hostname or FQDN of the linux instance does not match the instance name** set when creating the instance. Or when hostname is modified (via a custom startup script or whatever at linux start, ...) or is set with `"instance_name": ` in the builder json block
The builder, when instanciating a VM adds a metadata `startup-script`. In this script, there is a shell function `SetMetadata()`, which is called at the end of the startup script to set instance metadata `startup-script-status=done`
```bash
SetMetadata () {
gcloud compute instances add-metadata ${HOSTNAME} --metadata ${1}=${2} --zone ${ZONE}
}
```
See [startup.go#L27](https://github.com/hashicorp/packer/blob/55bfee509aae718b695f5c84736b281d4119cc6e/builder/googlecompute/startup.go#L27)
The problem lies in the fact that `${HOSTNAME}` is used. **The Google instance name should be used, not the hostname**.
Using the `GetMetadata()` function of the script, the instance name can be retrieved with
GetMetadata name
Contributor guide
Assessment
This issue has not been assessed yet.