Skip to content

Terraform crashes with panic: interface conversion: interface {} is nil, not map[string]interface {} #36420

@keereets

Description

@keereets

Terraform Version

Terraform v1.10.5
on linux_amd64

Terraform Configuration Files

terraform {
  required_providers {
    google = {
      source = "hashicorp/google"
      version = "6.17.0"
    }
  }
  backend "gcs" {
    # the bucket is configured through the config file, and the
    # command `terraform init --migrate-state --backend-config=config/gcp-pilot-us.config`
    prefix = "terraform/state"
  }
}

provider "google" {
  # Configuration options
  region = var.region
}

# FIXME: rename "db_name_suffix" to "rnd_name_suffix", needs to be done after a `destroy`, otherwise everything gets destroyed anyway
resource "random_id" "db_name_suffix" {
  byte_length = 4
}

data "google_compute_global_address" "global_ip_k8s" {
  name = var.app_lb_global_ip_name
  project = var.project_id
}

# Create LB backend buckets

resource "google_storage_bucket" "ng-frontend" {
  name                        = "${var.specific_name}ng-frontend-site"
  project                     = var.project_id
  location                    = var.bucket_location
  uniform_bucket_level_access = true
  storage_class               = "STANDARD"
  // delete bucket and contents on destroy.
  force_destroy = true

  website {
    main_page_suffix = "index.html"
    not_found_page   = "index.html"
  }
  cors {
    origin          = ["*"]
    method          = ["GET", "HEAD", "PUT", "POST", "PATCH", "DELETE", "OPTIONS"]
    response_header = ["Content-Type"]
    max_age_seconds = 3600
  }
}

resource "google_storage_bucket" "web-engine" {
  name                        = "${var.specific_name}web-engine-site"
  project                     = var.project_id
  location                    = var.bucket_location
  uniform_bucket_level_access = true
  storage_class               = "STANDARD"
  // delete bucket and contents on destroy.
  force_destroy = true

  website {
    main_page_suffix = "index.html"
    not_found_page   = "index.html"
  }
  cors {
    origin          = ["*"]
    method          = ["GET", "HEAD", "PUT", "POST", "PATCH", "DELETE", "OPTIONS"]
    response_header = ["Content-Type"]
    max_age_seconds = 3600
  }
}

resource "google_compute_backend_bucket" "ng-frontend" {
  name        = "ngfrontend"
  description = "Main application angular for ng-frontend"
  bucket_name = google_storage_bucket.ng-frontend.name
  project = var.project_id
  enable_cdn  = true
  cdn_policy {
    cache_key_policy {
        include_http_headers = ["X-Header-Field"] # FIXME: which ones do we need?
    }
  }
}

resource "google_compute_backend_bucket" "web-engine" {
  name        = "webengine"
  description = "Main application vue for web-engine"
  bucket_name = google_storage_bucket.web-engine.name
  project = var.project_id
  enable_cdn  = true
  cdn_policy {
    cache_key_policy {
        include_http_headers = ["X-Header-Field"] # FIXME: which ones do we need?
    }
  }
}

data "google_compute_global_address" "global-lb-address" {
  name = var.admin_bucket_lb_global_ip_name
  project = var.project_id
}

# Policy to make buckets public
data "google_iam_policy" "storage_object_viewer" {
  binding {
    role = "roles/storage.objectViewer"
    members = [
      "allUsers",
    ]
  }
}

resource "google_storage_bucket_iam_policy" "policy-ng-1" {
  bucket = google_storage_bucket.ng-frontend.name
  policy_data = data.google_iam_policy.storage_object_admin.policy_data
}

resource "google_storage_bucket_iam_policy" "policy-we-1" {
  bucket = google_storage_bucket.web-engine.name
  policy_data = data.google_iam_policy.storage_object_admin.policy_data
}

resource "google_storage_bucket_iam_policy" "policy-we-3" {
  bucket = google_storage_bucket.web-engine.name
  policy_data = data.google_iam_policy.storage_object_viewer.policy_data
}

resource "google_storage_bucket_iam_policy" "policy-ng-3" {
  bucket = google_storage_bucket.ng-frontend.name
  policy_data = data.google_iam_policy.storage_object_viewer.policy_data
}

# Create url map
resource "google_compute_url_map" "default" {
  name    = "http-lb"
  project = var.project_id

  default_service = google_compute_backend_bucket.ng-frontend.id

  host_rule {
    hosts        = [
        "ng-frontend.${var.dns_domain_name}",
        "admin.${var.dns_domain_name}",
    ]
    path_matcher = "path-matcher-ng-frontend"
  }

  host_rule {
    hosts        = ["web-engine.${var.dns_domain_name}"]
    path_matcher = "path-matcher-web-engine"
  }

  path_matcher {
    name            = "path-matcher-ng-frontend"
    default_service = google_compute_backend_bucket.ng-frontend.id
  }

  path_matcher {
    name            = "path-matcher-web-engine"
    default_service = google_compute_backend_bucket.web-engine.id
  }
}

resource "google_compute_managed_ssl_certificate" "default" {
  project = var.project_id
  name    = "global-lb-buckets-certificate"
  type    = "MANAGED"
  managed {
    # Note: these hostnames should appear as "NONE" in the DNS zone definitions in the other file
    domains = [
      "ng-frontend.${var.dns_domain_name}",
      "web-engine.${var.dns_domain_name}",
      "admin.${var.dns_domain_name}",
    ]
  }
}

# Create HTTPS target proxy
resource "google_compute_target_https_proxy" "default" {
  project  = var.project_id
  name     = "global-lb-buckets-proxy"
  url_map  = google_compute_url_map.default.id
  ssl_certificates = [
    google_compute_managed_ssl_certificate.default.id,
  ]
}

# Create forwarding rule
resource "google_compute_global_forwarding_rule" "default" {
  project               = var.project_id
  name                  = "http-lb-buckets-forwarding-rule"
  ip_protocol           = "TCP"
  load_balancing_scheme = "EXTERNAL_MANAGED"  # this makes it a global load-balancer
  port_range            = "443"
  target                = google_compute_target_https_proxy.default.id
  ip_address            = data.google_compute_global_address.global-lb-address.address
}

resource "google_storage_bucket" "files-site" {
  name          = "infra-tf-${var.specific_name}files-site"
  location      = var.bucket_location
  force_destroy = true
  project = var.project_id

  uniform_bucket_level_access = true

  hierarchical_namespace {
    enabled = true
  }
  versioning {
    enabled = false
  }
}

data "google_iam_policy" "storage_object_admin" {
  binding {
    role = "roles/storage.objectAdmin"
    members = [
      "serviceAccount:...",
      "serviceAccount:...",
    ]
  }
}

resource "google_storage_bucket_iam_policy" "policy-files-1" {
  bucket = google_storage_bucket.files-site.name
  policy_data = data.google_iam_policy.storage_object_admin.policy_data
}

Vars:

project_id = "qa-lotus"
terraform_state_bucket = "bucket-flower-1"
specific_name = "lotus-"
region     = "europe-west3"
dual_region = "eur8"
bucket_location = "EU"
dns_host_part = "lotus"
bucket_lb_name = "app-buckets-lb"
dns_zone_name = "gcp-lotus"
dns_domain_name = "example.com"
app_lb_global_ip_name = "app-lb-lotus"
admin_bucket_lb_global_ip_name = "admin-bucket-lb-lotus"
outputs_k8s_config_dir = "outputs-gcp-config-lotus"

Debug Output

...debug output, or link to a gist...

Expected Behavior

I ran terraform init and then CTRL-C on the first request for an input. I expected no crash.

Actual Behavior

$ terraform init
Initializing the backend...
bucket
  The name of the Google Cloud Storage bucket

  Enter a value: ^C

!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!

Terraform crashed! This is always indicative of a bug within Terraform.
Please report the crash with Terraform[1] so that we can fix this.

When reporting bugs, please include your terraform version, the stack trace
shown below, and any additional information which may help replicate the issue.

[1]: https://github.com/hashicorp/terraform/issues

!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!

panic: interface conversion: interface {} is nil, not map[string]interface {}
goroutine 1 [running]:
runtime/debug.Stack()
	runtime/debug/stack.go:26 +0x5e
github.com/hashicorp/terraform/internal/logging.PanicHandler()
	github.com/hashicorp/terraform/internal/logging/panic.go:84 +0x16a
panic({0x321ee80?, 0xc000bb86c0?})
	runtime/panic.go:785 +0x132
github.com/zclconf/go-cty/cty.Value.GetAttr({{{0x3e21210?, 0xc0009e3160?}}, {0x0?, 0x0?}}, {0x3791b4b, 0x1b})
	github.com/zclconf/go-cty@v1.16.2/cty/value_ops.go:819 +0x2d7
github.com/hashicorp/terraform/internal/backend/backendbase.SDKLikeDefaults.ApplyTo(0xc000a21e90, {{{0x3e21210?, 0xc0009e3160?}}, {0x0?, 0x0?}})
	github.com/hashicorp/terraform/internal/backend/backendbase/sdklike.go:195 +0x25a
github.com/hashicorp/terraform/internal/backend/backendbase.Base.PrepareConfig({0xc000a21ec0?, 0xc000a21e90?}, {{{0x3e21210?, 0xc0009e30c0?}}, {0x0?, 0x0?}})
	github.com/hashicorp/terraform/internal/backend/backendbase/base.go:109 +0x38f
github.com/hashicorp/terraform/internal/command.(*Meta).backendInitFromConfig(0xc000704700, 0xc0009f7d60)
	github.com/hashicorp/terraform/internal/command/meta_backend.go:1415 +0x537
github.com/hashicorp/terraform/internal/command.(*Meta).backend_C_r_s(0xc000704700, 0xc0009f7d60, 0x852e28c6, 0xc000a24780, 0xc00088d4d0)
	github.com/hashicorp/terraform/internal/command/meta_backend.go:989 +0x979
github.com/hashicorp/terraform/internal/command.(*Meta).backendFromConfig(0xc000704700, 0xc00088d4d0)
	github.com/hashicorp/terraform/internal/command/meta_backend.go:638 +0x1865
github.com/hashicorp/terraform/internal/command.(*Meta).Backend(0xc000704700, 0x0?)
	github.com/hashicorp/terraform/internal/command/meta_backend.go:105 +0x6a
github.com/hashicorp/terraform/internal/command.(*InitCommand).initBackend(0xc000704700, {0x3e20c30?, 0xc00071a730?}, 0xc0005822d0, {{0x37631a7?, 0xc0007220a0?}, 0xc00087b9e0?}, 0x48, {0x3e26120, 0xc000714a30})
	github.com/hashicorp/terraform/internal/command/init.go:499 +0x730
github.com/hashicorp/terraform/internal/command.(*InitCommand).Run(0xc000704700, {0xc000072050?, 0x0?, 0x0?})
	github.com/hashicorp/terraform/internal/command/init.go:187 +0xf65
github.com/hashicorp/cli.(*CLI).Run(0xc0002ee3c0)
	github.com/hashicorp/cli@v1.1.6/cli.go:265 +0x55f
main.realMain()
	github.com/hashicorp/terraform/main.go:339 +0x1deb
main.main()
	github.com/hashicorp/terraform/main.go:64 +0x13

Steps to Reproduce

  1. terraform init
  2. it expects an input, because I forgot to add the var file on the command line
  3. I pressed CTRL-C
  4. it crashed.

Additional Context

No response

References

No response

Generative AI / LLM assisted development?

No response

Metadata

Metadata

Assignees

Labels

bugconfirmeda Terraform Core team member has reproduced this issuecrash

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions