Merge pull request #27910 from hashicorp/jbardin/remote-provisioners

remote provisioners require a connection config
This commit is contained in:
James Bardin 2021-02-24 13:35:24 -05:00 committed by GitHub
commit 2b252ac677
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 0 deletions

View File

@ -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)

View File

@ -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)
}
}

View File

@ -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)

View File

@ -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)
}
}