azure-devops - 如何将双引号字符串列表作为天蓝色管道变量输入传递给 terraform 任务?
问题描述
我正在尝试将字符串列表作为 azure 管道变量传递给 terraform 任务。
我有一个为管道创建的变量,称为这样,ips = [\"1.1.1.1\", \"2.2.2.2\"]
我可以在 azure 管道中使用$(ips)
我想通过官方 terraform 文档中提到的这个变量:
toterraform apply -var='image_id_list=["ami-abc123","ami-def456"]'
the terraform plan task
这是我的 yaml 地形计划部分:
- task: TerraformTaskV1@0
inputs:
provider: 'azurerm'
command: 'plan'
commandOptions: '--var-file variables/$(Build.SourceBranchName)/$(Build.SourceBranchName).tfvars -var=''allowips=$(ips)'''
environmentServiceNameAzureRM: $(linked_service)
displayName: 'Terraform plan'
当管道运行时,它在 terraform plan 步骤失败并出现错误 -
terraform plan --var-file variables/dev/dev.tfvars -var='allowips=[ \1.1.1.1", "2.2.2.2" ]'
stat \1.1.1.1", "2.2.2.2" ]': no such file or directory
##[error]Error: The process '/opt/hostedtoolcache/terraform/0.12.28/x64/terraform' failed with exit code 1
我还尝试了各种组合来声明 azure 管道变量,例如:
ips = ["\"1.1.1.1\", \"2.2.2.2"\]
这也给出了同样的错误 -
terraform plan --var-file variables/dev/dev.tfvars -var='allowips=[ "1.1.1.1", "2.2.2.2" ]'
stat "1.1.1.1", "2.2.2.2" ]': no such file or directory
##[error]Error: The process '/opt/hostedtoolcache/terraform/0.12.28/x64/terraform' failed with exit code 1
我尝试了很多在commandOptions
值和ips
变量上设置引号或双引号的组合,但我得到了相同的错误(或有效的 terraforms 错误)。
似乎 azure 变量中的第一个双引号似乎引起了一些问题。非常感谢任何关于如何将双引号字符串列表作为天蓝色管道变量输入传递给 terraform 任务的指针。谢谢!
编辑 -
我直接在 yaml 中硬编码了这些值,但仍然出现错误。
commandOptions: '--var-file variables/$(Build.SourceBranchName)/$(Build.SourceBranchName).tfvars -var=''allowips=[\"1.1.1.1\", \"2.2.2.2\"]'''
它基本上不接受 ip 值并要求手动输入:
/opt/hostedtoolcache/terraform/0.12.28/x64/terraform plan --var-file variables/dev/dev.tfvars -var='allowips=[\1.1.1.1", "2.2.2.2"]'
var.allowips
Enter a value:
同样,第一个双引号似乎存在问题。
解决方案
今天我处理了一个类似的问题,这个答案对我帮助很大。
简而言之,您应该将变量定义ips
为["\"1.1.1.1\"", "\"2.2.2.2\""]
,而 terraform plan 任务需要将变量取为以下-var=ips=$(ips)
。
希望这可以帮助遇到类似问题的任何人。
推荐阅读
- javascript - 我们会为仅从缓存中读取(Cloud FireStore)支付(成本)吗?
- javascript - 如何更新多选并让它在 Chrome 中实际显示新选项
- python - 正则表达式从列表中提取项目
- java - 将 txt 行放入不同的数组或数组列表中
- python - 根据字典 Python 的键值检查列表中的值
- c++ - 关于在转换运算符中使用显式关键字的警告
- javascript - 为什么cookie更好地与服务器通信?
- hybris - Spartacus 是否支持 CMS 页面限制?
- c - 如何通过查看行中的属性之一来对 c 中的文件的行进行排序?
- macos - 在 Mac vim 上,如何将光标更改为闪烁块?