apache / cloudstack-terraform-provider

CloudStack Terraform Provider
https://cloudstack.apache.org
Apache License 2.0
28 stars 35 forks source link

terraform-provider-cloudstack_v0.5.0 plugin crashed while trying to read datasource #118

Open rakesh-p opened 3 months ago

rakesh-p commented 3 months ago

I have a simple main.tf as follows that includes a data resource. this plugin crashes when i run terraform plan I have the correct values for api_key and secret as i could create a VM by not using "data resource" What is that i am doing wrong please?

main.tf

terraform {
  required_version = ">= 1.6.6"
  required_providers {
    # Configure the CloudStack Provider
    cloudstack = {
      source  = "cloudstack/cloudstack"
      version = "0.5.0"
    }
  }
}

provider "cloudstack" {
  api_url    = "https://xxx.xxx.net/api"
  api_key    = "MY_KEY"
  secret_key = "MY_SECRET"
}

data "cloudstack_zone" "zone-data-source" {
  filter {
    name  = "regionid"
    value = 3
  }
}

terraform plan output:

data.cloudstack_zone.zone-data-source: Reading...

Planning failed. Terraform encountered an error while generating this plan.

╷
│ Error: Plugin did not respond
│ 
│   with data.cloudstack_zone.zone-data-source,
│   on versions.tf line 33, in data "cloudstack_zone" "zone-data-source":
│   33: data "cloudstack_zone" "zone-data-source" {
│ 
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ReadDataSource call. The plugin logs may contain more details.
╵

Stack trace from the terraform-provider-cloudstack_v0.5.0 plugin:

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

goroutine 56 [running]:
github.com/terraform-providers/terraform-provider-cloudstack/cloudstack.applyZoneFilters(0xc000130448?, 0x114b50a?)
    github.com/terraform-providers/terraform-provider-cloudstack/cloudstack/data_source_cloudstack_zone.go:114 +0x28a
github.com/terraform-providers/terraform-provider-cloudstack/cloudstack.dataSourceCloudstackZoneRead(0x115f9d2?, {0x1019200?, 0xc0003d2500})
    github.com/terraform-providers/terraform-provider-cloudstack/cloudstack/data_source_cloudstack_zone.go:72 +0x16b
github.com/hashicorp/terraform/helper/schema.(*Resource).ReadDataApply(0xc000404280, 0xc0003a16c0, {0x1019200, 0xc0003d2500})
    github.com/hashicorp/terraform@v0.12.0/helper/schema/resource.go:390 +0xc4
github.com/hashicorp/terraform/helper/schema.(*Provider).ReadDataApply(0xc000426000, 0xc0001998c8, 0xf996e0?)
    github.com/hashicorp/terraform@v0.12.0/helper/schema/provider.go:442 +0x5e
github.com/hashicorp/terraform/helper/plugin.(*GRPCProviderServer).ReadDataSource(0xc00006c900, {0xc00053c4c0?, 0x4c21a6?}, 0xc00053c4c0)
    github.com/hashicorp/terraform@v0.12.0/helper/plugin/grpc_provider.go:990 +0x2b1
github.com/hashicorp/terraform/internal/tfplugin5._Provider_ReadDataSource_Handler({0x10b9240?, 0xc00006c900}, {0x12ead38, 0xc0003daf60}, 0xc000531bd0, 0x0)
    github.com/hashicorp/terraform@v0.12.0/internal/tfplugin5/tfplugin5.pb.go:3055 +0x169
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000002480, {0x12ef698, 0xc000002000}, 0xc000144000, 0xc0004bf1a0, 0x19e0950, 0x0)
    google.golang.org/grpc@v1.18.0/server.go:966 +0xe59
google.golang.org/grpc.(*Server).handleStream(0xc000002480, {0x12ef698, 0xc000002000}, 0xc000144000, 0x0)
    google.golang.org/grpc@v1.18.0/server.go:1245 +0x987
google.golang.org/grpc.(*Server).serveStreams.func1.1()
    google.golang.org/grpc@v1.18.0/server.go:685 +0x8d
created by google.golang.org/grpc.(*Server).serveStreams.func1 in goroutine 9
    google.golang.org/grpc@v1.18.0/server.go:683 +0xd2

Error: The terraform-provider-cloudstack_v0.5.0 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.
kiranchavala commented 3 months ago

Hi @rakesh-p The datasource is working fine

Please find the sample code

provider "cloudstack" {
  api_url    = var.cloudstack_api_url
  api_key    = var.cloudstack_api_key
  secret_key = var.cloudstack_secret_key

}

data "cloudstack_zone" "zone-data-source" {
  filter {
    name  = "name"
    value = "ref-trl-6530-k-Mol8-kiran-chavala"
  }
}

output "zonedetails" {
value = data.cloudstack_zone.zone-data-source.dns1
}

terraform apply

zonedetails = "10.0.32.1"

I could get the following zone details

name 
dns1 
internal_dns1 
network_type