This default value is not compatible with the variable’s type constraint: element “tags”: string required

Solution for This default value is not compatible with the variable’s type constraint: element “tags”: string required
is Given Below:

I am trying to add the type but its not picking it up I am confused how to give the boot_disk and ‘network_interface’ type if I created the type as object.
Error : │ This default value is not compatible with the variable's type constraint: element "tags": string required.

variable worker {
    type        = map(string)
    default     = {
        worker_count = 2
        name         = "k3s-master"
        machine_type = "n1-standard-1"
        tags         = ["k3s", "k3s-master"]
        zone         = "us-central1-a"


        boot_disk = {
            initialize_params = {
            image = "debian-9-stretch-v20200805"
            }
        }

        network_interface = {
            network = "default"
        }
    }
}

@MarkoE’s answer in the comment is close, but not quite correct. Terraform’s map type is a “collection”, and per Terraform’s documentation, “all elements of a collection must always be of the same type.”

Since your variable has different types for different fields (e.g. worker_count is a number, but tags is a list(string)), map(any) will not work.

Since it looks like you want to strictly type the variable, what you probably want is the object type. In your case, it would look something like this:

variable "worker" {
    type = object({
      worker_count = number
      name         = string
      machine_type = string
      tags         = list(string)
      zone         = string
      boot_disk    = object({
        initialize_params = object({
          image = string
        })
      })
      network_interface = object({
        network = string
      })
    })

    default = ...
}