【发布时间】:2019-03-07 10:01:16
【问题描述】:
我正在尝试从配置 YAML 的 Azure DevOps 管道中的 PowerShell 步骤运行 Terraform,但我无法让它接受我的咒语:它不是初始化状态,而是打印使用说明并退出.
我已经为-backend-config 参数尝试了多种带/不带引号的组合,但似乎没有任何效果。
如果我将脚本剪切并粘贴到本地的ps1 文件中并运行它,一切都会按预期运行。
我在这里的./terraform.exe init 咒语有什么问题?
以下是完整的管道配置:
pool:
vmImage: 'win1803'
steps:
- powershell: |
# Download the Terraform executable into the current directory
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$url = 'https://releases.hashicorp.com/terraform/0.11.8/terraform_0.11.8_windows_amd64.zip'
$output = "$PSScriptRoot\terraform.zip"
Write-Host "Downloading from $url to $output"
$wc = New-Object System.Net.WebClient
$wc.DownloadFile($url, $output)
Expand-Archive $output -DestinationPath . -Force
Get-ChildItem
displayName: 'Download Terraform executable'
- powershell: |
# Create a config file with secrets, and initialize Terraform
"storage_account_name = `"$env:TerraformStateAccountName`"" | Out-File "./terraform-state.secrets.tfvars" -Append
"access_key = `"$env:TerraformStateAccountKey`"" | Out-File "./terraform-state.secrets.tfvars" -Append
"container_name = `"$env:TerraformStateContainer`"" | Out-File "./terraform-state.secrets.tfvars" -Append
./terraform.exe init -backend-config=./terraform-state.secrets.tfvars -input=false
env:
TerraformStateAccountName: $(Terraform.State.StorageAccountName)
TerraformStateAccountKey: $(Terraform.State.StorageAccountKey)
TerraformStateContainer: $(Terraform.State.ContainerName)
displayName: 'Initialize Terraform'
【问题讨论】:
-
究竟打印了什么?
-
@4c74356b41:与我在本地运行
./terraform.exe init -foo时的情况相同,除了在本地我得到最后一行说flag provided but not defined: -foo而在构建服务器上我根本没有收到任何消息。 -
@4c74356b41:正如我所写,它并不完全相同。 有一个例外:本地输出的最后一行
./terraform.exe init -foo不包含在构建服务器上。 (如果你想粗鲁,至少不要为了粗鲁而把话放在我嘴里。)
标签: powershell azure-devops terraform azure-pipelines