通过Terraform执行Dataflow任务时遇404错误:无法打开模板文件
解决Terraform部署Dataflow Flex模板任务的404错误
错误详情
│ 错误:googleapi: Error 404: (d958f8ba4ff671db): 无法打开模板文件: gs://sample_bucket_terraform/data_file., notFound
│
│ 关联资源:google_dataflow_flex_template_job.big_data_job,
│ 位于main.tf第13行,resource "google_dataflow_flex_template_job" "big_data_job"中:
排查与修复步骤
- 修正GCS路径格式:路径末尾多余的
.是无效字符,直接导致文件找不到。将gs://sample_bucket_terraform/data_file.修改为正确路径,比如gs://sample_bucket_terraform/data_file(Flex模板配置文件通常带.json后缀,如gs://sample_bucket_terraform/data_template.json)。 - 验证GCS资源存在性:确认
sample_bucket_terraform存储桶存在,且目标文件已正确上传到对应路径。可通过GCS控制台或执行gsutil stat gs://sample_bucket_terraform/[修正后的文件名]命令验证。 - 检查访问权限:确保Terraform使用的服务账号拥有
storage.objects.get权限,能读取该GCS文件。若使用默认服务账号,需为其添加Storage Object Viewer角色。 - 确认模板文件有效性:目标文件必须是合法的Dataflow Flex模板配置文件(JSON格式),包含
image、sdkInfo等必要字段,避免文件损坏或格式错误。
内容的提问来源于stack exchange,提问作者TEJAS
相关产品推荐
相关产品推荐

