riezebosch / vsts-tasks-packer

MIT License
15 stars 7 forks source link

Resource not found (for image I'm trying to create) #8

Closed GarethOates closed 5 years ago

GarethOates commented 5 years ago

I have a packer json file and a Packer build task defined in Azure DevOps, to use this file, but for some reason, the managed_image_name I'm trying to create, isn't being created because the task is saying it can't be found. Which is true, because I'm trying to build it.

I've tested my script locally and it works, however when running via the task in Azure DevOps, it won't get very far at all.

==> azure-arm: Getting tokens using client secret
    azure-arm: Creating Azure Resource Manager (ARM) client ...
==> azure-arm: ERROR: -> ResourceNotFound : The Resource 'Microsoft.Compute/images/SRF_Selenium_Image' under resource group 'Packer' was not found.
==> azure-arm:
==> azure-arm: resources.GroupsClient#CheckExistence: Failure responding to request: StatusCode=403 -- Original Error: autorest/azure: error response cannot be parsed: "" error: EOF
Build 'azure-arm' errored: resources.GroupsClient#CheckExistence: Failure responding to request: StatusCode=403 -- Original Error: autorest/azure: error response cannot be parsed: "" error: EOF

==> Some builds didn't complete successfully and had errors:
--> azure-arm: resources.GroupsClient#CheckExistence: Failure responding to request: StatusCode=403 -- Original Error: autorest/azure: error response cannot be parsed: "" error: EOF

Here is my packer-test.json file, which is the template I'm trying to use.

{
    "builders": [
        {
            "client_id": "{{user `client_id`}}",
            "client_secret": "{{user `client_secret`}}",
            "subscription_id": "{{user `subscription_id`}}",
            "tenant_id": "{{user `tenant_id`}}",

            "type": "azure-arm",
            "managed_image_resource_group_name": "Packer",
            "managed_image_name": "SRF_Selenium_Image",

            "os_type": "Windows",
            "image_publisher": "MicrosoftWindowsServer",
            "image_offer": "WindowsServer",
            "image_sku": "2019-Datacenter",

            "communicator": "winrm",
            "winrm_use_ssl": "true",
            "winrm_insecure": "true",
            "winrm_timeout": "3m",
            "winrm_username": "packer",

            "location": "North Europe",
            "vm_size": "Standard_DS2_v2"
        }
    ],

    "provisioners": [
        {
            "type": "powershell",
            "inline": ["Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))"]
        },
        {
            "type": "powershell",
            "script": "Packer/scripts/install-software.ps1"
        },
        {
            "type": "powershell",
            "script": "Packer/scripts/provision.ps1"
        }
    ]
}

And the yaml in my azure pipelines yml file is as follows. The Packer service definition for Azure has access to the 'Packer' resource group, which is already present.

- task: Packer@1
  inputs:
    connectedServiceType: 'azure'
    azureSubscription: 'Packer'
    templatePath: 'Packer/packer-test.json'
    command: 'build'

I saw the 403 status code so I went and double checked that the Service Endpoints were still working and ended up creating new ones just to be extra sure.

Any idea why it's not working? Like I say, I can run the template locally without error.

GarethOates commented 5 years ago

This was a permissions problem at my end. My service principal only had access to work within Packer resource group so I had to remove the 'location' parameter and instead set the 'build_resource_group_name' to be Packer.

tlunsfordCXP commented 3 months ago

This was a permissions problem at my end. My service principal only had access to work within Packer resource group so I had to remove the 'location' parameter and instead set the 'build_resource_group_name' to be Packer.

Thank you so much for your follow-up answer. I was very much stuck trying to figure it out.