I am currently getting the following error in my ADO pipeline when running "packer build". I have set HCP_CLIENT_ID and HCP_CLIENT_SECRET inside my variable group and it is utilizing them to connect to the packer registry but it is saying "access denied" as if my hcp client id and secret are not authorized. I have used the same client credentials on my local and on GitHub actions with no issues during a packer build. Seems to me like there is some api connection blocked on the ADO end or maybe the HCP packer registry end.
Error: HCP: populating iteration failed
Failed to create client connection to artifact registry: status 1: err unable to fetch organization list: Get "https://api.cloud.hashicorp.com:443/resource-manager/2019-12-10/organizations": oauth2: cannot fetch token: 401 Unauthorized Response: {"error":"access_denied","error_description":"Unauthorized"}
trigger:
- 'main'
variables:
- name: packer_file
value: ./test.pkr.hcl
stages:
- stage: packer
jobs:
- job: packer_deploy
timeoutInMinutes: 360
displayName: "Packer-deploy-job"
steps:
- checkout: self
- script: |
sudo apt update
sudo apt upgrade
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install packer
packer --version
name: install
displayName: Install Packer CLI
- script: |
packer init ${{ variables.packer_file }}
packer validate ${{ variables.packer_file }}
name: init_validate
displayName: Packer INIT & validate
- script: |
packer build --force -color=false -on-error=abort ${{ variables.packer_file }}
env:
HCP_API_URL: https://api.hashicorp.cloud
HCP_CLIENT_ID: $(HCP_CLIENT_ID)
HCP_CLIENT_SECRET: $(HCP_CLIENT_SECRET)
HCP_PACKER_BUILD_FINGERPRINT: "run.id.$(Build.BuildId)"
name: build
displayName: Packer Build
I fixed it. I was adding Azure client id and secret mistakenly to HCP_CLIENT_ID and HCP_CLIENT_SECRET. When updated and restarted the system, it started working.