hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.36k stars 1.75k forks source link

default_labels not applied to google_container_cluster #19603

Open paulmarsicloud opened 2 months ago

paulmarsicloud commented 2 months ago

Community Note

Terraform Version & Provider Version(s)

Terraform v1.9.5 on darwin_arm64

Affected Resource(s)

google_container_cluster source = "terraform-google-modules/kubernetes-engine/google//modules/beta-public-cluster"

Terraform Configuration

terraform {
  required_providers {
    google = {
      source = "hashicorp/google"
      version = "~> 6.4.0"
    }
  }
}

provider "google" {
    project = var.project_id
    region  = var.region
    default_labels = {
        terraform-managed = "true"
    }
}

### Cloud SQL Creation ###
module "setup-gke" {
  source                     = "terraform-google-modules/kubernetes-engine/google//modules/beta-public-cluster"
  version                    = "~> 33.0.0"
  ...
}

Debug Output

No response

Expected Behavior

resource_labels/terraform_labels are applied to google_container_cluster and contain the listed default_labels from the provider.

Actual Behavior

google_container_cluster does not get the listed provider labels

Steps to reproduce

  1. terraform apply

Important Factoids

Very similar to https://github.com/hashicorp/terraform-provider-google/issues/16375

References

No response

ggtisc commented 2 months ago

Hi @paulmarsicloud!

I tried to replicate this issue but everything was successful without errors and the labels were added. The difference is in the declaration of the default_labels. I suggest you follow this example and try it again:

provider "google" {
  # user_project_override = true
  # billing_project = "my-project"
  project = "my-project"
  region = "us-central1"

  default_labels = {
    "label1" = "value1"
    "label2" = "value2"
  }
}

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

resource "google_container_cluster" "container_cluster_19603" {
  name     = "container-cluster-19603"
  location = "us-central1"
  remove_default_node_pool = true
  initial_node_count       = 1
}

If after this you still continue with issues please share with us the complete configuration of the module and the google_container_cluster.