[英]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.