mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Fix: don't panic when both source and content of file provisioner are null (#1376)
Signed-off-by: Zejun Chen <tibazq@gmail.com>
This commit is contained in:
parent
07a9185767
commit
8d2216d24b
@ -149,7 +149,7 @@ func getSrc(v cty.Value) (string, bool, error) {
|
||||
return expansion, false, err
|
||||
|
||||
default:
|
||||
panic("source and content cannot both be null")
|
||||
return "", false, errors.New("source and content cannot both be null")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,3 +121,28 @@ func TestResourceProvisioner_connectionRequired(t *testing.T) {
|
||||
t.Fatalf("expected 'Missing connection' error: got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResourceProvisioner_nullSrcVars(t *testing.T) {
|
||||
conn := cty.ObjectVal(map[string]cty.Value{
|
||||
"type": cty.StringVal(""),
|
||||
"host": cty.StringVal("localhost"),
|
||||
})
|
||||
config := cty.ObjectVal(map[string]cty.Value{
|
||||
"source": cty.NilVal,
|
||||
"content": cty.NilVal,
|
||||
"destination": cty.StringVal("/tmp/bar"),
|
||||
})
|
||||
p := New()
|
||||
resp := p.ProvisionResource(provisioners.ProvisionResourceRequest{
|
||||
Connection: conn,
|
||||
Config: config,
|
||||
})
|
||||
if !resp.Diagnostics.HasErrors() {
|
||||
t.Fatal("expected error")
|
||||
}
|
||||
|
||||
got := resp.Diagnostics.Err().Error()
|
||||
if !strings.Contains(got, "file provisioner error: source and content cannot both be null") {
|
||||
t.Fatalf("file provisioner error: source and content cannot both be null' error: got %q", got)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user