无法在 azure devops 中执行 terraform apply
unable to execute terraform apply in azure devops
我正在尝试通过 azure devops 执行 terraform 脚本。我无法通过不同的任务申请和验证,尽管 terraform 计划成功 terraform 申请失败
##[error]TypeError: Cannot read property 'includes' of null
这是我正在使用的 terraform 任务。我尝试了两个不同的任务
1.
- task: ms-devlabs.custom-terraform-tasks.custom-terraform-release-task.TerraformTaskV2@2
displayName: 'Terraform : apply -auto-approve'
inputs:
command: apply
workingDirectory: '$(System.DefaultWorkingDirectory)/Terraform'
commandOptions: '-auto-approve'
environmentServiceNameAzureRM: 'ps-vs-sc'
backendAzureRmResourceGroupName: '$(rgname)'
backendAzureRmStorageAccountName: $(strname)
backendAzureRmContainerName: $(tfContainer)
backendAzureRmKey: '$(storagekey)'
- task: TerraformTaskV2@2
inputs:
provider: 'azurerm'
command: 'apply'
workingDirectory: '$(System.DefaultWorkingDirectory)/Terraform'
commandOptions: '--auto-approve'
environmentServiceNameAzureRM: 'ps-vs1-sc'
这是我的地形文件
provider "azurerm" {
features {}
}
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "2.74.0"
}
}
}
data "azurerm_api_management" "example" {
name = var.apimName
resource_group_name = var.rgName
}
resource "azurerm_api_management_api" "example" {
name = var.apName
resource_group_name = var.rgName
api_management_name = var.apimname
revision = "1"
display_name = "Example API1"
path = "example1"
protocols = ["https"]
service_url = "http://123.0.0.0:8000"
subscription_required = true
import {
content_format = "openapi+json"
content_value = #{storageaccountlink}#
}
terraform 文件看起来不错,没有问题。你能检查一下你是否使用了 Azure Service Principal 方法吗?
服务主体被认为是 CI/CD 管道中 DevOps 的良好实践。它用作在您的 Azure 订阅中对您进行身份验证的身份,以允许您部署相关的 Terraform 代码。
您可以按照此文档获取 Deploying Terraform using Azure DevOps.
的详细演示
如果您已经执行了上述步骤但仍然面临同样的问题,那么问题出在 Terraform“”中的“配置目录”设置验证并应用 ' 发布管道步骤。将其更改为包含构建工件的路径将解决此问题。还要检查您提供的 workingDirectory 是否正确。
也提出了类似但不相同的问题here,检查它是否解决了问题。
我在此处添加了整个管道详细信息,仅供参考 - https://gist.github.com/PrakashRajanSakthivel/e6d8e03044a51d74803499aca75a258c
我正在尝试通过 azure devops 执行 terraform 脚本。我无法通过不同的任务申请和验证,尽管 terraform 计划成功 terraform 申请失败
##[error]TypeError: Cannot read property 'includes' of null
这是我正在使用的 terraform 任务。我尝试了两个不同的任务
1.
- task: ms-devlabs.custom-terraform-tasks.custom-terraform-release-task.TerraformTaskV2@2
displayName: 'Terraform : apply -auto-approve'
inputs:
command: apply
workingDirectory: '$(System.DefaultWorkingDirectory)/Terraform'
commandOptions: '-auto-approve'
environmentServiceNameAzureRM: 'ps-vs-sc'
backendAzureRmResourceGroupName: '$(rgname)'
backendAzureRmStorageAccountName: $(strname)
backendAzureRmContainerName: $(tfContainer)
backendAzureRmKey: '$(storagekey)'
- task: TerraformTaskV2@2
inputs:
provider: 'azurerm'
command: 'apply'
workingDirectory: '$(System.DefaultWorkingDirectory)/Terraform'
commandOptions: '--auto-approve'
environmentServiceNameAzureRM: 'ps-vs1-sc'
这是我的地形文件
provider "azurerm" {
features {}
}
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "2.74.0"
}
}
}
data "azurerm_api_management" "example" {
name = var.apimName
resource_group_name = var.rgName
}
resource "azurerm_api_management_api" "example" {
name = var.apName
resource_group_name = var.rgName
api_management_name = var.apimname
revision = "1"
display_name = "Example API1"
path = "example1"
protocols = ["https"]
service_url = "http://123.0.0.0:8000"
subscription_required = true
import {
content_format = "openapi+json"
content_value = #{storageaccountlink}#
}
terraform 文件看起来不错,没有问题。你能检查一下你是否使用了 Azure Service Principal 方法吗?
服务主体被认为是 CI/CD 管道中 DevOps 的良好实践。它用作在您的 Azure 订阅中对您进行身份验证的身份,以允许您部署相关的 Terraform 代码。 您可以按照此文档获取 Deploying Terraform using Azure DevOps.
的详细演示如果您已经执行了上述步骤但仍然面临同样的问题,那么问题出在 Terraform“”中的“配置目录”设置验证并应用 ' 发布管道步骤。将其更改为包含构建工件的路径将解决此问题。还要检查您提供的 workingDirectory 是否正确。
也提出了类似但不相同的问题here,检查它是否解决了问题。
我在此处添加了整个管道详细信息,仅供参考 - https://gist.github.com/PrakashRajanSakthivel/e6d8e03044a51d74803499aca75a258c