Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Packer ARM Succeeded - Now What? #201

Closed
ndouba opened this Issue Feb 9, 2016 · 5 comments

Comments

Projects
None yet
5 participants

ndouba commented Feb 9, 2016

So the packer script succeeded after assigning the application I created with the Owner role to the Subcription object. I see the blob in my storage account but now I'm stuck at figuring out how we actually hydrate that image into a running VM? There doesn't seem to be any functionality in the Azure portal to do that. Could you please advise on the recommended steps?

Member

boumenot commented Feb 10, 2016

The latest Azure portal does not currently provide too much if you just want to deploy and go.. 😦 All of the legos are exposed, and you need (get?) to build them the way you want. We are working on making improving the experience.

At the end of a packer build you will have a template (.json), and a .vhd.

Portal

  1. Create a NIC for you VM, and attach it the appropriate Virtual Network and Subnet. Click + New > See all > Search for "Network Interface" > Select "Network interface > Create. Locate the NIC you just created, and copy the Resource ID (located under properties).
  2. Locate the template file, and copy the contents.
  3. Click + New > Template Deployment > Edit Template, and paste the contents of the template over all existing data. Click save.
  4. Edit Parameters - provide appropriate values for your template, you will be prompted for all of values that are required. The hardest value to supply in my case is networkInterfaceId, which is a fully qualified resource string of the form "/subscription/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Network/networkInterfaces/{name}. If you do not have one, you will need to create one in the portal or via the CLI.

Azure CLI:

Assuming these are the names of our resources.

  • Resource Group: MyResourceGroup
  • Location: westus
  • Virtual Network: MyVirtualNetwork
  • Subnet: MySubnet
  • Deployment Name: MyDeployment
  • Template URI: https://... (copy the URI from the portal, or download it and reference it directly.)
  • NIC: MyNic

Create a NIC.

azure network nic create MyResourceGroup MyNic westus --subnet-vnet-name MyVirtualNetwork --subnet-name MySubnet

The above command will out an Id for the NIC just created. Copy it, and use it in the command below.

Deploy a VM based on our image.

azure group deployment create -g MyResourceGroup -n MyDeployment --template-uri https://...

The above command will automatically prompt you for all of the values in the template that need to be set, such as vmName, adminUserName, adminPassword, and networkInterfaceId.

HTH.

@boumenot boumenot added the question label Feb 10, 2016

Member

paulmey commented Mar 23, 2016

We should at least create a post-processor for this...

@paulmey What would a post-processor look like for this? Doesn't the process of creating a NIC, and then a VM, have to occur every time the custom VHD is used?

Member

paulmey commented Mar 24, 2016

@Ancillas The builder deploys the initial VM with a template specifying all these resources. A post-processor could do the same thing. IIRC, there should be a json with a template left next to the vhd. See also #220, where we were discussing what the builder artifact should contain.

@boumenot boumenot closed this Apr 26, 2016

pburkholder commented Jan 20, 2017 edited

Here's the CLI guide for folks who are still finding their way around Packer and AzureRM:

Create the NIC

Assuming you're using the same ARM_RESOURCE_GROUP and LOCATION from packer build:

az network vnet create \
  -g $ARM_RESOURCE_GROUP -l $LOCATION \
  --name PackerVirtualNetwork --address-prefix 10.0.0.0/16

az network vnet subnet create \
  -g $ARM_RESOURCE_GROUP \
  --vnet-name PackerVirtualNetwork \
  -n PackerSubnet --address-prefix 10.0.1.0/24

az network nic create \
  -g $ARM_RESOURCE_GROUP \
  --vnet-name PackerVirtualNetwork \
  --subnet PackerSubnet \
  -n PackerDemoNic

This last command will spit out a lot JSON, you'll want the line that looks like this:

"id": "/subscriptions/12345678-abcd-1234-5678-1234567890ab/resourceGroups/my_dev_packer/providers/Microsoft.Network/networkInterfaces/PackerDemoNic/ipConfigurations/ipconfig1",

Create a params files

The newer azure-cli doesn't prompt for template params, so I created x.parameters.json file like this:

{
  "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vmName": {
      "value": "PackerDemoVm"
    },
    "adminUserName": {
      "value": "PackerDemoVm"
    },
    "adminPassword": {
      "value": "PackerD3moVm%%"
    },
    "networkInterfaceId": {
      "value": "/subscriptions/12345678-abcd-1234-5678-1234567890ab/resourceGroups/my_dev_packer/providers/Microsoft.Network/networkInterfaces/PackerDemoNic"
    }
  }
}

Run create with template-uri and parameters

Then I could run az group create:

az group deployment create -g $ARM_RESOURCE_GROUP \
  -n PackerDeployment \
  --parameters @x.parameters.json \
  --template-uri \
  'https://....

Since there's no public IP associated with the instance here, it cant actually be reached, but it should exist.

HTH, Peter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment