hashicorp/terraform · error
invalid null string in 'scripts'
Error message
invalid null string in 'scripts'
What it means
Error from generateScripts() while iterating the 'inline' list of the remote-exec provisioner: a list element is null (cty.NullVal). Each inline entry must be a non-null string.
Source
Thrown at internal/builtin/provisioners/remote-exec/resource_provisioner.go:158
return resp
}
func (p *provisioner) Stop() error {
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() {View on GitHub (pinned to c9def3e214)
Solutions
- Filter nulls out of the inline list, e.g. inline = [for c in var.commands : c if c != null].
- Ensure every element of the list variable is a concrete string.
Example fix
// before
variable "commands" { type = list(string) }
provisioner "remote-exec" {
inline = var.commands
}
// after
provisioner "remote-exec" {
inline = [for c in var.commands : c if c != null]
} Defensive patterns
Strategy: validation
Validate before calling
# Strip null entries from inline before passing to the provisioner:
# inline = [for c in var.commands : c if c != null]
# Or type the variable so nulls cannot enter:
variable "commands" { type = list(string) } Prevention
- Type list variables as list(string), not list(any).
- Apply compact()/filter to drop nulls from generated lists.
- Validate module inputs with terraform validate in CI.
When it happens
Trigger: provisioner "remote-exec" { inline = ["echo hi", null] } — a null element, commonly produced by a list variable containing a null item.
Common situations: A variable like var.commands that includes a null element (e.g. conditional that yields null); compact() not applied to a sparse list.
Related errors
- invalid empty string in 'scripts'
- invalid empty string in 'script'
- invalid null string in 'script'
- Cannot set both 'source' and 'content'
- Must provide one of 'source' or 'content'
AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07).
Data as JSON: /api/errors/5e8866169084871e.
Report an issue: GitHub.