-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathprovisioner.go
66 lines (53 loc) · 1.67 KB
/
provisioner.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"fmt"
"github.com/hashicorp/terraform/communicator/winrm"
"github.com/hashicorp/terraform/helper/config"
"github.com/hashicorp/terraform/terraform"
"log"
)
// Provisioner creates the Octopus Deploy resource provisioner.
func Provisioner() terraform.ResourceProvisioner {
return &OctopusProvisioner{}
}
// OctopusProvisioner represents the Octopus Deploy provisioner.
type OctopusProvisioner struct {
// TODO: Decide what state we need to hold for the provisioner.
}
// Apply executes provisioner
func (provisioner *OctopusProvisioner) Apply(output terraform.UIOutput, state *terraform.InstanceState, cfg *terraform.ResourceConfig) error {
log.Print("Executing Octopus Deploy provisioner.")
err := ensureConnectionIsWinRM(state)
if err != nil {
return err
}
communicator, err := winrm.New(state)
if err != nil {
return err
}
communicator.Connect(output)
defer communicator.Disconnect()
// TODO: Use communicator to upload and execute provisioning script.
return nil
}
// Validate checks if the required arguments are configured for the provisioner.
func (provisioner *OctopusProvisioner) Validate(cfg *terraform.ResourceConfig) (warnings []string, errors []error) {
validator := config.Validator{
Required: []string{
// TODO: List required fields.
},
Optional: []string{
// TODO: List optional fields.
},
}
return validator.Validate(cfg)
}
func ensureConnectionIsWinRM(state *terraform.InstanceState) error {
connectionType := state.Ephemeral.ConnInfo["type"]
switch connectionType {
case "winrm":
return nil
default:
return fmt.Errorf("Connection type '%s' not supported for provisioning Octopus Deploy", connectionType)
}
}