Terraform 和 GCP 作曲家设置

Terraform and GCP composer setup

我正在尝试使用 terraform 部署 GCP composer 但遇到了问题 ->

错误:资源“google_composer_environment”中 composer.tf 第 43 行不支持的块类型 “测试”:34:encryption_config { 此处不应使用“encryption_config”类型的块。

这里是 composer.tf 文件:

resource "google_composer_environment" "test" {
  name   = "dwh_composer"
  region = local.default_region
  config {
    node_count = 3
    node_config {
      zone         = local.default_zone
      machine_type = "e2-medium"
      network    = google_compute_network.test.id
      subnetwork = google_compute_subnetwork.test.id
      service_account = google_service_account.test.name
    }
    software_config {
      image_version = "composer-1.17.0-preview.9-airflow-2.1.1"
      python_version = "3"
      airflow_config_overrides = {
        core-load_example = "True"
      }
      pypi_packages = {
        numpy = ""
        scipy = "==1.1.0"
      }
      env_variables = {
        FOO = "bar"
        R1 = "test5"
        evvv_qqq_d = "test1"
        M1 = "test3"
        AIRFLOW-3 = "test2"
      }
    }
    private_environment_config {
      enable_private_endpoint = true
    }
    encryption_config {
      kms_key_name = google_kms_crypto_key.dwh_composer_crypto_key.name
    }
  }
}

resource "google_kms_key_ring" "data_warehouse_kms_keyring" {
  name     = "data-warehouse-kms-keyring"
  location = "europe-west4"
}

resource "google_kms_crypto_key" "dwh_composer_crypto_key" {
  name            = "dwh-composer-crypto-key"
  key_ring        = google_kms_key_ring.data_warehouse_kms_keyring.self_link
}

这里是 main.tf 文件:

terraform {
  required_version = "1.0.0"

  backend "gcs" {
    bucket = "terraform-data-warehouse"
    prefix = "gcp/data-warehouse/composer"
  }

  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "~> 3.70.0"
    }
    google-beta = {
      source  = "hashicorp/google-beta"
      version = "~> 3.70.0"
    }
  }
}

# -- Providers

provider "google" {
  project = local.project_id
}

provider "google-beta" {
  project = local.project_id
}

# -- common public state

data "terraform_remote_state" "common" {
  backend = "gcs"

  config = {
    bucket = "terraform-public"
    prefix = "common"
  }
}

# -- Local variables
locals {
  default_zone = "europe-west4-a"
  default_region = "europe-west1"
  project_id = "my-project"
  team_group = data.terraform_remote_state.common.outputs.teams.data_warehouse.group
  default_multi_region = "EU"
}

你能帮帮我吗?

您遇到的问题是因为 encryption_config 根据 docsgoogle_composer_environment terraform 资源中的 Beta 功能。只需在资源中指定测试版提供商:

resource "google_composer_environment" "test" {
  name   = "dwh_composer"
  region = local.default_region
  provider = google-beta
  ...
}

不要忘记terraform init,以便可以下载和使用 beta Google 提供程序。