Skip to content
This repository has been archived by the owner on Jan 30, 2021. It is now read-only.

Vagrantfile with specified vm_managed_image_id tries to create from a default image #218

Open
shurick81 opened this issue Jul 22, 2018 · 1 comment

Comments

@shurick81
Copy link

Steps to reproduce:

  1. Install all the prerequisites like vagrant and plugin
  2. create a vagrantfile with the following content:
Vagrant.configure('2') do |config|
  config.vm.box = 'azure'

  config.vm.provider :azure do |azure, override|

    # each of the below values will default to use the env vars named as below if not specified explicitly
    azure.tenant_id = ENV['ARM_TENANT_ID']
    azure.client_id = ENV['ARM_CLIENT_ID']
    azure.client_secret = ENV['ARM_CLIENT_SECRET']
    azure.subscription_id = ENV['ARM_SUBSCRIPTION_ID']
    # azure.vm_image = 'env-win2016-dev'
    azure.vm_managed_image_id = '/subscriptions/7bff593e-4ee7-40bb-9d2b-522f196626e5/resourceGroups/CommonRG/providers/Microsoft.Compute/images/env-win2016-dev'
    # azure.vm_vhd_uri = "https://commonstorsouthcentralus.blob.core.windows.net/system/Microsoft.Compute/Images/vmimages/env-win2016-dev-osDisk.5ae67658-0262-405e-8a84-eeaeb4b65507.vhd"
    azure.instance_ready_timeout = 600
    azure.location = 'WestUS2'
    azure.vm_size = 'Standard_DS1_v2'
    azure.vm_operating_system = 'Windows'
    azure.vm_name = 'envdev01'
    azure.vm_password = 'TopSecretPassw0rd'
    azure.admin_username = "OctoAdmin"
    override.winrm.transport = :ssl
    override.winrm.port = 5986
    override.winrm.ssl_peer_verification = false # must be false if using a self signed cert
    override.vm.synced_folder ".", "/vagrant", disabled: true
  end

end
  1. Run vagrant up

Expected result

  1. VM is created based on my image.

Actual result:

  1. Error in console
...
  "response": {
    "body": "{\"status\":\"Failed\",\"error\":{\"code\":\"DeploymentFailed\",\"message\":\"At least one resource deploym
ent operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-debug for usage detai
ls.\",\"details\":[{\"code\":\"Conflict\",\"message\":\"{\\r\\n  \\\"status\\\": \\\"Failed\\\",\\r\\n  \\\"error\\\": {
\\r\\n    \\\"code\\\": \\\"ResourceDeploymentFailure\\\",\\r\\n    \\\"message\\\": \\\"The resource operation complete
d with terminal provisioning state 'Failed'.\\\",\\r\\n    \\\"details\\\": [\\r\\n      {\\r\\n        \\\"code\\\": \\
\"VMExtensionProvisioningTimeout\\\",\\r\\n        \\\"message\\\": \\\"Provisioning of VM extension 'WinRMCustomScriptE
xtension' has timed out. Extension installation may be taking too long, or extension status could not be obtained.\\\"\\
r\\n      }\\r\\n    ]\\r\\n  }\\r\\n}\"}]}}",
    "headers": {
      "cache-control": "no-cache",
      "pragma": "no-cache",
      "content-type": "application/json; charset=utf-8",
      "expires": "-1",
      "vary": "Accept-Encoding",
      "x-ms-ratelimit-remaining-subscription-reads": "14997",
      "x-ms-request-id": "773d3106-b848-4a90-956d-3f978453f623",
      "x-ms-correlation-request-id": "773d3106-b848-4a90-956d-3f978453f623",
      "x-ms-routing-request-id": "WESTEUROPE:20180721T232812Z:773d3106-b848-4a90-956d-3f978453f623",
      "strict-transport-security": "max-age=31536000; includeSubDomains",
      "x-content-type-options": "nosniff",
      "date": "Sat, 21 Jul 2018 23:28:12 GMT",
      "connection": "close",
      "content-length": "525"
    },
    "status": 200
  }
...

My image is Windows based, however, it seems that Vagrant is trying to create a linux one. Here is what I see in deployment template in Azure portal:

...
{
            "type": "Microsoft.Compute/virtualMachines",
            "name": "[parameters('vmName')]",
            "apiVersion": "2016-04-30-preview",
            "location": "[variables('location')]",
            "properties": {
                "hardwareProfile": {
                    "vmSize": "[parameters('vmSize')]"
                },
                "osProfile": {
                    "computerName": "[parameters('vmName')]",
                    "adminUsername": "[parameters('adminUsername')]",
                    "adminPassword": "[parameters('adminPassword')]"
                },
                "storageProfile": {
                    "imageReference": {
                        "publisher": "canonical",
                        "offer": "ubuntuserver",
                        "sku": "16.04.0-LTS",
                        "version": "latest"
                    },
                    "osDisk": {
                        "createOption": "fromImage",
                        "caching": "ReadWrite"
                    },
                    "dataDisks": []
                },
                "networkProfile": {
                    "networkInterfaces": [
                        {
                            "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]"
                        }
                    ]
                }
            },
            "resources": [
                {
                    "type": "Microsoft.Compute/virtualMachines/extensions",
                    "name": "[concat(parameters('vmName'),'/WinRMCustomScriptExtension')]",
                    "apiVersion": "[variables('apiVersion')]",
                    "location": "[resourceGroup().location]",
                    "properties": {
                        "publisher": "Microsoft.Compute",
                        "type": "CustomScriptExtension",
                        "typeHandlerVersion": "1.4",
                        "settings": {
                            "commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -command ', variables('doubleQuote'), '& { $hostname = ', variables('singleQuote'), 'envdev01.WestUS2.cloudapp.azure.com', variables('singleQuote'), '; $Cert = (New-SelfSignedCertificate -CertstoreLocation Cert:/LocalMachine/My -DnsName $hostname).Thumbprint; $transport = New-Item -Path WSMan:/LocalHost/Listener -Transport HTTPS -Address * -CertificateThumbPrint $Cert -Force; cd $transport.PSPath; set-item  ./HostName -value $hostname -force; set-item  ./Port -value 5986 -force; netsh advfirewall firewall add rule name=WinRM_HTTPS dir=in action=allow protocol=TCP localport=5986;  }', variables('doubleQuote'))]"
                        }
                    },
                    "dependsOn": [
                        "[concat('Microsoft.Compute/virtualMachines/', parameters('vmName'))]"
                    ]
                }
            ],
            "dependsOn": [
                "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
            ]
        }
...
@JSchissler
Copy link

Hi,
I have the same problem.
Unfortunately I can't get vagrant to run with a custom image.
Do you have a solution?
Thanks

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

No branches or pull requests

2 participants