Retrieving virtual machine network information (azure-arm)

During a Packer build the network information for a given virtual machine gets shown in the output prior to WinRM becoming available:

2020-06-11T10:22:31+03:00: ==> vm: Getting the VM's IP address ...
2020-06-11T10:22:31+03:00: ==> vm:  -> ResourceGroupName   : 'packer-5e6afc58-5156-4354-9b25-69bacea685b7'
2020-06-11T10:22:31+03:00: ==> vm:  -> PublicIPAddressName : 'pkrip962o2olfs1'
2020-06-11T10:22:31+03:00: ==> vm:  -> NicName             : 'pkrni962o2olfs1'
2020-06-11T10:22:31+03:00: ==> vm:  -> Network Connection  : 'PublicEndpointInPrivateNetwork'
2020-06-11T10:22:32+03:00: ==> vm:  -> IP Address          : '52.162.91.186'
2020-06-11T10:22:32+03:00: ==> vm: Waiting for WinRM to become available...

Is there a way to get this information programmatically during the build so some provisioners could use those values or even after the fact? I tried to use the manifest post-processor, but that did not expose such information. This seems like something that should be a template variable for the azure-arm builder, but the overall level of documentation for any builder’s template variable is severely lacking.

EDIT:

After sleuthing in the source code for Getting the VM's IP address I came across the relevant step in the code that gets the IP address and at the very start it imports a set of Azure-specific constants that seem to be the very thing I would want access to. Using these as template variables did not work, at least with the variants I tried:

{{ .ArmPublicIPAddressName }}
{{ .PublicIPAddressName }}

I also tried setting them as user variables at the very start, though that may have been the wrong way to go as perhaps those values aren’t even initialized then, and that did not work either.

EDIT 2:

Continued searching and came across this issue in GitHub and from there I was able to leverage the following build variable:

{{ build `Host` }}

With the ID variable I got an error: ERR_ID_NOT_IMPLEMENTED_BY_BUILDER, so that’s out of the question.

Prefixing the “variables” from the first edit with build had no effect. This is already an overall improvement, but I would still leave my original question open as I’m interested in additional Azure-related data as well that seems to be available in one way or another during the build.

I would also pose an additional question: how hard would it be to expose the aforementioned constants as build variables? I have zero experience with Go and with developing Packer in general…

@usrme glad to see that you were able to find the build template engine variables. That is how Packer 1.5.0+ shares dynamic builder information such as instance ID or network address with provisioners and post-processors. Here’s a list of all the available variables https://www.packer.io/docs/templates/engine/#build

As for adding new variable information, the Packer code base has a helper for exposing information as build variables. There is a some documentation on how and what would need to be done at https://www.packer.io/docs/extending/custom-builders/#build-variables

Apologies in advance for all the documentation links. If you know what information you would like to see made available please open an enhancement issue on GitHub https://github.com/hashicorp/packer/issues/new?labels=enhancement&template=feature_requests.md with the details. Cheers!