部署带有Terraform的作曲家资源(GCP)时出现错误消息

时间:2019-04-23 19:14:04

标签: google-cloud-platform terraform google-cloud-composer

在部署GCP作曲者资源时,我遇到了Terraform代码错误:

  • google_composer_environment.composer-beta:googleapi:错误400:属性密钥的格式必须为section-namesection可能不包含方括号,闭合方括号或连字符,name可能不包含分号或等号。整个属性键可能不包含句点。badRequest

部署此GCP资源时出现问题:https://www.terraform.io/docs/providers/google/r/composer_environment.html

这是我的代码:

Variables.tf文件:

variable "composer_airflow_version" {
  type = "map"
  default = {
    image_version="composer-1.6.1-airflow-1.10.1"
  }
}

variable "composer_python_version" {
  type = "map"
  default = {
    python_version="3"
  }
}

my-composer.tf文件:

resource "google_composer_environment" "composer-beta" {
  provider= "google-beta"
  project = "my-proyect"
  name    = "${var.composer_name}"
  region  = "${var.region}"
  config {
    node_count = "${var.composer_node_count}"

  node_config {
    zone         = "${var.zone}"
    machine_type = "${var.composer_machine_type}"
    network      = "${google_compute_network.network.self_link}"
    subnetwork   = "${lookup(var.vpc_subnets_01[0], "subnet_name")}"
  }

  software_config {
    airflow_config_overrides="${var.composer_airflow_version}",
    airflow_config_overrides="${var.composer_python_version}",
  }
  }

  depends_on = [
    "google_service_account.comp-py3-dev-worker",
    "google_compute_subnetwork.subnetwork",
  ]
}

根据错误消息,错误的根本原因似乎与terraform代码中的software_config部分有关。我知道变量“ composer_airflow_version”和“ composer_python_version”应为“ map”类型,因此,我将其设置为地图格式。

如果有人可以确定错误原因并告诉我要进行的调整,我真的很感激。我可能应该对变量进行更改,但我不知道它是什么。 :-(

预先感谢, 何塞

1 个答案:

答案 0 :(得分:1)

根据文档,airflow_config_overrides,pypi_packages, env_variables image_version python_version 应该直接位于 software_config

Variables.tf文件:

variable "composer_airflow_version" {
  default = "composer-1.6.1-airflow-1.10.1"
}

variable "composer_python_version" {
  default = "3"
}

my-composer.tf文件:

resource "google_composer_environment" "composer-beta" {
  provider= "google-beta"
  project = "my-proyect"
  name    = "${var.composer_name}"
  region  = "${var.region}"
  config {
    node_count = "${var.composer_node_count}"

    node_config {
      zone         = "${var.zone}"
      machine_type = "${var.composer_machine_type}"
      network      = "${google_compute_network.network.self_link}"
      subnetwork   = "${lookup(var.vpc_subnets_01[0], "subnet_name")}"
    }

    software_config {
      image_version  = "${var.composer_airflow_version}",
      python_version = "${var.composer_python_version}",
    }
  }

  depends_on = [
    "google_service_account.comp-py3-dev-worker",
    "google_compute_subnetwork.subnetwork",
  ]
}