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.33k stars 1.73k forks source link

Error: Provider produced inconsistent final plan #10816

Open webpwnized opened 2 years ago

webpwnized commented 2 years ago

Community Note

Terraform Version

Terraform v1.1.2 on linux_amd64

Affected Resource(s)

Terraform Configuration Files


locals {
    gke-cluster-name    = "mutillidae-gke-cluster"
    gke-cluster-description = "A GKE Cluster to run Docker containers"

    gke-node-image-type         = "COS_CONTAINERD"
    gke-node-disk-size-gb       = 25
    gke-node-initial-node-count = 1
    gke-node-min-node-count     = 1
    gke-node-max-node-count     = 3
}

resource "google_container_cluster" "gke_cluster" {
    project     = "${var.project}"
    location    = "${var.location}"
    network     = "${var.network}"
    subnetwork  = "${var.subnetwork}"
    name        = "${local.gke-cluster-name}"
    remove_default_node_pool    = true
    initial_node_count      = 1
    addons_config {
        horizontal_pod_autoscaling {
            disabled    = false
        }
        http_load_balancing {
            disabled    = false
        }
        network_policy_config {
            disabled    = false
        }
    }
    confidential_nodes {
        enabled     = true
    }
}

resource "google_container_node_pool" "gke_cluster_nodes" {
    project         = "${google_container_cluster.gke_cluster.project}"
    name            = "${google_container_cluster.gke_cluster.name}-node-pool"
    cluster         = "${google_container_cluster.gke_cluster.name}"
    location        = "${google_container_cluster.gke_cluster.location}"
    initial_node_count  = local.gke-node-initial-node-count
    autoscaling {
        min_node_count  = local.gke-node-min-node-count
        max_node_count  = local.gke-node-max-node-count     
    }
    management {
        auto_repair = true
        auto_upgrade    = true
    }
    node_config {
        image_type      = "${local.gke-node-image-type}"
        machine_type        = "${var.vm-machine-type}"
        disk_size_gb    = local.gke-node-disk-size-gb
        disk_type   = "${var.vm-boot-disk-type}"
        shielded_instance_config {
            enable_secure_boot      = true
            enable_integrity_monitoring = true
        }
    }
}

Debug Output

Panic Output

Error: Provider produced inconsistent final plan

When expanding the plan for module.kubernetes_module.google_container_cluster.gke_cluster to include new values learned so far during apply, provider "registry.terraform.io/hashicorp/google" produced an invalid new value for .network: was cty.StringVal("mutillidae-vpc"), but now cty.StringVal("https://www.googleapis.com/compute/v1/projects//global/networks/mutillidae-vpc").

This is a bug in the provider, which should be reported in the provider's own issue tracker.

Expected Behavior

The module would create the Kubernetes cluster, then the Kubernetes nodes

Actual Behavior

The build stopped when the panic error message appeared

Steps to Reproduce

Run terraform apply

b/300742865

davdmrgn commented 1 year ago

I was able to work around this by defining the network of the GKE cluster for the network parameter rather than use a generated value.

network = "projects/${var.shared_vpc_host_project}/global/networks/NETWORK"

Alternatively, this is the value which did not work for me resulting in the same error in the OP:

network = google_compute_subnetwork.shared-vpc-service-subnet.network

This has the generated value of https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/networks/NETWORK.