fix provisioner tests
Add host where required in the test configs, and fix the mock to check for a null connection.
This commit is contained in:
parent
c552284157
commit
0b59f9cad2
|
@ -5675,11 +5675,8 @@ func TestContext2Apply_provisionerDestroyRefInvalid(t *testing.T) {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
if _, diags := ctx.Plan(); diags.HasErrors() {
|
// this was an apply test, but this is now caught in Validation
|
||||||
t.Fatalf("plan errors: %s", diags.Err())
|
if diags := ctx.Validate(); !diags.HasErrors() {
|
||||||
}
|
|
||||||
|
|
||||||
if _, diags := ctx.Apply(); diags == nil {
|
|
||||||
t.Fatal("expected error")
|
t.Fatal("expected error")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -374,8 +374,9 @@ func TestEvalValidateProvisioner_valid(t *testing.T) {
|
||||||
Config: hcl.EmptyBody(),
|
Config: hcl.EmptyBody(),
|
||||||
},
|
},
|
||||||
ConnConfig: &configs.Connection{
|
ConnConfig: &configs.Connection{
|
||||||
//Type: "ssh",
|
Config: configs.SynthBody("", map[string]cty.Value{
|
||||||
Config: hcl.EmptyBody(),
|
"host": cty.StringVal("foo"),
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -421,6 +422,7 @@ func TestEvalValidateProvisioner_warning(t *testing.T) {
|
||||||
},
|
},
|
||||||
ConnConfig: &configs.Connection{
|
ConnConfig: &configs.Connection{
|
||||||
Config: configs.SynthBody("", map[string]cty.Value{
|
Config: configs.SynthBody("", map[string]cty.Value{
|
||||||
|
"host": cty.StringVal("localhost"),
|
||||||
"type": cty.StringVal("ssh"),
|
"type": cty.StringVal("ssh"),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
@ -442,7 +444,7 @@ func TestEvalValidateProvisioner_warning(t *testing.T) {
|
||||||
var diags tfdiags.Diagnostics
|
var diags tfdiags.Diagnostics
|
||||||
diags = diags.Append(err)
|
diags = diags.Append(err)
|
||||||
if len(diags) != 1 {
|
if len(diags) != 1 {
|
||||||
t.Fatalf("wrong number of diagsnostics in %#v; want one warning", diags)
|
t.Fatalf("wrong number of diagnostics in %s; want one warning", diags.ErrWithWarnings())
|
||||||
}
|
}
|
||||||
|
|
||||||
if got, want := diags[0].Description().Summary, mp.ValidateProvisionerConfigResponse.Diagnostics[0].Description().Summary; got != want {
|
if got, want := diags[0].Description().Summary, mp.ValidateProvisionerConfigResponse.Diagnostics[0].Description().Summary; got != want {
|
||||||
|
@ -492,7 +494,7 @@ func TestEvalValidateProvisioner_connectionInvalid(t *testing.T) {
|
||||||
|
|
||||||
var diags tfdiags.Diagnostics
|
var diags tfdiags.Diagnostics
|
||||||
diags = diags.Append(err)
|
diags = diags.Append(err)
|
||||||
if len(diags) != 2 {
|
if len(diags) != 3 {
|
||||||
t.Fatalf("wrong number of diagnostics; want two errors\n\n%s", diags.Err())
|
t.Fatalf("wrong number of diagnostics; want two errors\n\n%s", diags.Err())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package terraform
|
package terraform
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/zclconf/go-cty/cty"
|
"github.com/zclconf/go-cty/cty"
|
||||||
|
@ -79,21 +80,29 @@ func (p *MockProvisioner) ProvisionResource(r provisioners.ProvisionResourceRequ
|
||||||
p.ProvisionResourceCalled = true
|
p.ProvisionResourceCalled = true
|
||||||
p.ProvisionResourceRequest = r
|
p.ProvisionResourceRequest = r
|
||||||
if p.ApplyFn != nil {
|
if p.ApplyFn != nil {
|
||||||
|
if !r.Config.IsKnown() {
|
||||||
|
panic(fmt.Sprintf("cannot provision with unknown value: %#v", r.Config))
|
||||||
|
}
|
||||||
|
|
||||||
schema := p.getSchema()
|
schema := p.getSchema()
|
||||||
rc := NewResourceConfigShimmed(r.Config, schema.Provisioner)
|
rc := NewResourceConfigShimmed(r.Config, schema.Provisioner)
|
||||||
connVal := r.Connection
|
connVal := r.Connection
|
||||||
connMap := map[string]string{}
|
connMap := map[string]string{}
|
||||||
for it := connVal.ElementIterator(); it.Next(); {
|
|
||||||
ak, av := it.Element()
|
|
||||||
name := ak.AsString()
|
|
||||||
|
|
||||||
if !av.IsKnown() || av.IsNull() {
|
if !connVal.IsNull() && connVal.IsKnown() {
|
||||||
continue
|
for it := connVal.ElementIterator(); it.Next(); {
|
||||||
|
ak, av := it.Element()
|
||||||
|
name := ak.AsString()
|
||||||
|
|
||||||
|
if !av.IsKnown() || av.IsNull() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
av, _ = convert.Convert(av, cty.String)
|
||||||
|
connMap[name] = av.AsString()
|
||||||
}
|
}
|
||||||
|
|
||||||
av, _ = convert.Convert(av, cty.String)
|
|
||||||
connMap[name] = av.AsString()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We no longer pass the full instance state to a provisioner, so we'll
|
// We no longer pass the full instance state to a provisioner, so we'll
|
||||||
// construct a partial one that should be good enough for what existing
|
// construct a partial one that should be good enough for what existing
|
||||||
// test mocks need.
|
// test mocks need.
|
||||||
|
|
|
@ -12,12 +12,14 @@ resource "aws_instance" "foo" {
|
||||||
|
|
||||||
resource "aws_instance" "bar" {
|
resource "aws_instance" "bar" {
|
||||||
connection {
|
connection {
|
||||||
|
host = "localhost"
|
||||||
type = "telnet"
|
type = "telnet"
|
||||||
}
|
}
|
||||||
|
|
||||||
provisioner "shell" {
|
provisioner "shell" {
|
||||||
foo = "${aws_instance.foo.value}"
|
foo = "${aws_instance.foo.value}"
|
||||||
connection {
|
connection {
|
||||||
|
host = "localhost"
|
||||||
type = "telnet"
|
type = "telnet"
|
||||||
user = "superuser"
|
user = "superuser"
|
||||||
port = 2222
|
port = 2222
|
||||||
|
|
|
@ -25,6 +25,7 @@ resource "aws_load_balancer" "weblb" {
|
||||||
provisioner "shell" {
|
provisioner "shell" {
|
||||||
cmd = "add ${aws_instance.web.id}"
|
cmd = "add ${aws_instance.web.id}"
|
||||||
connection {
|
connection {
|
||||||
|
host = "localhost"
|
||||||
type = "magic"
|
type = "magic"
|
||||||
user = "${aws_security_group.firewall.id}"
|
user = "${aws_security_group.firewall.id}"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue