【问题标题】:Passing Terraform output to Powershell task in Azure Devosps将 Terraform 输出传递给 Azure Devosps 中的 Powershell 任务
【发布时间】:2021-07-29 06:11:39
【问题描述】:

在 Azure DevOps 中,我们有以下 YAML 管道,它从 CmdLine 任务应用 Terraform 配置。 输出任务应在 Terraform 部署后返回 Data Factory 的 ObjectId。 我想使用该 ObjectId 并将其作为参数传递给下一个 Azure Powershell Task,以便我可以将该 Id 作为成员添加到 AzureADGroup。 如何在下一个 Powershell 任务中使用名为“Terraform output”的步骤的输出?

  - task: CmdLine@2
    displayName: Terraform Apply
    enabled: False
    inputs:
      script: terraform apply -auto-approve -input=false tfplan
      workingDirectory: infrastructure/tf_scripts/dev
  - task: CmdLine@2
    displayName: Terraform output
    enabled: False
    inputs:
      script: |
        terraform output adf_objectid
      workingDirectory: infrastructure/tf_scripts/dev

  - task: AzurePowerShell@4
    displayName: 'Azure PowerShell script: InlineScript'
    inputs:
      azureSubscription: 'a6cb1cd3-8d5e-4db6-8af5-bcb66492d5cc'
      ScriptType: 'InlineScript'
      Inline: |
                $spn=(terraform output adf_objectid)
                Connect-AzureAD -AadAccessToken $aadToken -AccountId $context.Account.Id -TenantId $context.tenant.id -MsAccessToken $graphToken
                Add-AzureADGroupMember -ObjectId xxxxx-xxxxx-xxxxx -RefObjectId $spn
      workingDirectory: wd/scripts/dev
      azurePowerShellVersion: 'LatestVersion'

【问题讨论】:

    标签: azure azure-devops yaml terraform


    【解决方案1】:

    将 Terraform 输出传递给 Azure Devosps 中的 Powershell 任务

    您可以尝试使用 Logging Commandadf_objectid 设置为 azure devops 管道变量:

    echo ##vso[task.setvariable variable=spn]$(terraform output adf_objectid)
    

    查看similar thread 了解一些详细信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-29
      • 2021-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-18
      • 1970-01-01
      • 2021-12-28
      相关资源
      最近更新 更多