gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 07:03:33 24 4
gpt4 key购买 nike

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

通过模板在管道中运行 terraform init 时出现错误(退出代码 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

很难理解为什么它向我抛出“找不到命令”错误。有什么想法吗?

最佳答案

${TF_STORAGE_RG} 后面的“\”后面的行末尾有一个空格。请参见下文 - 如果我运行 sed 来删除行末尾的空格,“找不到命令”错误就会消失。我收到了不同的错误,但这是一个不同的问题。

$ 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

关于Azure Pipelines terraform init -backend-config 抛出退出代码 127,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71861864/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com