简体   繁体   English

从terraform代码中的Azure DevOps的现有项目中获取存储库id

[英]To get the repository id from an existing project of Azure DevOps in terraform code

I need to get the repository id of an existing project to work on that repo.我需要获取现有项目的存储库 ID 才能处理该存储库。 There seems no other way than using Azure DevOps REST API.除了使用 Azure DevOps REST API 似乎没有其他方法。

I tried to utilize the REST API to get the repo id in my terraform code:我试图利用 REST API 在我的 terraform 代码中获取 repo id:

data "http" "example" {
  url = "https://dev.azure.com/{organization}/{project}/_apis/git/repositories?api-version=6.0"

  request_headers = {
    "Authorization" = "Basic ${base64encode("PAT:${var.personal_access_token}")}"
  }
}

output "repository_id" {
  value = data.http.example.json.value[0].id
}

It yields error while I was running terraform plan:当我运行 terraform 计划时出现错误:

Error: Unsupported attribute
line 29, in output "repository_id":
29:   value = data.http.example.json.value[0].id

I tried also with jsondecode (jq is already installed):我也尝试过使用 jsondecode(已经安装了 jq):

resource "null_resource" "example" {
  provisioner "local-exec" {
    command = "curl -s -H 'Authorization: Bearer ${var.pat}' https://dev.azure.com/{organization}/{project}/_apis/git/repositories?api-version=6.0 | jq '.value[0].id'"
    interpreter = ["bash", "-c"]
  }
}
output "repo_id" {
  value = "${jsondecode(null_resource.example.stdout).id}"
}

That did not work either!!那也不管用!!

Azure DevOps REST API works fine, I just cannot fetch the value from the responce into terraform! Azure DevOps REST API 工作正常,我只是无法从响应中获取值到 terraform 中! What would be the right code or can it be done without using REST API!什么是正确的代码,或者可以在不使用 REST API 的情况下完成!

Thank you!谢谢!

To proper way to interact with external API and return its output to TF is through external data source .与外部 API 交互并将其 output 返回给 TF 的正确方法是通过外部数据源 TF docs linked provide example of how to use and create such a data source.链接的 TF 文档提供了如何使用和创建此类数据源的示例。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Terraform CDKTF:如何在现有的 terraform 项目中使用/导入 CDKTF 代码? - Terraform CDKTF: How to use/import CDKTF code in existing terraform project? Azure DevOps 管道无法找到可执行文件:“terraform” - Azure DevOps Pipeline unable to locate executable file: 'terraform' 连接 AAD 后不再能够在 Azure Devops 中看到现有项目 - No longer able to see existing projects in Azure Devops after connecting AAD 过滤 azure terraform backend_address_pool 输出,其中后端池的名称并获取 ID。? - Filter azure terraform backend_address_pool outputs, where name of backend pool and get the id.? 在 Azure DevOps Repos 上拆分大型软件项目 - Split large Software Project on Azure DevOps Repos 从 Azure DevOps 存储库导入时,go 获取私有仓库失败。 - go get private repo fails due to missing .git when importing from Azure DevOps repositories 使用 ssh 配置从 azure devops 克隆 - Cloning from azure devops using ssh config 我想创建一个 devops 管道以使用 Azure 创建我的资源 Terraform - I want to create a devops pipeline to create my resources in Azure using Terraform 如何使用应用程序 ID(服务主体)的令牌向 Azure Devops 进行身份验证? - How to authenticate to Azure Devops by using token of an Application ID(service principal)? Azure Devops - 在不分配项目集合管理员的情况下将用户添加到组织 - Azure Devops - Add users to organization without assigning project collection administrator
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM