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!

Related questions

failed to save provider manifest: open .terraform/plugins/linux_amd64/lock.json: permission denied hot 4
The argument "host" is required, but no definition was found. hot 3
Unable to run 0.12upgrade hot 3
Module cannot find alias AWS provider in 0.12.0 hot 3
Error: Invalid template interpolation value hot 2
Terraform v0.11.1 : Error downloading modules: Error loading modules: open .terraform/modules/3f10921295c292995128e9e36eb: no such file or directory hot 2
MalformedPolicyDocument: Policy document should not specify a principal. hot 2
Error in Terraform 0.12.0: This object has no argument, nested block, or exported attribute hot 2
Feature Request - Allow list/array in 'query' in 'external' data source hot 2
Terraform provider downloads fail with TLS handshake timeout hot 2
'terraform init' failed with 'Registry service unreachable.' error hot 2
for_each attribute for creating multiple resources based on a map hot 2
`Unreadable module directory` error is not clear for nested modules hot 2
Error loading state: state snapshot was created by Terraform v0.12.7, which is newer than current v0.12.6 hot 2
[BUG] Terraform 0.12.x corrupts state when upgrading from 0.11.14 hot 1
Github User Rank List