mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-30 10:47:14 -06:00
builtin/provisioners/*: new API
This commit is contained in:
parent
53ebc5cb51
commit
8720d2465e
@ -14,31 +14,31 @@ import (
|
||||
type ResourceProvisioner struct{}
|
||||
|
||||
func (p *ResourceProvisioner) Apply(s *terraform.ResourceState,
|
||||
c *terraform.ResourceConfig) (*terraform.ResourceState, error) {
|
||||
c *terraform.ResourceConfig) error {
|
||||
// Ensure the connection type is SSH
|
||||
if err := helper.VerifySSH(s); err != nil {
|
||||
return s, err
|
||||
return err
|
||||
}
|
||||
|
||||
// Get the SSH configuration
|
||||
conf, err := helper.ParseSSHConfig(s)
|
||||
if err != nil {
|
||||
return s, err
|
||||
return err
|
||||
}
|
||||
|
||||
// Get the source and destination
|
||||
sRaw := c.Config["source"]
|
||||
src, ok := sRaw.(string)
|
||||
if !ok {
|
||||
return s, fmt.Errorf("Unsupported 'source' type! Must be string.")
|
||||
return fmt.Errorf("Unsupported 'source' type! Must be string.")
|
||||
}
|
||||
|
||||
dRaw := c.Config["destination"]
|
||||
dst, ok := dRaw.(string)
|
||||
if !ok {
|
||||
return s, fmt.Errorf("Unsupported 'destination' type! Must be string.")
|
||||
return fmt.Errorf("Unsupported 'destination' type! Must be string.")
|
||||
}
|
||||
return s, p.copyFiles(conf, src, dst)
|
||||
return p.copyFiles(conf, src, dst)
|
||||
}
|
||||
|
||||
func (p *ResourceProvisioner) Validate(c *terraform.ResourceConfig) (ws []string, es []error) {
|
||||
|
@ -21,16 +21,16 @@ type ResourceProvisioner struct{}
|
||||
|
||||
func (p *ResourceProvisioner) Apply(
|
||||
s *terraform.ResourceState,
|
||||
c *terraform.ResourceConfig) (*terraform.ResourceState, error) {
|
||||
c *terraform.ResourceConfig) error {
|
||||
|
||||
// Get the command
|
||||
commandRaw, ok := c.Config["command"]
|
||||
if !ok {
|
||||
return s, fmt.Errorf("local-exec provisioner missing 'command'")
|
||||
return fmt.Errorf("local-exec provisioner missing 'command'")
|
||||
}
|
||||
command, ok := commandRaw.(string)
|
||||
if !ok {
|
||||
return s, fmt.Errorf("local-exec provisioner command must be a string")
|
||||
return fmt.Errorf("local-exec provisioner command must be a string")
|
||||
}
|
||||
|
||||
// Execute the command using a shell
|
||||
@ -51,10 +51,10 @@ func (p *ResourceProvisioner) Apply(
|
||||
|
||||
// Run the command to completion
|
||||
if err := cmd.Run(); err != nil {
|
||||
return s, fmt.Errorf("Error running command '%s': %v. Output: %s",
|
||||
return fmt.Errorf("Error running command '%s': %v. Output: %s",
|
||||
command, err, output.Bytes())
|
||||
}
|
||||
return s, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *ResourceProvisioner) Validate(c *terraform.ResourceConfig) ([]string, []error) {
|
||||
|
@ -21,8 +21,7 @@ func TestResourceProvider_Apply(t *testing.T) {
|
||||
})
|
||||
|
||||
p := new(ResourceProvisioner)
|
||||
_, err := p.Apply(nil, c)
|
||||
if err != nil {
|
||||
if err := p.Apply(nil, c); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
|
@ -23,22 +23,22 @@ const (
|
||||
type ResourceProvisioner struct{}
|
||||
|
||||
func (p *ResourceProvisioner) Apply(s *terraform.ResourceState,
|
||||
c *terraform.ResourceConfig) (*terraform.ResourceState, error) {
|
||||
c *terraform.ResourceConfig) error {
|
||||
// Ensure the connection type is SSH
|
||||
if err := helper.VerifySSH(s); err != nil {
|
||||
return s, err
|
||||
return err
|
||||
}
|
||||
|
||||
// Get the SSH configuration
|
||||
conf, err := helper.ParseSSHConfig(s)
|
||||
if err != nil {
|
||||
return s, err
|
||||
return err
|
||||
}
|
||||
|
||||
// Collect the scripts
|
||||
scripts, err := p.collectScripts(c)
|
||||
if err != nil {
|
||||
return s, err
|
||||
return err
|
||||
}
|
||||
for _, s := range scripts {
|
||||
defer s.Close()
|
||||
@ -46,9 +46,9 @@ func (p *ResourceProvisioner) Apply(s *terraform.ResourceState,
|
||||
|
||||
// Copy and execute each script
|
||||
if err := p.runScripts(conf, scripts); err != nil {
|
||||
return s, err
|
||||
return err
|
||||
}
|
||||
return s, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *ResourceProvisioner) Validate(c *terraform.ResourceConfig) (ws []string, es []error) {
|
||||
|
Loading…
Reference in New Issue
Block a user