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

Passing [""] to data.tfe_workspace_ids.names crashes plugin #409

Closed
arthurmcgregor opened this issue Jan 16, 2022 · 1 comment · Fixed by #421
Closed

Passing [""] to data.tfe_workspace_ids.names crashes plugin #409

arthurmcgregor opened this issue Jan 16, 2022 · 1 comment · Fixed by #421
Labels

Comments

@arthurmcgregor
Copy link

Terraform Cloud/Enterprise version

I'm using Terraform CLI to access Terraform Cloud workspaces via the data.tfe_workspace_ids

Terraform version

Terraform v1.0.0

Terraform Configuration Files

variable "cloud_workspace_prefix" {
  type    = string
  default = null
}

locals {
  cloud_workspace_name = var.cloud_workspace_prefix == null ? "" : "${var.cloud_workspace_prefix}${var.environment}"
}

data "tfe_workspace_ids" "this" {
  names          = [local.cloud_workspace_name]
  organization = "my-name"
}

Debug Output

Stack trace from the terraform-provider-tfe_v0.27.0_x5 plugin:
panic: interface conversion: interface {} is nil, not string
goroutine 126 [running]:
github.com/hashicorp/terraform-provider-tfe/tfe.dataSourceTFEWorkspaceIDsRead(0x68, {0xe80e00, 0xc000126c00})
	/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-tfe/tfe/data_source_workspace_ids.go:57 +0x9d1
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0xeec399, {0x10dba80, 0xc0004f1cc0}, 0xc0004897a0, {0xe80e00, 0xc000126c00})
	/opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/v2@v2.7.1/helper/schema/resource.go:335 +0x178
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).ReadDataApply(0xc0000a50a0, {0x10dba80, 0xc0004f1cc0}, 0xc00048d460, {0xe80e00, 0xc000126c00})
	/opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/v2@v2.7.1/helper/schema/resource.go:558 +0xf7
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadDataSource(0xc0004fb6e0, {0x10dba80, 0xc0004f1cc0}, 0xc00048d180)
	/opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/v2@v2.7.1/helper/schema/grpc_provider.go:1105 +0x32c
github.com/hashicorp/terraform-plugin-mux.SchemaServer.ReadDataSource({0xc000558cf0, 0xc000558d20, {0xc00048da80, 0x2, 0x2}, 0xc000556300, 0x1}, {0x10dba80, 0xc0004f1cc0}, 0xc00048d180)
	/opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/hashicorp/terraform-plugin-mux@v0.2.0/schema_server.go:309 +0x91
github.com/hashicorp/terraform-plugin-go/tfprotov5/server.(*server).ReadDataSource(0xc00048dac0, {0x10dbb28, 0xc0004880c0}, 0xc00007d680)
	/opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.3.1/tfprotov5/server/server.go:247 +0x1db
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadDataSource_Handler({0xeaf520, 0xc00048dac0}, {0x10dbb28, 0xc0004880c0}, 0xc000194180, 0x0)
	/opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.3.1/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:416 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000552380, {0x10ecb80, 0xc0000fe600}, 0xc00084ea00, 0xc000558db0, 0x17150d0, 0x0)
	/opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/google.golang.org/grpc@v1.36.0/server.go:1217 +0xc8f
google.golang.org/grpc.(*Server).handleStream(0xc000552380, {0x10ecb80, 0xc0000fe600}, 0xc00084ea00, 0x0)
	/opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/google.golang.org/grpc@v1.36.0/server.go:1540 +0xa2a
google.golang.org/grpc.(*Server).serveStreams.func1.2()
	/opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/google.golang.org/grpc@v1.36.0/server.go:878 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
	/opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/google.golang.org/grpc@v1.36.0/server.go:876 +0x294
Error: The terraform-provider-tfe_v0.27.0_x5 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.

Expected Behavior

I expected the plugin to look for names that match "", which would be none, and so return an empty map

Actual Behavior

The plugin crashed

Additional Context

I was able to work around this by passing an empty array, instead of an empty string inside and empty array

variable "cloud_workspace_prefix" {
  type    = string
  default = null
}

data "tfe_workspace_ids" "this" {
  names          = var.cloud_workspace_prefix == null ? [] : ["${var.cloud_workspace_prefix}${var.environment}"]
  organization = "my-name"
}
@sebasslash
Copy link
Contributor

Hi Arthur, thanks for submitting this issue. The short answer is the plugin interprets empty strings as nil values (but an empty array is not), so when the plugin attempts to perform some type conversions behind the scenes it crashes. Ideally we should let you know the plugin doesn't like this rather than letting it crash. Out of curiosity, is there a particular reason you want to set the names argument to an array of empty strings ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants