google-cloud-platform - 使用 Terraform 部署数据流
问题描述
我正在尝试在 GCloud 中使用 Terraform 部署数据流模板。
有几个教程包含一些 terraform 代码。有 2 个选项:使用如下链接的模块或使用如下链接的资源
使用这两个选项我有以下错误:
Error: googleapi: got HTTP response code 502 with body: <!DOCTYPE html>
<html lang=en>
<meta charset=utf-8>
<meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
<title>Error 502 (Server Error)!!1</title>
<style>
*{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
</style>
<a href=//www.google.com/><span id=logo aria-label=Google></span></a>
<p><b>502.</b> <ins>That’s an error.</ins>
<p>The server encountered a temporary error and could not complete your request.<p>Please try again in 30 seconds. <ins>That’s all we know.</ins>
on .terraform\modules\dataflow-job\terraform-google-modules-terraform-google-dataflow-722fc1d\main.tf line 17, in resource "google_dataflow_job" "dataflow_job":
17: resource "google_dataflow_job" "dataflow_job" {
我尝试从本地计算机以及 GCP 内的云外壳运行。
问题应该出在数据流模块中,因为我还尝试创建其他资源,例如存储桶和计算引擎,并且它可以正常工作。
在我运行 terraform 脚本之前,数据流模板存储在存储桶中。
地形版本:0.12.19
编码:
主文件
variable "project_id" {}
<...>
provider "google" {
version = "~> 2.8.0"
region = var.region
}
resource "google_dataflow_job" "dataflow_job" {
project = var.project_id
region = var.region
zone = "${var.region}-a"
name = var.project_name
on_delete = "cancel"
max_workers = var.max_workers
template_gcs_path = var.template_location
temp_gcs_location = "gs://${var.gcs_location}/tmp_dir"
service_account_email = var.controller_service_account_email
parameters = {
inputPubSub = var.input_PubSub_subscription
outputPubSub = var.output_PubSub_subscription
}
machine_type = var.machine_type
}
terraform.tfvars
<...>
template_location = "gs://www/zzz/template"
gcs_location= "gs://www/yyy"
<...>
为了测试我的代码是否错误,我也直接从链接的代码中尝试了同样的错误。
我是否缺少添加到代码中的任何依赖项?
解决方案
请注意,您已声明temp_gcs_location
为,"gs://${var.gcs_location}/tmp_dir"
但随后在terraform.tvars
您设置gcs_location
为"gs://www/yyy"
(因此gs://
前缀出现两次)。在任何情况下,作业都应该启动,但随后无法创建。
我用以下版本做了一个最小的例子:
$ terraform --version
Terraform v0.12.20
+ provider.google v3.5.0
并使用 Google 提供的字数统计模板。我的main.tf
文件是:
variable "project_id" {
type = string
description = "GCP Project ID."
}
variable "gcs_location" {
type = string
description = "GCS bucket name (no gs:// prefix)."
}
provider "google" {
project = var.project_id
region = "us-central1"
zone = "us-central1-c"
}
resource "google_dataflow_job" "wordcount" {
name = "wordcount"
template_gcs_path = "gs://dataflow-templates/latest/Word_Count"
temp_gcs_location = "gs://${var.gcs_location}/temp"
parameters = {
inputFile = "gs://dataflow-samples/shakespeare/kinglear.txt"
output = "gs://${var.gcs_location}/wordcount/output"
}
}
和df.tfvars
(用适当的值改变):
project_id = "PROJECT_ID"
gcs_location = "BUCKET_NAME"
我运行它:
terraform apply -var-file="df.tvars"
并成功创建作业:
google_dataflow_job.wordcount: Creating...
google_dataflow_job.wordcount: Creation complete after 3s [id=2020-01-27_...]
让我知道这是否有帮助。
推荐阅读
- javascript - 单个列搜索文本输入角度
- javascript - 根据条件着色单元格
- typescript - 是否可以为输入是对象的可区分联合编写类型安全函数,该对象的键可区分其对应值
- mysql - MYSQL 试图返回重复值
- r - 寻找移位指数分布的起始值的问题
- python - 通过移动字母在数组中复制零以腾出空间
- sql - 使用特定代码选择不存在的数字
- javascript - 如何在 reactjs 中提供静态文件?
- c# - How can I read migrations files at runtime and apply them to my database in EF Core?
- mysql - Mysql查询用子句从另一个表中的值中减去表中列的总和