-1

As the terraform docs for google_container_cluster resource (https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_cluster), to provision a GKE cluster we need to add enterprise_config block to the google_container_cluster resource in our terraform code but after adding the block during the terraform plan phase I get the error

│ Error: Unsupported block type
│ 
│   on .terraform/modules/gke_standard/compute/gke_standard/main.tf line 24, in resource "google_container_cluster" "this":
│   24:   enterprise_config {
│ 
│ Blocks of type "enterprise_config" are not expected here.

Any resolution for the above.

Below is my terraform configuration

Terraform Version:

Terraform v1.5.7
on darwin_arm64

Google Cloud Terraform Provider:

terraform {
  backend "gcs" {
    bucket = "<bucket_name>"
    prefix = "test/"
  }

  required_version = ">= 1.3.0, < 2.0.0"

  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "6.8.0"
    }
    google-beta = {
      source = "hashicorp/google-beta"
    }
  }
}

Terraform Code for GKE clusters

resource "google_container_cluster" "this" {
  for_each = local.clusters

  name                     = each.key
  location                 = each.value.region
  project                  = var.project
  remove_default_node_pool = var.remove_default_node_pool
  initial_node_count       = var.initial_node_count
  network                  = each.value.network
  subnetwork               = each.value.subnetwork
  deletion_protection = false

  enterprise_config {
    desired_tier = "ENTERPRISE"
  }

  release_channel {
    channel = "STABLE"
  }

  ip_allocation_policy {
    cluster_secondary_range_name  = each.value.cluster_secondary_range_name
    services_secondary_range_name = each.value.services_secondary_range_name
  }

  private_cluster_config {
    enable_private_nodes    = each.value.enable_private_nodes
    master_ipv4_cidr_block  = each.value.master_ipv4_cidr_block
    enable_private_endpoint = true
  }

  master_authorized_networks_config {

  }

  lifecycle {
    ignore_changes = [
      private_cluster_config[0].enable_private_endpoint,
    ]
  }
}

2 Answers 2

1

The enterprise_config block was introduced in version 6.13 of the Google Cloud provider, but you're currently using version 6.8.0. That's why Terraform doesn't recognize the block. You need to update your provider version to at least 6.13.0.

Sign up to request clarification or add additional context in comments.

Comments

0

As Answered above enterprise_config block was added in terraform gcp provider version 6.13.0 and before using it, we need to update the gcp project to enterprise project, below is the terraform code to do that.

Main.tf

resource "google_project_service" "anthos" {
  project = var.project_id
  service = "anthos.googleapis.com"
}

resource "google_project_service" "gke_enterprise" {
  project = var.project_id
  service = "container.googleapis.com"
}

resource "google_project_service" "gke_hub" {
  project = var.project_id
  service = "gkehub.googleapis.com"
}

variables.tf

variable "project_id" {
  description = "Google Cloud Project ID"
  type = string
}

variable "region" {
  description = "Google Cloud Region"
  type = string
  default = "<region>"
}

outputs.tf

output "anthos_api_status" {
  description = "Anthos API service status"
  value       = google_project_service.anthos.service
}

output "gke_api_status" {
  description = "GKE API service status"
  value       = google_project_service.gke_enterprise.service
}

output "gke_hub_api_status" {
  description = "GKE Hub API service status"
  value       = google_project_service.gke_hub.service
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.