You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Terraform HTTP Provider下载Azure DevOps文件失败求助

解决Terraform通过HTTP下载Azure DevOps仓库文件的404问题

正确的URL格式

要直接获取仓库文件的原始内容,必须使用Azure DevOps的原始文件URL,正确格式如下:

https://dev.azure.com/<organization>/<project>/_git/<repository>/raw/test.txt?ref=main

参数说明:

  • <organization>:替换为你的Azure DevOps组织名称
  • <project>:替换为目标项目名称
  • <repository>:替换为目标仓库名称
  • test.txt:根目录下的目标文件名(如果文件在子目录,路径写/subfolder/test.txt)
  • ref=main:指定文件所在分支,按需替换为其他分支名

正确的授权头写法

Azure DevOps的Basic认证规则:

  • 用户名可留空,密码为你的PAT
  • 需将":" + PAT组合后进行Base64编码(冒号不可省略,前面无内容)

对应的Terraform代码片段:

request_headers = {
  Authorization = "Basic ${base64encode(":你的PAT内容")}"
}

完整可运行的Terraform代码

provider "http" {}

data "http" "file" {
  url = "https://dev.azure.com/<organization>/<project>/_git/<repository>/raw/test.txt?ref=main"

  request_headers = {
    Authorization = "Basic ${base64encode(":你的PAT内容")}"
  }
}

resource "local_file" "fchiertest" {
  content  = data.http.file.response_body
  filename = "${path.root}/test.txt"
}

错误原因说明

  • 你之前使用的URL是仓库网页路径,而非原始文件的直接访问地址,导致返回404
  • 授权头若仅填写PAT不带前置冒号,会触发认证失败,部分场景下Azure DevOps会返回404而非401,加剧排查难度

内容的提问来源于stack exchange,提问作者Frédéric De Lène Mirouze

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 19:22:47