profile
viewpoint

Ask questionsProvider Development: Expected type 'string', got unconvertible type '[]interface {}' - with complicated block

Hi there,

I am working on provider development. My template file should support a complicated block like that

resource "myresource" "my_resource" {
  name = "my name"
  description = "description"

  deployment_map = {
    "database" = ["target1", "target2", "target3"]
    "comp" = ["target4", "target5"]
  }
}

When I run terraform plan, it got error as below

'' expected type 'string', got unconvertible type '[]interface {}'

In debug mode, the message is as below

config is invalid: Incorrect attribute value type: Inappropriate value for attribute "deployment_map": element "database": string required.

I think it comes from terraform config/language. Please have a look at that.

Thanks,

hashicorp/terraform

Answer questions donglev91

Hi there, I truly forgot to define Elem type, and it got the default one is TypeString as you said. Now I fixed it with more complex schema as your suggestion, it got another error "panic: Unknown validation type: 6". It seems Map value does not support TypeList now (I saw supported types are TypeBool, TypeInt, TypeFloat, TypeString). Please check that. Below is my schema of deployment_map

"deployment_map":{  
   Type:schema.TypeMap,
   Elem:&schema.Schema   {  
      Type:schema.TypeList,
      Elem:&schema.Schema      {  
         Type:schema.TypeString,

      },

   },
   Optional:true,

},

Thanks for your support.

useful!
source:https://uonfu.com/
Github User Rank List