hashicorp/terraform · error

tag object values must be strings

Error message

tag object values must be strings

What it means

Config-parsing diagnostic from the cloud backend when workspaces.tags is an object/map type but one of its values is not a cty.String. All tag object values must be strings so they can be collected into a map[string]string.

Source

Thrown at internal/cloud/backend.go:508

		ret.token = val.AsString()
		log.Printf("[TRACE] cloud: found token in cloud config block")
	}

	// Grab any workspace/project info from the nested config object in one go,
	// so it's easier to work with.
	var name, project string
	if workspaces := obj.GetAttr("workspaces"); !workspaces.IsNull() {
		if val := workspaces.GetAttr("name"); !val.IsNull() {
			name = val.AsString()
			log.Printf("[TRACE] cloud: found workspace name %q in cloud config block", name)
		}
		if val := workspaces.GetAttr("tags"); !val.IsNull() {
			log.Printf("[TRACE] tags is a %q type", val.Type().FriendlyName())
			tagsAsMap := make(map[string]string)
			if val.Type().IsObjectType() || val.Type().IsMapType() {
				for k, v := range val.AsValueMap() {
					if v.Type() != cty.String {
						diags = diags.Append(errors.New("tag object values must be strings"))
						return ret, diags
					}
					tagsAsMap[k] = v.AsString()
				}
				log.Printf("[TRACE] cloud: using tags %q from cloud config block", tagsAsMap)
				ret.workspaceMapping.TagsAsMap = tagsAsMap
			} else if val.Type().IsTupleType() || val.Type().IsSetType() {
				var tagsAsSet []string
				length := val.LengthInt()
				if length > 0 {
					it := val.ElementIterator()
					for it.Next() {
						_, v := it.Element()
						if !v.Type().Equals(cty.String) {
							diags = diags.Append(errors.New("tag elements must be strings"))
							return ret, diags
						}
						if vs := v.AsString(); vs != "" {

View on GitHub (pinned to c9def3e214)

Solutions

  1. Ensure every tag value is a string, e.g. tags = { Count = "3" }.
  2. Type the variable as map(string) so non-string values fail earlier.

Example fix

// before
workspaces {
  tags = {
    Count = 3
  }
}
// after
workspaces {
  tags = {
    Count = "3"
  }
}
Defensive patterns

Strategy: validation

Validate before calling

# Type the tags variable as map(string) so non-string values fail early:
variable "tags" { type = map(string) }
# Then: workspaces { tags = var.tags }

Prevention

When it happens

Trigger: workspaces { tags = { Count = 3 } } — a numeric value in the tags object; or any value whose cty type is not cty.String.

Common situations: Passing a number/bool/list as a tag value; a variable typed as map(any) that contains non-string values.

Related errors


AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07). Data as JSON: /api/errors/f5e3a7efa68c9b62. Report an issue: GitHub.