Azure Pipelines terraform init -backend-config 抛出退出代码 127

Azure Pipelines terraform init -backend-config throwing exit code 127

拥有用于 Terraform 规划和部署的简单管道

当 运行 通过模板在我的管道中初始化 terraform 时出现错误(退出代码 127)

这是包含初始化步骤的模板

steps:
  - task: Bash@3
    displayName: 'Terraform Init'
    env:
      ARM_CLIENT_ID: $(AZURE_CLIENT_ID)
      ARM_CLIENT_SECRET: $(AZURE_CLIENT_SECRET)
      ARM_SUBSCRIPTION_ID: $(AZURE_SUBSCRIPTION_ID)
      ARM_TENANT_ID: $(AZURE_TENANT_ID)
    inputs:
      targetType: 'inline'
      workingDirectory: $(System.DefaultWorkingDirectory)
      script: |
        set -euo pipefail
        
        echo "Initialize"
        terraform init \
            -input=false \
            -backend-config="resource_group_name=${TF_STORAGE_RG}" \ 
            -backend-config="storage_account_name=${TF_STORAGE_ACCOUNT}" \
            -backend-config="container_name=${TF_STORAGE_BLOB_CONTAINER}" \
            -backend-config="key=${TF_STORAGE_BLOB_NAME}" 
    
     
        terraform validate
    
       
        terraform -v
        terraform providers

我将值存储在管道可访问的变量组中

但我遇到了错误

Terraform initialized in an empty directory!

The directory has no Terraform configuration files. You may begin working
with Terraform immediately by creating Terraform configuration files.
/home/vsts/work/_temp/d3a0a3ba-04aa-4b39-8c4a-78045790fbe4.sh: line 8: -backend-config=storage_account_name="statebucket": command not found
##[error]Bash exited with code '127'.
Finishing: Terraform Init

努力理解为什么它向我抛出 'command not found' 错误。有什么想法吗?

在 ${TF_STORAGE_RG} 之后的“\”之后的行尾有一个 space。见下文 - 如果我 运行 a sed 删除行尾的 space,“找不到命令”错误就会消失。我得到了一个不同的错误,但这是一个不同的问题。

$ cat doit.sh
export TF_STORAGE_RG=a
export TF_STORAGE_ACCOUNT=b
export TF_STORAGE_BLOB_CONTAINER=c
export TF_STORAGE_BLOB_NAME=d

terraform init \
        -input=false \
        -backend-config="resource_group_name=${TF_STORAGE_RG}" \
        -backend-config="storage_account_name=${TF_STORAGE_ACCOUNT}" \
        -backend-config="container_name=${TF_STORAGE_BLOB_CONTAINER}" \
        -backend-config="key=${TF_STORAGE_BLOB_NAME}"

$ ./doit.sh
Too many command line arguments. Did you mean to use -chdir?
./doit.sh: line 10: -backend-config=storage_account_name=b: command not found

$ sed -i 's/ $//g' doit.sh
$ ./doit.sh

Initializing the backend...
╷
│ Error: Failed to get existing workspaces: Error retrieving keys for Storage Account "b": storage.AccountsClient#ListKeys: Invalid input: autorest/validation: validation failed: parameter=accountName constraint=MinLength value="b" details: value length must be greater than or equal to 3