powershell - 在 Azure DevOps Pipeline 中从 PowerShell 运行 Terraform
问题描述
我正在尝试从配置 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'
解决方案
推荐阅读
- ubuntu - gunicorn 无法启动烧瓶项目 ec2 ubuntu
- gcc - gcc 交叉编译 -mips1 不生成 MIPS-I
- mysql - 无法在 WSL 中成功安装 mysql-server
- javascript - null 不是对象(正在评估 'document.getElementById('logout-form').submit') - 为什么会出现此错误?
- powershell - 如何使用 Powershell 递归多次移动文件?
- apache-nifi - NiFi - 提高 QueryDatabaseTable 性能以超越 Sqoop
- c - 使用 c 图形的赛车游戏
- java - Firebase 实时数据库非常高的下载使用率
- pandas - AttributeError: 'RangeIndex' 对象没有属性 'stop'
- instagram - 是否有 LinkedIn 和 Instagram API 来获取我的联系人并向他们发送消息?