使用Terraform部署数据流 [英] Deploy a Dataflow with Terraform

查看:111
本文介绍了使用Terraform部署数据流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在GCloud中使用Terraform部署数据流模板.

I'm trying to deploy a Dataflow template with Terraform in GCloud.

有几本教程,其中包含一些Terraform代码.有2个选项:像以下

There are several tutorial which include some terraform code. There are 2 options:Use module like the following link or use resource like the following link

同时使用这两个选项,我会遇到以下错误:

With both options I have the following error:

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内的云外壳运行.

I have tried running from my local computer and also from the cloud shell inside GCP.

问题应该出在数据流模块中,因为我还尝试创建其他资源,例如存储桶和计算引擎,并且它可以正常工作.

The problem should be in the dataflow module, because I also tried to create other resource like a bucket and compute engine and it works without any problem.

在运行terraform脚本之前,数据流模板已存储在存储桶中.

The dataflow template is storaged in a bucket before I run the terraform script.

Terraform版本:0.12.19

Terraform version: 0.12.19

代码:

main.tf

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"
<...>

要测试我的代码是否错误,我还直接从

To test if my code is wrong, I also tried directly from the code of link and also the same error.

我是否缺少添加到代码中的依赖项?

Am I missing any dependence to add to the code?

推荐答案

请注意,您已将 temp_gcs_location 声明为"gs://$ {var.gcs_location}/tmp_dir" ,然后在 terraform.tvars 中将 gcs_location 设置为"gs://www/yyy" (因此, gs://前缀出现两次).无论如何,应该启动该作业,但之后创建失败.

Note that you have declared temp_gcs_location as "gs://${var.gcs_location}/tmp_dir" but then, in terraform.tvars you set gcs_location as "gs://www/yyy" (so the gs:// prefix appears twice). In any case, the job should be launched but then fail to create.

我用以下版本做了一个最小的例子:

I made a minimal example with the following versions:

$ terraform --version
Terraform v0.12.20
+ provider.google v3.5.0

并使用Google提供的单词计数模板.我的 main.tf 文件是:

and using the Google-provided word count template. My main.tf file is:

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 (更改为适当的值):

and df.tfvars (change with the appropriate values):

project_id = "PROJECT_ID"
gcs_location = "BUCKET_NAME"

我通过以下方式运行它:

I run it with:

terraform apply -var-file="df.tvars"

作业成功创建:

google_dataflow_job.wordcount: Creating...
google_dataflow_job.wordcount: Creation complete after 3s [id=2020-01-27_...]

让我知道这是否有帮助.

Let me know if this helps.

这篇关于使用Terraform部署数据流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆