0
votes

From an Azure DevOps pipeline, using a self hosted linux build agent running on docker, I get the error below in terraform plan. I tried many things, even running the steps from a bash shell on the build agent: this worked well.

Do you have any suggestion?

2019-09-12T13:55:21.8133489Z ##[debug]Evaluating condition for step: 'Terraform plan'
2019-09-12T13:55:21.8134075Z ##[debug]Evaluating: succeeded()
2019-09-12T13:55:21.8134246Z ##[debug]Evaluating succeeded:
2019-09-12T13:55:21.8134443Z ##[debug]=> True
2019-09-12T13:55:21.8134723Z ##[debug]Result: True
2019-09-12T13:55:21.8134976Z ##[section]Starting: Terraform plan
2019-09-12T13:55:21.8138406Z ==============================================================================
2019-09-12T13:55:21.8138526Z Task         : Run Terraform
2019-09-12T13:55:21.8138605Z Description  : Run a Terraform on the build agent
2019-09-12T13:55:21.8138647Z Version      : 2.4.0
2019-09-12T13:55:21.8138688Z Author       : Peter Groenewegen - Xpirit
2019-09-12T13:55:21.8138772Z Help         : [More Information](https://pgroene.wordpress.com/2016/06/14/getting-started-with-terraform-on-windows-and-azure/)
2019-09-12T13:55:21.8138828Z ==============================================================================
2019-09-12T13:55:21.8347594Z ##[error]The current operating system is not capable of running this task. That typically means the task was written for Windows only. For example, written for Windows Desktop PowerShell.
2019-09-12T13:55:21.8361383Z ##[debug]System.Exception: The current operating system is not capable of running this task. That typically means the task was written for Windows only. For example, written for Windows Desktop PowerShell.
   at Microsoft.VisualStudio.Services.Agent.Worker.TaskRunner.RunAsync()
   at Microsoft.VisualStudio.Services.Agent.Worker.StepsRunner.RunStepAsync(IStep step, CancellationToken jobCancellationToken)
2019-09-12T13:55:21.8365066Z ##[section]Finishing: Terraform plan

The pipelines fails on "terraform plan". Here's the yml:

variables:
  env: 'environment'

steps:
- task: petergroenewegen.PeterGroenewegen-Xpirit-Vsts-Release-Terraform.Xpirit-Vsts-Release-Terraform.Terraform@2
  displayName: 'Terraform plan'
  inputs:
    TemplatePath: '$(System.DefaultWorkingDirectory)/_repository/tf'
    Arguments: 'plan -var-file=$(System.DefaultWorkingDirectory)/_repository/tf/$(env)/$(env).tfvars  '
    InstallTerraform: true
    UseAzureSub: true
    ConnectedServiceNameARM: 'deploy-sco'
    ManageState: true
    SpecifyStorageAccount: true
    StorageAccountResourceGroup: 'rg-terraform'
    StorageAccountRM: sta
    StorageContainerName: terraform
    InitArguments: '-backend-config=$(System.DefaultWorkingDirectory)/_repository/tf/$(env)/$(env).beconf'

The build agent is a docker container, built with the following dockerfile

FROM ubuntu:16.04
ENV DEBIAN_FRONTEND=noninteractive
RUN echo "APT::Get::Assume-Yes \"true\";" > /etc/apt/apt.conf.d/90assumeyes
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates curl jq git iputils-ping libcurl3 libunwind8 netcat libssl-dev unzip wget apt-utils apt-transport-https make binutils gcc lsb-release gnupg
RUN wget -P /tmp/download https://releases.hashicorp.com/terraform/0.12.7/terraform_0.12.7_linux_amd64.zip
RUN wget -P /tmp/download -q https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb
RUN unzip /tmp/download/terraform_0.12.7_linux_amd64.zip -d /tmp/download/
RUN mv /tmp/download/terraform /usr/local/bin
RUN chmod a+x /usr/local/bin/terraform
RUN apt-get install /tmp/download/packages-microsoft-prod.deb
RUN apt-get update
RUN apt-get -y install powershell
RUN wget -P /tmp/download -q https://curl.haxx.se/download/curl-7.65.3.tar.gz
RUN cd /tmp/download; tar xzf curl-7.65.3.tar.gz
RUN cd /tmp/download/curl-7.65.3; ./configure --prefix=/opt/curl-7.65.3 --disable-ipv6 --with-ssl; make; make install
RUN mv /usr/bin/curl /tmp; ln -s /opt/curl-7.65.3/bin/curl /usr/bin/curl
RUN curl -sL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | tee /etc/apt/trusted.gpg.d/microsoft.asc.gpg > /dev/null
RUN AZ_REPO=$(lsb_release -cs); echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" | tee /etc/apt/sources.list.d/azure-cli.list
RUN apt-get update
RUN apt-get install azure-cli
RUN pwsh -c "Install-Module -Name Az -Force"
RUN pwsh -c "Install-Module -Name Azure -Force"

WORKDIR /azp

COPY ./start.sh .
RUN chmod +x start.sh

CMD ["./start.sh"]
1
I don't understand what you're asking. The error message is very clear: The task doesn't support Linux. You can't use it on a Linux agent.Daniel Mann
Hi Daniel, this is a terraform plan, which is compatible with Linux. Moreover, as I wrote, I can replicate the steps by hand from the agent. What I don't understand is why terraform complains, I tried also to set more verbose logs/debug with no success.Marco
Terraform might be compatible with Linux, but the task you have installed to run it is not compatible. There's a difference.Daniel Mann
Hi, how the things going now? Does the below answer could help you? What about trying with the other terroform extension which can compiled with linux agent?Merlin Liang - MSFT
Perfect suggestion, I managed to solve the issue.Marco

1 Answers

1
votes

As what you said, yes, the Terraform plan can be compatible including linux, windows and MacOS. But now, the issue you are facing, is the extension and task you are using which named Run Terraform task can only be executed in the agent which installed on Windows. You can see its doc to know that: Getting started with Terraform on Windows and Azure.

There has another extensions which created by our Microsoft DevLabs and individual developer: Terraform and Terraform Build & Release Tasks. The tasks in these two extensions can all compiled in windows, linux and macOS.

enter image description here

You'd better change to use the tasks which in these two extensions.