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

panic: interface conversion: interface {} is nil, not string #300

Closed
mag415 opened this issue Sep 25, 2024 · 3 comments · Fixed by #301
Closed

panic: interface conversion: interface {} is nil, not string #300

mag415 opened this issue Sep 25, 2024 · 3 comments · Fixed by #301
Labels
bug Something isn't working

Comments

@mag415
Copy link

mag415 commented Sep 25, 2024

Describe the bug

Running terraform plan results in panic. This seems like a recent regression since the same TF resources we're previously built correctly on same version (0.3.16).

Error message

Stack trace from the terraform-provider-dbtcloud_v0.3.16 plugin:

panic: interface conversion: interface {} is nil, not string

goroutine 484 [running]:
github.com/dbt-labs/terraform-provider-dbtcloud/pkg/sdkv2/resources.resourceConnectionRead({0x104ccc498?, 0x1400091c510?}, 0x140005b0280, {0x104cb5420?, 0x140004b2800})
	github.com/dbt-labs/terraform-provider-dbtcloud/pkg/sdkv2/resources/connection.go:309 +0x126c
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0x140002da8c0, {0x104ccc498, 0x1400091c510}, 0xd?, {0x104cb5420, 0x140004b2800})
	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:823 +0xe8
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).RefreshWithoutUpgrade(0x140002da8c0, {0x104ccc498, 0x1400091c510}, 0x14000826340, {0x104cb5420, 0x140004b2800})
	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:1117 +0x430
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadResource(0x1400000d890, {0x104ccc498?, 0x1400091c3c0?}, 0x1400068e880)
	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:708 +0x5ac
github.com/hashicorp/terraform-plugin-mux/tf5to6server.v5tov6Server.ReadResource({{0x104cd8740?, 0x1400000d890?}}, {0x104ccc498?, 0x1400091c3c0?}, 0x1400068e4c0?)
	github.com/hashicorp/[email protected]/tf5to6server/tf5to6server.go:215 +0x228
github.com/hashicorp/terraform-plugin-mux/tf6muxserver.(*muxServer).ReadResource(0x104ccc4d0?, {0x104ccc498?, 0x1400058fec0?}, 0x1400068e4c0)
	github.com/hashicorp/[email protected]/tf6muxserver/mux_server_ReadResource.go:35 +0x184
github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server.(*server).ReadResource(0x140002595e0, {0x104ccc498?, 0x1400058e900?}, 0x140002522a0)
	github.com/hashicorp/[email protected]/tfprotov6/tf6server/server.go:784 +0x224
github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/tfplugin6._Provider_ReadResource_Handler({0x104c8e7e0?, 0x140002595e0}, {0x104ccc498, 0x1400058e900}, 0x140005b0000, 0x0)
	github.com/hashicorp/[email protected]/tfprotov6/internal/tfplugin6/tfplugin6_grpc.pb.go:482 +0x164
google.golang.org/grpc.(*Server).processUnaryRPC(0x14000189000, {0x104ccc498, 0x1400058e2d0}, {0x104cd3950, 0x140004f4000}, 0x140005767e0, 0x1400037b380, 0x10531b868, 0x0)
	google.golang.org/[email protected]/server.go:1369 +0xba0
google.golang.org/grpc.(*Server).handleStream(0x14000189000, {0x104cd3950, 0x140004f4000}, 0x140005767e0)
	google.golang.org/[email protected]/server.go:1780 +0xc80
google.golang.org/grpc.(*Server).serveStreams.func2.1()
	google.golang.org/[email protected]/server.go:1019 +0x8c
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 23
	google.golang.org/[email protected]/server.go:1030 +0x150

Error: The terraform-provider-dbtcloud_v0.3.16 plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.

Resource configuration

terraform {
  required_providers {
    dbtcloud = {
      source  = "dbt-labs/dbtcloud"
      version = ">= 0.3.16"
    }
  }
}

resource "dbtcloud_project" "this" {
  dbt_project_subdirectory = "dbt/${var.project_name}"
  name                     = var.project_name
}

resource "dbtcloud_global_connection" "this" {
  databricks = {
    catalog   = var.databricks_catalog
    host      = var.databricks_host
    http_path = var.databricks_http_path
  }
  name = "Databricks - ${var.project_name}"
}

resource "dbtcloud_connection" "this" {
  catalog    = var.databricks_catalog
  database   = "" // currenyly need to be empty for databricks
  host_name  = var.databricks_host
  http_path  = var.databricks_http_path
  name       = "Databricks - ${var.project_name}"
  project_id = dbtcloud_project.this.id
  type       = "adapter"
}

resource "dbtcloud_databricks_credential" "this" {
  adapter_id   = dbtcloud_connection.this.adapter_id
  adapter_type = "databricks"
  project_id   = dbtcloud_project.this.id
  schema       = var.schema
  target_name  = "default"
  token        = var.databricks_token
}

resource "dbtcloud_environment" "dev_env" {
  connection_id     = dbtcloud_global_connection.this.id
  dbt_version       = "versionless"
  name              = "Development"
  project_id        = dbtcloud_project.this.id
  type              = "development"
  use_custom_branch = false
}

resource "dbtcloud_environment" "ci_env" {
  connection_id     = dbtcloud_global_connection.this.id
  credential_id     = dbtcloud_databricks_credential.this.credential_id
  dbt_version       = "versionless"
  name              = "CI"
  project_id        = dbtcloud_project.this.id
  type              = "deployment"
  use_custom_branch = false
}

resource "dbtcloud_environment" "prod_env" {
  connection_id     = dbtcloud_global_connection.this.id
  credential_id     = dbtcloud_databricks_credential.this.credential_id
  dbt_version       = "versionless"
  deployment_type   = "production"
  name              = "Production"
  project_id        = dbtcloud_project.this.id
  type              = "deployment"
  use_custom_branch = false
}

resource "dbtcloud_repository" "this" {
  git_clone_strategy        = "github_app"
  github_installation_id    = local.github_installation_id
  project_id                = dbtcloud_project.this.id
  remote_url                = var.git_repo_remote_url
}

resource "dbtcloud_project_repository" "this" {
  project_id    = dbtcloud_project.this.id
  repository_id = dbtcloud_repository.this.repository_id
}

resource "dbtcloud_job" "ci_job" {
  environment_id       = dbtcloud_environment.ci_env.environment_id
  execute_steps        = ["dbt build"]
  generate_docs        = false
  name                 = "CI"
  num_threads          = 4
  project_id           = dbtcloud_project.this.id
  run_generate_sources = false
  target_name          = "CI"
  timeout_seconds      = 0
  triggers = {
    git_provider_webhook = false
    github_webhook       = true
    on_merge             = false
    schedule             = false
  }
  triggers_on_draft_pr = true
}

resource "dbtcloud_job" "prod_merge_job" {
  environment_id       = dbtcloud_environment.prod_env.environment_id
  execute_steps        = ["dbt compile"]
  generate_docs        = false
  name                 = "Production"
  num_threads          = 4
  project_id           = dbtcloud_project.this.id
  run_generate_sources = false
  target_name          = "PROD"
  timeout_seconds      = 0
  triggers = {
    git_provider_webhook = false
    github_webhook       = false
    on_merge             = true
    schedule             = false
  }
  triggers_on_draft_pr = false
}

resource "dbtcloud_job" "prod_deploy_job" {
  environment_id       = dbtcloud_environment.prod_env.environment_id
  execute_steps        = ["dbt build"]
  generate_docs        = true
  name                 = "Production Deployment"
  num_threads          = 4
  project_id           = dbtcloud_project.this.id
  run_generate_sources = false
  target_name          = "PROD"
  timeout_seconds      = 0
  triggers = {
    git_provider_webhook = false
    github_webhook       = false
    on_merge             = false
    schedule             = false
  }
  triggers_on_draft_pr = false

  job_completion_trigger_condition {
    job_id     = dbtcloud_job.prod_merge_job.id
    project_id = dbtcloud_project.this.id
    statuses   = ["success"]
  }
}

Expected behavior

terraform plan runs without errors.

Config (please complete the following information):

( the version can be retrieved running the command terraform providers )

  • dbt Cloud provider version 0.3.16

Additional context

Add any other context about the problem here.

@mag415 mag415 added the bug Something isn't working label Sep 25, 2024
@b-per
Copy link
Collaborator

b-per commented Sep 25, 2024

Thanks for the report!

Nothing really changed in this part of the provider code recently, so I am not too sure what is happening but seeing the error I can still think of ways to avoid this null pointer issue.

I will release a fix soon.

@b-per
Copy link
Collaborator

b-per commented Sep 25, 2024

I could reproduce it and I am working on a quick fix.

I think that someone might have removed the catalog from the dbtcloud_connection (not the dbtcloud_global_connection) directly from the UI.

@b-per
Copy link
Collaborator

b-per commented Sep 25, 2024

Will be fixed in 0.3.17 that should be out in the registry in 15-20 min

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants