github.com/yoctocloud/packer@v0.6.2-0.20160520224004-e11a0a18423f/builder/azure/arm/README.md (about) 1 # packer-azure-arm 2 3 The ARM flavor of packer-azure utilizes the 4 [Azure Resource Manager APIs](https://msdn.microsoft.com/en-us/library/azure/dn790568.aspx). 5 Please see the 6 [overview](https://azure.microsoft.com/en-us/documentation/articles/resource-group-overview/) 7 for more information about ARM as well as the benefit of ARM. 8 9 ## Device Login vs. Service Principal Name (SPN) 10 11 There are two ways to get started with packer-azure. The simplest is device login, and only requires a Subscription ID. 12 Device login is only supported for Linux based VMs. The second is the use of an SPN. We recommend the device login 13 approach for those who are first time users, and just want to ''kick the tires.'' We recommend the SPN approach if you 14 intend to automate Packer, or you are deploying Windows VMs. 15 16 ## Device Login 17 18 A sample template for device login is show below. There are three pieces of information 19 you must provide to enable device login mode. 20 21 1. SubscriptionID 22 1. Resource Group - parent resource group that Packer uses to build an image. 23 1. Storage Account - storage account where the image will be placed. 24 25 > Device login mode is enabled by not setting client_id, client_secret, and tenant_id. 26 27 The device login flow asks that you open a web browser, navigate to http://aka.ms/devicelogin, and input the supplied 28 code. This authorizes the Packer for Azure application to act on your behalf. An OAuth token will be created, and 29 stored in the user's home directory (~/.azure/packer/oauth-TenantID.json, and TenantID will be replaced with the actual 30 Tenant ID). This token is used if it exists, and refreshed as necessary. 31 32 ```json 33 { 34 "variables": { 35 "sid": "your_subscription_id", 36 "rgn": "your_resource_group", 37 "sa": "your_storage_account" 38 }, 39 "builders": [ 40 { 41 "type": "azure-arm", 42 43 "subscription_id": "{{user `sid`}}", 44 45 "resource_group_name": "{{user `rgn`}}", 46 "storage_account": "{{user `sa`}}", 47 48 "capture_container_name": "images", 49 "capture_name_prefix": "packer", 50 51 "os_type": "Linux", 52 "image_publisher": "Canonical", 53 "image_offer": "UbuntuServer", 54 "image_sku": "14.04.3-LTS", 55 56 "location": "South Central US", 57 "vm_size": "Standard_A2" 58 } 59 ], 60 "provisioners": [ 61 { 62 "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'", 63 "inline": [ 64 "apt-get update", 65 "apt-get upgrade -y", 66 67 "/usr/sbin/waagent -force -deprovision+user && export HISTSIZE=0 && sync" 68 ], 69 "inline_shebang": "/bin/sh -x", 70 "type": "shell" 71 } 72 ] 73 } 74 ``` 75 76 ## Service Principal Name 77 78 The ARM APIs use OAUTH to authenticate, and requires an SPN. The following articles 79 are a good starting points for creating a new SPN. 80 81 * [Automating Azure on your CI server using a Service Principal](http://blog.davidebbo.com/2014/12/azure-service-principal.html) 82 * [Authenticating a service principal with Azure Resource Manager](https://azure.microsoft.com/en-us/documentation/articles/resource-group-authenticate-service-principal/) 83 84 There are three (four in the case of Windows) pieces of configuration you need to note 85 after creating an SPN. 86 87 1. Client ID (aka Service Principal ID) 88 1. Client Secret (aka Service Principal generated key) 89 1. Client Tenant (aka Azure Active Directory tenant that owns the 90 Service Principal) 91 1. Object ID (Windows only) - a certificate is used to authenticate WinRM access, and the certificate is injected into 92 the VM using Azure Key Vault. Access to the key vault is protected by an ACL associated with the SPN's ObjectID. 93 Linux does not need nor use a key vault, so there's no need to know the ObjectID. 94 95 You will also need the following. 96 97 1. Subscription ID 98 1. Resource Group 99 1. Storage Account 100 101 Resource Group is where your storage account is located, and Storage 102 Account is where the created packer image will be stored. 103 104 The Service Principal has been tested with the following [permissions](https://azure.microsoft.com/en-us/documentation/articles/role-based-access-control-configure/). 105 Please review the document for the [built in roles](https://azure.microsoft.com/en-gb/documentation/articles/role-based-access-built-in-roles/) 106 for more details. 107 108 * Owner 109 110 > NOTE: the Owner role is too powerful, and more explicit set of roles 111 > is TBD. Issue #183 is tracking this work. Permissions can be scoped to 112 > a specific resource group to further limit access. 113 114 ### Sample Ubuntu 115 116 The following is a sample Packer template for use with the Packer 117 Azure for ARM builder. 118 119 ```json 120 { 121 "variables": { 122 "cid": "your_client_id", 123 "cst": "your_client_secret", 124 "tid": "your_client_tenant", 125 "sid": "your_subscription_id", 126 127 "rgn": "your_resource_group", 128 "sa": "your_storage_account" 129 }, 130 "builders": [ 131 { 132 "type": "azure-arm", 133 134 "client_id": "{{user `cid`}}", 135 "client_secret": "{{user `cst`}}", 136 "subscription_id": "{{user `sid`}}", 137 "tenant_id": "{{user `tid`}}", 138 139 "resource_group_name": "{{user `rgn`}}", 140 "storage_account": "{{user `sa`}}", 141 142 "capture_container_name": "images", 143 "capture_name_prefix": "packer", 144 145 "os_type": "Linux", 146 "image_publisher": "Canonical", 147 "image_offer": "UbuntuServer", 148 "image_sku": "14.04.3-LTS", 149 150 "location": "South Central US", 151 152 "vm_size": "Standard_A2" 153 } 154 ], 155 "provisioners": [ 156 { 157 "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'", 158 "inline": [ 159 "apt-get update", 160 "apt-get upgrade -y", 161 162 "/usr/sbin/waagent -force -deprovision+user && export HISTSIZE=0 && sync" 163 ], 164 "inline_shebang": "/bin/sh -x", 165 "type": "shell" 166 } 167 ] 168 } 169 ``` 170 171 Using the above template, Packer would be invoked as follows. 172 173 > NOTE: the following variables must be **changed** based on your 174 > subscription. These values are just dummy values, but they match 175 > format of expected, e.g. if the value is a GUID the sample is a 176 > GUID. 177 178 ```bat 179 packer build^ 180 -var cid="593c4dc4-9cd7-49af-9fe0-1ea5055ac1e4"^ 181 -var cst="GbzJfsfrVkqL/TLfZY8TXA=="^ 182 -var sid="ce323e74-56fc-4bd6-aa18-83b6dc262748"^ 183 -var tid="da3847b4-8e69-40bd-a2c2-41da6982c5e2"^ 184 -var rgn="My Resource Group"^ 185 -var sa="mystorageaccount"^ 186 c:\packer\ubuntu_14_LTS.json 187 ``` 188 189 Please see the 190 [config_sameples/arm](https://github.com/Azure/packer-azure/tree/master/config_examples) 191 directory for more examples of usage.