Hello,
I am deploying resource to azure from bitbucket pipeline with terraform code.
when applying terraform plan , i am getting this error. I have no clue how to fix it.
terraform plan -out=tfplan
Planning failed. Terraform encountered an error while generating this plan.
Error: building AzureRM Client: please ensure you have installed Azure CLI version 2.0.79 or newer. Error parsing json result from the Azure CLI: launching Azure CLI: exec: "az": executable file not found in $PATH.
with provider["registry.terraform.io/hashicorp/azurerm"],
on main.tf line 14, in provider "azurerm":
14: provider "azurerm" {
FYI , I have mentioned these in variable section. still it gives me error.
Please suggest me some solution
Hi @Subhasis Tripathy and welcome to the community!
The error indicates that Azure CLI version 2.0.79 or newer is not installed in the build environment.
If your Pipelines builds run on Atlassian infrastructure or with a self-hosted Linux Docker runner, they use Docker containers. For every step of your build, a Docker container starts (the build container) using the image you have specified in your bitbucket-pipelines.yml file. The definition will look like this:
image: atlassian/default-image:4
and it may be defined either at the top of the file (and applies to all steps), or at a step level.
If you want to use a certain tool during your build, it either needs to be preinstalled in the Docker image you use as a build container, or you can install it during the build by adding the necessary commands in your bitbucket-pipelines.yml file in that specific step.
So, you can either use a different Docker image as a build container that has Azure CLI version 2.0.79 or newer preinstalled, or you can add commands in your yml file to install Azure CLI 2.0.79 or newer.
In case the pipelines builds run with a self-hosted Linux Shell, Windows, or MacOS runner, these runners don't use Docker containers, and the builds run directly on the host. Any tools you want to use during the build need to be installed on the host machine.
Please feel free to reach out if you have any questions!
Kind regards,
Theodora
Hello Theodora,
Thanks for giving solution. But still i am facing error while running terraform plan. Here is the code I am using
###############
#
terraform plan
Planning failed. Terraform encountered an error while generating this plan.
Error: building AzureRM Client: please ensure you have installed Azure CLI version 2.0.79 or newer. Error parsing json result from the Azure CLI: launching Azure CLI: exec: "az": executable file not found in $PATH.
with provider["registry.terraform.io/hashicorp/azurerm"],
on main.tf line 14, in provider "azurerm":
14: provider "azurerm" {
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The first step of your pipeline runs on a separate Docker container and it uses the pipe https://bitbucket.org/microsoft/azure-cli-run/src/master/. Please note that AZ_CLI_VERSION is not a valid variable for the pipe and this step won't have any effect on the second step.
The second step that fails is running on a Docker container based on the image hashicorp/terraform:light and this Docker image doesn't have Azure CLI preinstalled.
This Docker image is using Alpine Linux v3.17 and I don't see any details on how to install Azure CLI on Alpine Linux in Azure's official documentation.
I searched online and the following answer to a StackOverflow post was helpful:
I was able to install the latest version of Azzure CLI in a step using hashicorp/terraform:light as follows:
- step:
image: hashicorp/terraform:light
script:
- apk add --no-cache --update python3 py3-pip
- apk add --no-cache --update --virtual=build gcc musl-dev python3-dev libffi-dev openssl-dev cargo make
- pip3 install --no-cache-dir --prefer-binary azure-cli
- apk del build
- az --version
The last command is to check the version and ensure that Azure CLI is installed.
Can you try adding these commands at the beginning of the second step and let me know how it goes?
If you are familiar with Docker, another option would be to build your own custom Docker image, with base image hashicorp/terraform:light, install Azure CLI on that image, and then use it as a build container. You can find more info on building your own custom image here:
Kind regards,
Theodora
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.