Merge pull request #27910 from hashicorp/jbardin/remote-provisioners
remote provisioners require a connection config
This commit is contained in:
commit
2b252ac677
|
@ -74,6 +74,11 @@ func (p *provisioner) ValidateProvisionerConfig(req provisioners.ValidateProvisi
|
|||
}
|
||||
|
||||
func (p *provisioner) ProvisionResource(req provisioners.ProvisionResourceRequest) (resp provisioners.ProvisionResourceResponse) {
|
||||
if req.Connection.IsNull() {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(errors.New("missing connection configuration for provisioner"))
|
||||
return resp
|
||||
}
|
||||
|
||||
comm, err := communicator.New(req.Connection)
|
||||
if err != nil {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(err)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package file
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/provisioners"
|
||||
|
@ -102,3 +103,16 @@ func TestResourceProvisioner_StopClose(t *testing.T) {
|
|||
p.Stop()
|
||||
p.Close()
|
||||
}
|
||||
|
||||
func TestResourceProvisioner_connectionRequired(t *testing.T) {
|
||||
p := New()
|
||||
resp := p.ProvisionResource(provisioners.ProvisionResourceRequest{})
|
||||
if !resp.Diagnostics.HasErrors() {
|
||||
t.Fatal("expected error")
|
||||
}
|
||||
|
||||
got := resp.Diagnostics.Err().Error()
|
||||
if !strings.Contains(got, "missing connection") {
|
||||
t.Fatalf("expected 'missing connection' error: got %q", got)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,6 +85,11 @@ func (p *provisioner) ValidateProvisionerConfig(req provisioners.ValidateProvisi
|
|||
}
|
||||
|
||||
func (p *provisioner) ProvisionResource(req provisioners.ProvisionResourceRequest) (resp provisioners.ProvisionResourceResponse) {
|
||||
if req.Connection.IsNull() {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(errors.New("missing connection configuration for provisioner"))
|
||||
return resp
|
||||
}
|
||||
|
||||
comm, err := communicator.New(req.Connection)
|
||||
if err != nil {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(err)
|
||||
|
|
|
@ -261,3 +261,16 @@ func TestResourceProvisioner_StopClose(t *testing.T) {
|
|||
p.Stop()
|
||||
p.Close()
|
||||
}
|
||||
|
||||
func TestResourceProvisioner_connectionRequired(t *testing.T) {
|
||||
p := New()
|
||||
resp := p.ProvisionResource(provisioners.ProvisionResourceRequest{})
|
||||
if !resp.Diagnostics.HasErrors() {
|
||||
t.Fatal("expected error")
|
||||
}
|
||||
|
||||
got := resp.Diagnostics.Err().Error()
|
||||
if !strings.Contains(got, "missing connection") {
|
||||
t.Fatalf("expected 'missing connection' error: got %q", got)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue