hashicorp/terraform · error

invalid empty string in 'scripts'

Error message

invalid empty string in 'scripts'

What it means

Error from generateScripts() when an 'inline' list element is an empty string (""). Each inline script must be non-empty.

Source

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

	p.cancel()
	return nil
}

func (p *provisioner) Close() error {
	return nil
}

// generateScripts takes the configuration and creates a script from each inline config
func generateScripts(inline cty.Value) ([]string, error) {
	var lines []string
	for _, l := range inline.AsValueSlice() {
		if l.IsNull() {
			return nil, errors.New("invalid null string in 'scripts'")
		}

		s := l.AsString()
		if s == "" {
			return nil, errors.New("invalid empty string in 'scripts'")
		}
		lines = append(lines, s)
	}
	lines = append(lines, "")

	return []string{strings.Join(lines, "\n")}, nil
}

// collectScripts is used to collect all the scripts we need
// to execute in preparation for copying them.
func collectScripts(v cty.Value) ([]io.ReadCloser, error) {
	// Check if inline
	if inline := v.GetAttr("inline"); !inline.IsNull() {
		scripts, err := generateScripts(inline)
		if err != nil {
			return nil, err
		}

View on GitHub (pinned to c9def3e214)

Solutions

  1. Remove empty entries: inline = [for c in var.commands : c if c != ""].
  2. Sanitize the source list so all entries are real command strings.

Example fix

// before
provisioner "remote-exec" {
  inline = var.commands
}
// after
provisioner "remote-exec" {
  inline = [for c in var.commands : c if c != ""]
}
Defensive patterns

Strategy: validation

Validate before calling

# Drop empty strings from inline:
# inline = [for c in var.commands : c if c != ""]

Prevention

When it happens

Trigger: provisioner "remote-exec" { inline = ["echo hi", ""] } — an empty element, often from a list variable with blank entries.

Common situations: A variable populated from an external source that yields blank strings; leftover placeholder in a list literal.

Related errors


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