azure 您所在的位置:网站首页 天蓝色字符 azure

azure

2024-07-12 11:34| 来源: 网络整理| 查看: 265

我正在尝试将字符串列表作为 azure 管道变量传递给 terraform 任务。

我为管道创建了一个名为 ips = [\"1.1.1.1\",\"2.2.2.2\"] 的变量,我可以在 azure 管道中使用$(ips)

我想按照官方 terraform 文档中提到的 here 传递这个变量: terraform apply -var='image_id_list=["ami-abc123","ami-def456"]' 到 terraform 计划任务

这是我在 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 计划步骤失败并出现错误 -

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 变量上设置引号或双引号的组合,但我得到了相同的错误(或有效地形错误)。

似乎 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:

第一个双引号似乎也有问题。

最佳答案

今天我处理了一个类似的问题和this answer对我帮助很大。

简而言之,您应该将变量ips定义为["\"1.1.1.1\"", "\"2.2.2.2\""],而 terraform plan 任务需要将变量取为如下-var=ips=$(ips)。

希望这对遇到类似问题的人有所帮助。

关于azure-devops - 如何将双引号字符串列表作为天蓝色管道变量输入传递给 Terraform 任务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64408064/



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有