func (p *ResourceProvisioner) Apply(s *terraform.ResourceState, c *terraform.ResourceConfig) error { // Ensure the connection type is SSH if err := helper.VerifySSH(s); err != nil { return err } // Get the SSH configuration conf, err := helper.ParseSSHConfig(s) if err != nil { return err } // Collect the scripts scripts, err := p.collectScripts(c) if err != nil { return err } for _, s := range scripts { defer s.Close() } // Copy and execute each script if err := p.runScripts(conf, scripts); err != nil { return err } return nil }