hashicorp / terraform-provider-tfe

Official HCP Terraform and Terraform Enterprise provider, maintained by HashiCorp. Provision HCP Terraform or Terraform Enterprise - with Terraform!
https://registry.terraform.io/providers/hashicorp/tfe
Mozilla Public License 2.0
167 stars 157 forks source link

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

Closed willdafoe closed 2 years ago

willdafoe commented 2 years ago

Terraform Cloud/Enterprise version

Terraform Cloud

Terraform version

Terraform v1.2.2
on linux_amd64
+ provider registry.terraform.io/hashicorp/tfe v0.30.2

Terraform Configuration Files

data "terraform_remote_state" "tfc_organization" {
  backend = "remote"
  config = {
    organization = module.organization.tfe_organization_id
    workspaces = {
      name = "terraform_cloud_organization"
    }
  }
}

locals {
  workspace_object = {
    "vpc-us-east-1" = {
      allow_destroy_plan            = true
      add_vcs_repo                  = true
      auto_apply                    = true
      execution_mode                = "local"
      file_triggers_enabled         = false
      global_remote_state           = true
      name                          = "vpc-us-east-1"
      oauth_token_id                = data.terraform_remote_state.tfc_organization.outputs.oauth_client_id
      queue_all_runs                = true
      speculative_enabled           = false
      structured_run_output_enabled = true
      tags                          = ["source:aws", "env:dev", "aws_region:us-east-1"]
      tfe_token                     = var.terraform_api_token
      vcs_repository                = "/terraform-aws-vpc"
      vcs_branch                    = "main"
      working_directory             = "./us-east-1"
    },
    "vpc-us-east-2" = {
      allow_destroy_plan            = true
      add_vcs_repo                  = true
      auto_apply                    = true
      execution_mode                = "local"
      file_triggers_enabled         = false
      global_remote_state           = true
      name                          = "vpc-us-east-2"
      oauth_token_id                = data.terraform_remote_state.tfc_organization.outputs.oauth_client_id
      queue_all_runs                = true
      speculative_enabled           = false
      structured_run_output_enabled = true
      tags                          = ["source:aws", "env:dev", "aws_region:us-east-2"]
      tfe_token                     = var.terraform_api_token
      vcs_repository                = "/terraform-aws-vpc"
      vcs_branch                    = "main"
      working_directory             = "./us-east-2"
    },
    "vpc-us-west-1" = {
      allow_destroy_plan            = true
      add_vcs_repo                  = true
      auto_apply                    = true
      execution_mode                = "local"
      file_triggers_enabled         = false
      global_remote_state           = true
      name                          = "vpc-us-west-1"
      oauth_token_id                = data.terraform_remote_state.tfc_organization.outputs.oauth_client_id
      queue_all_runs                = true
      speculative_enabled           = false
      structured_run_output_enabled = true
      tags                          = ["source:aws", "env:dev","aws_region:us-west-1"]
      tfe_token                     = var.terraform_api_token
      vcs_repository                = "/terraform-aws-vpc"
      vcs_branch                    = "main"
      working_directory             = "./us-west-1"
    },
    "vpc-us-west-2" = {
      allow_destroy_plan            = true
      add_vcs_repo                  = true
      auto_apply                    = true
      execution_mode                = "local"
      file_triggers_enabled         = false
      global_remote_state           = true
      name                          = "vpc-us-west-2"
      oauth_token_id                = data.terraform_remote_state.tfc_organization.outputs.oauth_client_id
      queue_all_runs                = true
      speculative_enabled           = false
      structured_run_output_enabled = true
      tags                          = ["source:aws", "env:dev", "aws_region:us-west-2"]
      tfe_token                     = var.terraform_api_token
      vcs_repository                = "/terraform-aws-vpc"
      vcs_branch                    = "main"
      working_directory             = "./us-west-2"
    }
  }
}

module "workspace" {
  source                        = "./terraform-cloud/tfe//modules/tfe_workspace"
  version                       = "0.1.5"
  for_each                      = local.workspace_object
  allow_destroy_plan            = each.value.allow_destroy_plan
  add_vcs_repo                  = each.value.add_vcs_repo
  auto_apply                    = each.value.auto_apply
  execution_mode                = each.value.execution_mode
  file_triggers_enabled         = each.value.file_triggers_enabled
  global_remote_state           = each.value.global_remote_state
  name                          = each.value.name
  oauth_token_id                = each.value.oauth_token_id
  organization                  = module.organization.tfe_organization_id
  queue_all_runs                = each.value.queue_all_runs
  speculative_enabled           = each.value.speculative_enabled
  structured_run_output_enabled = each.value.structured_run_output_enabled
  tags                          = each.value.tags
  tfe_token                     = each.value.tfe_token
  vcs_repository                = each.value.vcs_repository
  vcs_branch                    = each.value.vcs_branch
  working_directory             = each.value.working_directory
}

Debug Output

╷
│ Error: Plugin did not respond
│
│   with module.workspace["vpc-us-west-1"].tfe_workspace.this,
│   on .terraform/modules/workspace/modules/tfe_workspace/main.tf line 1, in resource "tfe_workspace" "this":
│    1: resource "tfe_workspace" "this" {
│
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ApplyResourceChange call. The
│ plugin logs may contain more details.
╵
╷
│ Error: Request cancelled
│
│   with module.workspace["vpc-us-east-2"].tfe_workspace.this,
│   on .terraform/modules/workspace/modules/tfe_workspace/main.tf line 1, in resource "tfe_workspace" "this":
│    1: resource "tfe_workspace" "this" {
│
│ The plugin.(*GRPCProvider).ApplyResourceChange request was cancelled.
╵
╷
│ Error: Plugin did not respond
│
│   with module.workspace["vpc-us-west-2"].tfe_workspace.this,
│   on .terraform/modules/workspace/modules/tfe_workspace/main.tf line 1, in resource "tfe_workspace" "this":
│    1: resource "tfe_workspace" "this" {
│
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ApplyResourceChange call. The
│ plugin logs may contain more details.
╵
╷
│ Error: Request cancelled
│
│   with module.workspace["vpc-us-east-1"].tfe_workspace.this,
│   on .terraform/modules/workspace/modules/tfe_workspace/main.tf line 1, in resource "tfe_workspace" "this":
│    1: resource "tfe_workspace" "this" {
│
│ The plugin.(*GRPCProvider).ApplyResourceChange request was cancelled.
╵

Stack trace from the terraform-provider-tfe_v0.30.2_x5 plugin:

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

goroutine 194 [running]:github.com/hashicorp/terraform-provider-tfe/tfe.resourceTFEWorkspaceUpdate(0xc000207880, {0xe981e0, 0xc0000a8700})
        /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-tfe/tfe/resource_tfe_workspace.go:446 +0x2ecd
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).update(0xde56c0, {0x10f6c60, 0xc00039a740}, 0x24, {0xe981e0, 0xc0000a8700})
        /opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/v2@v2.7.1/helper/schema/resource.go:352 +0x178
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc0002fefc0, {0x10f6c60, 0xc00039a740}, 0xc0005400e0, 0xc0004346c0, {0xe981e0, 0xc0000a8700})
        /opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/v2@v2.7.1/helper/schema/resource.go:464 +0x6ba
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc00018cfa8, {0x10f6c60, 0xc00039a740}, 0xc0007d0500)
        /opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/v2@v2.7.1/helper/schema/grpc_provider.go:955 +0x9aa
github.com/hashicorp/terraform-plugin-mux.SchemaServer.ApplyResourceChange({0xc0002267b0, 0xc0002267e0, {0xc000090320, 0x2, 0x2}, 0xc000134e80, 0x1}, {0x10f6c60, 0xc00039a740}, 0xc0007d0500)
        /opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/hashicorp/terraform-plugin-mux@v0.2.0/schema_server.go:287 +0x91
github.com/hashicorp/terraform-plugin-go/tfprotov5/server.(*server).ApplyResourceChange(0xc000090360, {0x10f6d08, 0xc00082ca50}, 0x50)
        /opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.3.1/tfprotov5/server/server.go:332 +0x6c
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0xec74c0, 0xc000090360}, {0x10f6d08, 0xc00082ca50}, 0xc0001146c0, 0x0)
        /opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.3.1/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:380 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0001e4380, {0x11080e0, 0xc000724180}, 0xc000b2c300, 0xc000226870, 0x17380e0, 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(0xc0001e4380, {0x11080e0, 0xc000724180}, 0xc000b2c300, 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.30.2_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 had previously run the apply with two workspace_objects for vpc-us-east-1 and vpc-us-east-2. Adding the two additional workspace objects to the locals block resulted in the crash. This also previously happened when I started with just vpc-us-east-1 as a workspace object and then add the second for vpc-us-east-2.

Actual Behavior

Plugin crashed and the request was cancelled.

Additional Context

annawinkler commented 2 years ago

Hi @Dev0psPleb - thank you for submitting this issue! We're looking into the problem, and I was wondering if it might be possible for you to share the referenced file .terraform/modules/workspace/modules/tfe_workspace/main.tf?

willdafoe commented 2 years ago

Hi @Dev0psPleb - thank you for submitting this issue! We're looking into the problem, and I was wondering if it might be possible for you to share the referenced file .terraform/modules/workspace/modules/tfe_workspace/main.tf?

Hi @annawinkler,

Here's main.tf for the referenced module:

resource "tfe_workspace" "this" { 
   allow_destroy_plan            = var.allow_destroy_plan 
   auto_apply                    = var.auto_apply 
   description                   = var.workspace_description 
   execution_mode                = var.execution_mode 
   file_triggers_enabled         = var.file_triggers_enabled 
   global_remote_state           = var.global_remote_state 
   name                          = var.name 
   organization                  = var.organization 
   queue_all_runs                = var.queue_all_runs 
   speculative_enabled           = var.speculative_enabled 
   structured_run_output_enabled = var.structured_run_output_enabled 
   ssh_key_id                    = var.ssh_key_id 
   terraform_version             = var.terraform_version 
   trigger_prefixes              = var.trigger_prefixes 
   working_directory             = var.working_directory 

   dynamic "vcs_repo" { 
     for_each = var.add_vcs_repo ? [1] : [] 
     content { 
       identifier         = var.vcs_repository 
       branch             = var.vcs_branch 
       oauth_token_id     = var.oauth_token_id 
       ingress_submodules = var.ingress_submodules 
     } 
   } 

   tag_names = var.tags 
 }
annawinkler commented 2 years ago

Thank you! I've submitted an issue for this problem.