簡體   English   中英

通過 azure devops 中的管道將 terraform 部署到 azure

[英]Deploy terraform to azure through a pipeline in azure devops

我已經從 azure cli 本地部署 terraform 到 azure 到成功,所以我知道 TF 正在工作我現在正在嘗試構建一個管道來自動化這個過程......

Error: Error building ARM Config: obtain subscription(xxxxxx) from Azure CLI: Error parsing json result from the Azure CLI: Error waiting for the Azure CLI: exit status 1

當 init 在管道中運行時會出現此錯誤。

這就是管道的樣子……

pool:
  vmImage: ubuntu-latest

stages :
  - stage: validate
    jobs:
    - job: validate
      continueOnError: false
      steps:
      - task: ms-devlabs.custom-terraform-tasks.custom-terraform-installer-task.TerraformInstaller@0
        displayName: 'install'
        inputs:
          terraformVersion: '0.14.10'
      
      - bash: echo $(ls -latR)
        
      - task: TerraformTaskV1@0
        displayName: 'init'
        inputs:
          provider: 'azurerm'
          command: 'init'
          workingDirectory: "$(System.DefaultWorkingDirectory)"
          backendServiceArm: 'Service-Fabric'
          backendAzureRmResourceGroupName: 'fvs-uks-sf-rg-02'
          backendAzureRmStorageAccountName: 'fvsukssfstorage'
          backendAzureRmContainerName: 'fvs-uks-sf-backend01'
          backendAzureRmKey: 'terraform.tfstate'
              
      - task: TerraformTaskV1@0
        displayName: 'validate'
        inputs:
         provider: 'azurerm'
         command: 'validate'

      - task: TerraformTaskV1@0
        displayName: 'plan'
        inputs:
          provider: 'azurerm'
          command: 'plan'
          workingDirectory: "$(System.DefaultWorkingDirectory)"
          environmentServiceNameAzureRM: 'test'
          environmentServiceNameAWS: 'AWS-Azure-VPN'

這就是 backend.tf 的樣子……

provider "azurerm" {
  alias   = "hub"
  subscription_id = "xxxxxxx"
  features {}
}

provider "azurerm" {
  features {}
}

terraform {
  backend "azurerm" {
    subscription_id      = "xxxxxx"
    resource_group_name  = "xxxxxx"
    storage_account_name = "xxxxxx"
    container_name       = "xxxxxx"
    key                  = "terraform.tfstate"
  }
}

我還通過服務主體建立了到 azure 的服務連接,當驗證連接成功時。

任何幫助是極大的贊賞

通過 azure devops 中的管道將 terraform 部署到 azure

這個問題應該和授權有關。

當我們使用服務連接進行授權時,它使用服務主體而不是用戶名/密碼來進行身份驗證。

然后根據terraform 文檔

如果您使用服務主體進行身份驗證,則它必須具有讀取和寫入所有應用程序以及登錄和讀取 Windows Azure Active Directory API 中的用戶配置文件的權限

請嘗試為您的委托人添加 API 權限,用於創建服務連接:

在此處輸入圖像描述

導航到 Azure 門戶和 select 應用程序注冊刀片中的 Azure Active Directory 概述。 找到您注冊的應用程序並單擊其顯示名稱來管理它。

Go 到應用程序的 API 權限刀片,然后單擊“添加權限”按鈕。 在打開的窗格中,select“Azure Active Directory Graph”(在 Supported Legacy APIs 子標題下)。 不要 select“Microsoft Graph”,因為提供程序當前不使用此 API。

為權限類型選擇“應用程序權限”,然后檢查您要分配的權限。 您需要的權限取決於您要使用 Terraform 管理的目錄對象。 我們建議以下權限:

Application.ReadWrite.All

Directory.ReadWrite.All

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM