jackall3n / terraform-provider-render

A terraform provider for render.com
https://registry.terraform.io/providers/jackall3n/render
Mozilla Public License 2.0
21 stars 9 forks source link

crash while running `terraform plan` #4

Open matifali opened 1 year ago

matifali commented 1 year ago
│ Error: Plugin did not respond
│
│ The plugin encountered an error, and failed to respond to the plugin6.(*GRPCProvider).ValidateResourceConfig call. The plugin logs 
│ may contain more details.
╵

Stack trace from the terraform-provider-render_v1.2.0.exe plugin:

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x14bd177]

goroutine 105 [running]:
github.com/jackall3n/terraform-provider-render/render/resources.(*serviceResource).Configure(0x1773910?, {0xc00048b170?, 0x164aa04?}, {{0x150ce00?, 0x0?}}, 0x2b?)
        github.com/jackall3n/terraform-provider-render/render/resources/service.go:48 +0x57
github.com/hashicorp/terraform-plugin-framework/internal/fwserver.(*Server).ValidateResourceConfig(0xc000185600, {0x1773910, 0xc00048b170}, 0xc0000051e8, 0xc000115620)
        github.com/hashicorp/terraform-plugin-framework@v1.1.1/internal/fwserver/server_validateresourceconfig.go:40 +0x19c
github.com/hashicorp/terraform-plugin-framework/internal/proto6server.(*Server).ValidateResourceConfig(0xc000185600, {0x1773910?, 0xc00048b020?}, 0xc000005170)
        github.com/hashicorp/terraform-plugin-framework@v1.1.1/internal/proto6server/server_validateresourceconfig.go:44 +0x3cf      
github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server.(*server).ValidateResourceConfig(0xc000305180, {0x1773910?, 0xc00048a8d0?}, 0xc00009b280)
        github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov6/tf6server/server.go:686 +0x2dc
github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/tfplugin6._Provider_ValidateResourceConfig_Handler({0x161b7c0?, 0xc000305180}, {0x1773910, 0xc00048a8d0}, 0xc0002bb960, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov6/internal/tfplugin6/tfplugin6_grpc.pb.go:277 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0003021e0, {0x1776d70, 0xc000313520}, 0xc00063d320, 0xc000443d10, 0x1be5cd0, 0x0)
        google.golang.org/grpc@v1.51.0/server.go:1340 +0xd13
google.golang.org/grpc.(*Server).handleStream(0xc0003021e0, {0x1776d70, 0xc000313520}, 0xc00063d320, 0x0)
        google.golang.org/grpc@v1.51.0/server.go:1713 +0xa1b
google.golang.org/grpc.(*Server).serveStreams.func1.2()
        google.golang.org/grpc@v1.51.0/server.go:965 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/grpc@v1.51.0/server.go:963 +0x28a

Error: The terraform-provider-render_v1.2.0.exe 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.
jackall3n commented 1 year ago

Thanks for raising @matifali

What is your terraform configuration, are you able to share your terraform files?

jackall3n commented 1 year ago

I think, given where it's broken, it's failing to find a user which an email address you provided in the provider "render" block. Can you confirm if there's an existing user with that email address?

I've pushed up a new version with additional logging and error handling around this area to avoid the nil reference error

matifali commented 1 year ago

Yes sure. I am actually trying to write a terraform template for https://github.com/coder/coder. I will post my terraform code later today.

matifali commented 1 year ago

Sorry for being late; I had been quite busy. Here is my complete terraform code; I am getting the same error.

terraform {
  required_providers {
    render = {
      source = "jackall3n/render"
      # version = "1.1.1"

    }
    coder = {
      source = "coder/coder"
    }
  }
}

provider "render" {
  # setting empty values to null will cause the provider to use the environment variables
  api_key = var.render_api_key == "" ? null : var.render_api_key
  email   = var.render_email == "" ? null : var.render_email
}

provider "coder" {
  feature_use_managed_variables = true
}

variable "render_api_key" {
  type        = string
  description = <<-EOF
Your Render api key, created in the render.com Account Settings. If not supplied, RENDER_API_KEY is used.
You can generate one by going to: Account Settings > API Keys > Create API Key
EOF
  sensitive   = true
}

variable "render_email" {
  type        = string
  description = <<-EOF
Your Render email. This is used as a default owner in all services where no owner is specified. If not supplied, RENDER_EMAIL is used.
EOF
  sensitive   = true
}

resource "render_service" "workspace" {
  count = data.coder_workspace.me.start_count
  name  = data.coder_workspace.me.name
  repo  = "https://github.com/matifali/render-docker-build"
  type  = "private_service"

  private_service_details = {
    env = "docker"
    disk = {
      name       = "coder-${data.coder_workspace.me.owner}-${lower(data.coder_workspace.me.name)}-home"
      mount_path = "/home/coder"
      size_gb    = data.coder_parameter.volume-size.value
    }
  }
}

data "coder_parameter" "volume-size" {
  name        = "Volume Size"
  description = "The size of the volume to create for the workspace in GB (1-20)"
  type        = "number"
  default     = "1"
  icon        = "https://raw.githubusercontent.com/matifali/logos/main/database.svg"
  validation {
    min = 1
    max = 20
  }
}

data "coder_parameter" "region" {
  name        = "Region"
  description = "The region to deploy the workspace in"
  default     = "oregon"
  icon        = "/emojis/1f30e.png"
  option {
    name  = "Frankfurt, Germany"
    value = "frankfurt"
    icon  = "/emojis/1f1e9-1f1ea.png"
  }
  option {
    name  = "Oregon, USA"
    value = "oregon"
    icon  = "/emojis/1f1fa-1f1f8.png"
  }
}

resource "coder_app" "code-server" {
  count        = 1
  agent_id     = coder_agent.main.id
  display_name = "Code Server"
  slug         = "code-server"
  url          = "http://localhost:8080?folder=/home/coder/"
  icon         = "/icon/code.svg"
  subdomain    = false
  share        = "owner"

  healthcheck {
    url       = "http://localhost:8080/healthz"
    interval  = 3
    threshold = 10
  }
}

resource "coder_agent" "main" {
  arch                   = data.coder_provisioner.me.arch
  os                     = "linux"
  login_before_ready     = false
  startup_script_timeout = 180
  startup_script         = <<-EOT
    set -e
    # Start code-server
    code-server --auth none >/tmp/code-server.log 2>&1 &
    # Set the hostname to the workspace name
    sudo hostname -b "${data.coder_workspace.me.name}-render"
  EOT
}

data "coder_provisioner" "me" {
}

data "coder_workspace" "me" {
}
tazarov commented 11 months ago

@matifali, found a workaround of sorts:

variable "render_api_token" {
  sensitive   = true
}

variable "render_user_email" {
  sensitive   = true
}

provider "render" {
  api_key = var.render_api_token
}

data "render_owner" "render_owner" {
  email = var.render_user_email
}

resource "render_service" "my_service" {
  name = "my_service"
  repo = var.my_service_repo
  branch = var.my_service_branch
  owner = data.render_owner.render_owner.id
  ...