Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terraform plan crashing on nil pointer - google provider #4010

Closed
ghost opened this issue Jul 12, 2019 · 7 comments
Closed

Terraform plan crashing on nil pointer - google provider #4010

ghost opened this issue Jul 12, 2019 · 7 comments
Assignees

Comments

@ghost
Copy link

ghost commented Jul 12, 2019

This issue was originally opened by @TE-Chris as hashicorp/terraform#22041. It was migrated here as a result of the provider split. The original body of the issue is below.


Terraform Version

0.12.3

Terraform Configuration Files

provider "google" {
  credentials = "${file("creds/prod.json")}"
  region = "europe-west2"
  zone= "europe-west2-a"
  version = "~> 2.8"
}

data "google_container_cluster" "cluster_config" {
  name = "${google_container_cluster.cluster.name}"
}

data "google_client_config" "default" {}

resource "google_container_cluster" "cluster"{
  name = "prod"

  remove_default_node_pool = true
  initial_node_count = 1
  min_master_version = "1.13"
  # network = "${google_compute_network.vpc.self_link}"

  ip_allocation_policy {
    use_ip_aliases = true
  }
}

resource "google_container_node_pool" "node_pool" {
  name = "pool1"
  cluster = "${google_container_cluster.cluster.name}"

  node_count = 3
  node_config {
    oauth_scopes = [
      "https://www.googleapis.com/auth/compute",
      "https://www.googleapis.com/auth/devstorage.read_only",
      "https://www.googleapis.com/auth/logging.write",
      "https://www.googleapis.com/auth/monitoring"
    ]
    machine_type = "n1-standard-2"
    disk_size_gb = 10
    disk_type = "pd-ssd"
  }
}

resource "google_sql_database_instance" "db" {
  name = "db-prod-${lower(random_string.db_suffix.result)}"
  database_version = "POSTGRES_11"

  settings {
    # Second-generation instance tiers are based on the machine
    # type. See argument reference below.
    tier = "db-custom-1-3840"
    disk_autoresize = true
    activation_policy = "ALWAYS"

    backup_configuration {
      enabled = true
      start_time = "02:00"
    }
  }
}

resource "google_sql_database" "users" {
  name = "db"
  instance = "${google_sql_database_instance.db.name}"
}

resource "google_sql_user" "users" {
  name = "${random_string.username.result}"
  instance = "${google_sql_database_instance.db.name}"
  password = "${random_string.password.result}"
}

# Service account for SQL instance
resource "google_service_account" "proxydb" {
  account_id   = "proxydb"
  display_name = "Proxy DB Service Account"
}

resource "google_project_iam_member" "cloudsql_client" {
  role = "roles/cloudsql.client"
  member = "serviceAccount:${google_service_account.proxydb.email}"
}

resource "google_service_account_key" "mykey" {
  service_account_id = "${google_service_account.proxydb.name}"
}

resource "google_redis_instance" "rails_redis" {
  name = "rails-redis"
  memory_size_gb = 1
}

resource "random_string" "username" {
  length = 8
  special = false
}

resource "random_string" "password" {
  length = 16
  special = false
}

resource "random_string" "db_suffix" {
  length = 4
  special = false
}

output "db_instance_connection_name" {
  value = "${google_sql_database_instance.db.connection_name}"
}

output "db_service_account_key" {
  value = "${base64decode(google_service_account_key.mykey.private_key)}"
}

output "kube_access_token" {
  value = "${data.google_client_config.default.access_token}"
}

output "kube_ca_cert" {
  value = "${base64decode(data.google_container_cluster.cluster_config.master_auth.0.cluster_ca_certificate)}"
}

output "kube_endpoint" {
  value = "${data.google_container_cluster.cluster_config.endpoint}"
}

output "db_password" {
  value = "${google_sql_user.users.password}"
}

output "db_username" {
  value = "${google_sql_user.users.name}" 
}

output "kube_cluster_name" {
  value = "${google_container_cluster.cluster.name}"
}

output "rails_redis_url" {
  value = "redis://${google_redis_instance.rails_redis.host}:${google_redis_instance.rails_redis.port}"
}

Debug Output

Crash Output

https://gist.github.com/te-chris/b3ad78777a4784679c04057519339365

Expected Behavior

Terraform plan should run

Actual Behavior

Terraform plan crashed while acquiring state

Steps to Reproduce

terraform init
terraform apply
terraform plan

Additional Context

Terraform is running with the TF cloud backend.

@Vishwas1976
Copy link

Vishwas1976 commented Jul 12, 2019

Getting a similar error while building a gcp managed k8s cluster with private node pool

@christopherdbull
Copy link

Yeah it seems to be when it tries to create the node pool

@rileykarson
Copy link
Collaborator

This should be fixed by GoogleCloudPlatform/magic-modules#2035 when that's merged

@slevenick
Copy link
Collaborator

Additional nil checks prevent this crash, fixed in GoogleCloudPlatform/magic-modules#2035

This will be available with the next release expected early next week.

@christopherdbull
Copy link

Any idea when this is going live or how I get around it? this is blocking a bit rollout for us.

@h4
Copy link

h4 commented Jul 15, 2019

As temporary solution I add maintenance_policy to cluster resource. After that I can create new cluster without crashes:

resource "google_container_cluster" "primary" {
  name     = "primary-cluster"

  maintenance_policy {
    daily_maintenance_window {
      start_time = "03:00"
    }
  }
}

@ghost
Copy link
Author

ghost commented Aug 12, 2019

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators Aug 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants