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

Azure-chroot has issues with detecting environment information. Error is 'function "vm" not defined' #87

Closed
ghost opened this issue May 15, 2021 · 6 comments · Fixed by #396
Labels

Comments

@ghost
Copy link

ghost commented May 15, 2021

This issue was originally opened by @arvindn05 as hashicorp/packer#10985. It was migrated here as a result of the Packer plugin split. The original body of the issue is below.


Overview of the Issue

Unable to run azure-chroot builder using the instructions from the documentation.

Getting the error
* unable to render temporary disk id: template: root:1: function "vm" not defined

Looking at the code, looks like a "vm" function is being defined and it uses Azure metadata endpoint to retrive the information required. But it does not seem to be functioning.
https://github.com/hashicorp/packer/blob/master/builder/azure/chroot/builder.go#L154

Reproduction Steps

Take the below packer file and run it on an azure VM. Just running validate is good enough to repro the problem.

The packer file is taken almost as is from https://www.packer.io/docs/builders/azure/chroot#using-a-service-principal

Uncommenting the commented section allows it to run without issues....but they are not required fields and they need to be autopopulated per the documentation.

Packer version

2021/05/01 01:17:22 [INFO] Packer version: 1.7.2 [go1.16.3 linux amd64]

Simplified Packer Buildfile

variables {
  az_subscription_id  = "sub"
  az_client_id        = "client_bar"
  az_client_secret    = "secret_bar"
  az_resource_group   = "my-resource-group"
}

source "azure-chroot" "basic-example" {
  client_id = var.az_client_id
  client_secret = var.az_client_secret
  subscription_id = var.az_subscription_id

  # image_resource_id = "/subscriptions/${var.az_subscription_id}/resourceGroups/${var.az_resource_group}/providers/Microsoft.Compute/images/MyDebianOSImage-{{timestamp}}"
  # temporary_os_disk_id = "/subscriptions/${var.az_subscription_id}/resourceGroups/${var.az_resource_group}/providers/Microsoft.Compute/disks/PackerTemp-osdisk-{{timestamp}}"
  # temporary_os_disk_snapshot_id = "/subscriptions/${var.az_subscription_id}/resourceGroups/${var.az_resource_group}/providers/Microsoft.Compute/snapshots/PackerTemp-osdisk-snapshot-{{timestamp}}"
  # temporary_data_disk_id_prefix = "/subscriptions/${var.az_subscription_id}/resourceGroups/${var.az_resource_group}/providers/Microsoft.Compute/disks/PackerTemp-datadisk-{{timestamp}}-"
  # temporary_data_disk_snapshot_id = "/subscriptions/${var.az_subscription_id}/resourceGroups/${var.az_resource_group}/providers/Microsoft.Compute/snapshots/PackerTemp-datadisk-snapshot-{{timestamp}}-"

  source = "credativ:Debian:9:latest"
}

build {
  sources = ["sources.azure-chroot.basic-example"]

  provisioner "shell" {
    inline = ["apt-get update", "apt-get upgrade -y"]
    inline_shebang = "/bin/sh -x"
  }
}

Operating system and Environment details

Virtualization: microsoft

Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-1160.15.2.el7.x86_64
Architecture: x86-64

Log Fragments and crash.log files

[root@Azure-Packer-Builder basic-packer]# ../packer build azure_sample.pkr.hcl
2021/05/01 01:00:37 [INFO] Packer version: 1.6.5 [go1.15.3 linux amd64]
2021/05/01 01:00:37 Checking 'PACKER_CONFIG' for a config file path
2021/05/01 01:00:37 'PACKER_CONFIG' not set; checking the default config file path
2021/05/01 01:00:37 Attempting to open config file: /root/.packerconfig
2021/05/01 01:00:37 [WARN] Config file doesn't exist: /root/.packerconfig
2021/05/01 01:00:37 Setting cache directory: /home/azureuser/basic-packer/packer_cache
2021/05/01 01:00:37 Creating plugin client for path: /home/azureuser/packer
2021/05/01 01:00:37 Starting plugin: /home/azureuser/packer []string{"/home/azureuser/packer", "plugin", "packer-builder-azure-chroot"}
2021/05/01 01:00:37 Waiting for RPC address for: /home/azureuser/packer
2021/05/01 01:00:37 packer-builder-azure-chroot plugin: [INFO] Packer version: 1.6.5 [go1.15.3 linux amd64]
2021/05/01 01:00:37 packer-builder-azure-chroot plugin: Checking 'PACKER_CONFIG' for a config file path
2021/05/01 01:00:37 packer-builder-azure-chroot plugin: 'PACKER_CONFIG' not set; checking the default config file path
2021/05/01 01:00:37 packer-builder-azure-chroot plugin: Attempting to open config file: /root/.packerconfig
2021/05/01 01:00:37 packer-builder-azure-chroot plugin: [WARN] Config file doesn't exist: /root/.packerconfig
2021/05/01 01:00:37 packer-builder-azure-chroot plugin: Setting cache directory: /home/azureuser/basic-packer/packer_cache
2021/05/01 01:00:37 packer-builder-azure-chroot plugin: args: []string{"packer-builder-azure-chroot"}
2021/05/01 01:00:37 packer-builder-azure-chroot plugin: Plugin address: unix /tmp/packer-plugin312089225
2021/05/01 01:00:37 packer-builder-azure-chroot plugin: Waiting for connection...
2021/05/01 01:00:37 Received unix RPC address for /home/azureuser/packer: addr is /tmp/packer-plugin312089225
2021/05/01 01:00:37 packer-builder-azure-chroot plugin: Serving a plugin connection...

* unable to render temporary disk id: template: root:1: function "vm" not defined
* unable to render temporary snapshot id: template: root:1: function "vm" not defined
* unable to render temporary data disk id prefix: template: root:1: function "vm" not defined
* unable to render temporary data disk snapshot id prefix: template: root:1: function "vm" not defined
Error: 5 error(s) occurred:
* image_resource_id or shared_image_destination is required


  on azure_sample.pkr.hcl line 18:
  (source code not available)

2021/05/01 01:00:37 Build debug mode: false
2021/05/01 01:00:37 Force build: false
2021/05/01 01:00:37 On error:
2021/05/01 01:00:37 Waiting on builds to complete...
==> Wait completed after 5 microseconds
==> Builds finished but no artifacts were created.
2021/05/01 01:00:37 packer-builder-azure-chroot plugin: Source is platform image: credativ:Debian:9:latest
* unable to render temporary disk id: template: root:1: function "vm" not defined
* unable to render temporary snapshot id: template: root:1: function "vm" not defined
* unable to render temporary data disk id prefix: template: root:1: function "vm" not defined
* unable to render temporary data disk snapshot id prefix: template: root:1: function "vm" not defined
* image_resource_id or shared_image_destination is required

  on azure_sample.pkr.hcl line 18:
  (source code not available)
@iluoy
Copy link

iluoy commented Jun 22, 2021

I have met the same issue, anyone have solution about it ?

@tsujp
Copy link

tsujp commented Aug 19, 2021

I'm having this problem too, tried a few things and nothing helped.

@arvindn05
Copy link

arvindn05 commented Aug 31, 2021

the post also gives you work around. Add the below lines and it should fix it

temporary_os_disk_id = "/subscriptions/${var.az_subscription_id}/resourceGroups/${var.az_resource_group}/providers/Microsoft.Compute/disks/PackerTemp-osdisk-{{timestamp}}"
temporary_os_disk_snapshot_id = "/subscriptions/${var.az_subscription_id}/resourceGroups/${var.az_resource_group}/providers/Microsoft.Compute/snapshots/PackerTemp-osdisk-snapshot-{{timestamp}}"
temporary_data_disk_id_prefix = "/subscriptions/${var.az_subscription_id}/resourceGroups/${var.az_resource_group}/providers/Microsoft.Compute/disks/PackerTemp-datadisk-{{timestamp}}-"
temporary_data_disk_snapshot_id = "/subscriptions/${var.az_subscription_id}/resourceGroups/${var.az_resource_group}/providers/Microsoft.Compute/snapshots/PackerTemp-datadisk-snapshot-{{timestamp}}-"

@narg95
Copy link

narg95 commented Dec 3, 2021

Is there any answer to this issue?

@jkurek1
Copy link

jkurek1 commented Mar 24, 2022

I have the same problem.

@JenGoldstrich
Copy link
Contributor

Hey all, this was fixed in #396, this error should no longer appear, and you shouldn't have to set those temporary values manually anymore, however the vm function defined in the chroot builder docs does not work as expected inside of user templates, while this issue is fixed there is still an issue with the vm function, I have opened the above issue #399 to capture this, if you are still running into this error unless the temporary values are set please let us know!

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

Successfully merging a pull request may close this issue.

6 participants