aledeniz
aledeniz

Reputation: 463

Running Packer as part of the Build Immutable Image task on Azure Pipelines returns ResourceNotFound error

Running Packer as part of the Build Immutable Image task on Azure Pipelines returns ResourceNotFound error.

This is the log:

[command]d:\a\_temp\1560443280032\packer\packer.exe --version
1.2.4
.. OMISSIS ..
Running packer fix command
[command]d:\a\_temp\1560443280032\packer\packer.exe fix -validate=false d:\a\_temp\1560443280032\default.managed.windows.template-builderUpdated.json
{
.. OMISSIS ..
}

Running packer validate command to ensure template is valid
[command]d:\a\_temp\1560443280032\packer\packer.exe validate -var-file=d:\a\_temp\1rmtqjuiul6pfzkv7busvvaemi.json -var-file=d:\a\_temp\uhd7du4kq3yqnb8ow5d4jwcdi.json d:\a\_temp\1560443280032\default.managed.windows.template-builderUpdated-fixed.json
Template validated successfully.
Running packer build command. Waiting for it to finish...
[command]d:\a\_temp\1560443280032\packer\packer.exe build -force -color=false -var-file=d:\a\_temp\4ehhcm7h7b87enzmq6zz7iudi.json -var-file=d:\a\_temp\su5hmxk6n2ly2vs00pundygb9.json d:\a\_temp\1560443280032\default.managed.windows.template-builderUpdated-fixed.json

==> azure-arm: Running builder ...

    azure-arm: Creating Azure Resource Manager (ARM) client ...

==> azure-arm: ERROR: -> ResourceNotFound : The Resource 'Microsoft.Compute/images/COMPUTERNAME' under resource group 'RESOURCEGROUP' 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

==> Builds finished but no artifacts were created.

##[error]Error: d:\a\_temp\1560443280032\packer\packer.exe failed with return code: 1

The execution stops quite early, it takes really only 20 seconds to reach the error (the working tasks would take around 30 minutes).

Upvotes: 0

Views: 1415

Answers (1)

aledeniz
aledeniz

Reputation: 463

It turns out the service principal created while configuring the Build Immutable Image task is configured as contributor only in the specific resource group selected during the task configuration (the one holding the storage account used by the task).

Granting contributor role to the service principal name at the subscription level fix the issue.

Running the task, we may discover that this is because during the execution, a new temporary resource group is created, and therefore the service principal requires contributor rights (or some subset thereof) to the entire subscription.

It is an interesting choice, as this resource group is deleted at the end of the task.

Upvotes: 3

Related Questions