hashicorp/terraform · error

invalid null string in 'script'

Error message

invalid null string in 'script'

What it means

Error from collectScripts() while iterating the 'scripts' list of the remote-exec provisioner: a list element is null (cty.NullVal). Each scripts entry (a file path) must be a non-null string.

Source

Thrown at internal/builtin/provisioners/remote-exec/resource_provisioner.go:203

		}

		return r, nil
	}

	// Collect scripts
	var scripts []string
	if script := v.GetAttr("script"); !script.IsNull() {
		s := script.AsString()
		if s == "" {
			return nil, errors.New("invalid empty string in 'script'")
		}
		scripts = append(scripts, s)
	}

	if scriptList := v.GetAttr("scripts"); !scriptList.IsNull() {
		for _, script := range scriptList.AsValueSlice() {
			if script.IsNull() {
				return nil, errors.New("invalid null string in 'script'")
			}
			s := script.AsString()
			if s == "" {
				return nil, errors.New("invalid empty string in 'script'")
			}
			scripts = append(scripts, s)
		}
	}

	// Open all the scripts
	var fhs []io.ReadCloser
	for _, s := range scripts {
		fh, err := os.Open(s)
		if err != nil {
			for _, fh := range fhs {
				fh.Close()
			}
			return nil, fmt.Errorf("Failed to open script '%s': %v", s, err)

View on GitHub (pinned to c9def3e214)

Solutions

  1. Filter nulls: scripts = [for s in var.script_paths : s if s != null].
  2. Ensure every list element is a real file path string.

Example fix

// before
provisioner "remote-exec" {
  scripts = var.script_paths
}
// after
provisioner "remote-exec" {
  scripts = [for s in var.script_paths : s if s != null]
}
Defensive patterns

Strategy: validation

Validate before calling

# Filter nulls from the scripts list:
# scripts = [for s in var.script_paths : s if s != null]

Prevention

When it happens

Trigger: provisioner "remote-exec" { scripts = ["a.sh", null] } — a null path element, commonly from a list variable with a null item.

Common situations: var.script_paths containing a null element; conditional list building that leaves a null.

Related errors


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