【发布时间】:2020-09-12 00:02:01
【问题描述】:
我有一个列表,其中包含地址前缀,例如 192.168.1.0/24
$listOfSubnetsToBeCreated = @()
Write-Host "##vso[task.setvariable variable=availableSubnetList]$listOfSubnetsToBeCreated"
在 powershell 中创建并转移到我已经在 Azure Devops 中定义的 azure devops 管道变量。 我正在使用这个在运行时设置的变量
terraform apply -var="availableSubnetList=$(availableSubnetList)"
在我的 Terraform 任务中创建子网。下面是 tf 脚本:
variable "availableSubnetList" {
type = list(string)
default = [""]
}
resource "azurerm_subnet" "Subnet-lab" {
count = var.project_subnet_number
name = join("-", ["${var.LabRGName}","subnet", "${count.index + 1}"])
resource_group_name = var.AdminRGName
virtual_network_name = var.lab_vnet
address_prefix = var.availableSubnetList[count.index]
}
当我执行管道时,terraform apply 任务出现以下错误:
2020-05-25T14:39:52.5509261Z [0m on <value for var.availableSubnetList> line 1:
2020-05-25T14:39:52.5510090Z (source code not available)
2020-05-25T14:39:52.5510378Z
2020-05-25T14:39:52.5510814Z This character is not used within the language.
2020-05-25T14:39:52.5511149Z [0m[0m
2020-05-25T14:39:52.5511412Z [31m
2020-05-25T14:39:52.5512135Z [1m[31mError: [0m[0m[1mInvalid expression[0m
2020-05-25T14:39:52.5512438Z
2020-05-25T14:39:52.5512833Z [0m on <value for var.availableSubnetList> line 1:
2020-05-25T14:39:52.5513301Z (source code not available)
2020-05-25T14:39:52.5513582Z
2020-05-25T14:39:52.5513977Z Expected the start of an expression, but found an invalid expression token.
2020-05-25T14:39:52.5514566Z [0m[0m
Afaik,Azure Devops 中的变量是字符串。您对如何使用 Azure Devops 将 powershell 列表正确传输到 terraform 有任何想法吗?
【问题讨论】:
标签: azure powershell azure-devops terraform terraform-provider-azure