/
install.go
88 lines (77 loc) · 1.98 KB
/
install.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package arm
import (
"context"
"fmt"
"strings"
"github.com/pkg/errors"
yaml "gopkg.in/yaml.v2"
)
type InstallAction struct {
Steps []InstallStep `yaml:"install"`
}
type InstallStep struct {
InstallArguments `yaml:"arm"`
}
type InstallArguments struct {
Step `yaml:",inline"`
Template string `yaml:"template"`
Name string `yaml:"name"`
ResourceGroup string `yaml:"resourceGroup"`
Parameters map[string]interface{} `yaml:"parameters"`
}
func (m *Mixin) Install(ctx context.Context) error {
payload, err := m.getPayloadData()
if err != nil {
return err
}
var action InstallAction
err = yaml.Unmarshal(payload, &action)
if err != nil {
return err
}
if len(action.Steps) != 1 {
return errors.Errorf("expected a single step, but got %d", len(action.Steps))
}
step := action.Steps[0]
// Get the arm deployer
deployer, err := m.getARMDeployer()
if err != nil {
return err
}
// Get the Template based on the arguments (type)
t, err := deployer.FindTemplate(step.Template)
if err != nil {
return err
}
fmt.Fprintln(m.Out, "Starting deployment operations...")
// call Deployer.Deploy(...)
outputs, err := deployer.Deploy(
step.Name,
step.ResourceGroup,
step.Parameters["location"].(string),
t,
step.Parameters, // arm params
)
if err != nil {
return err
}
fmt.Fprintln(m.Out, "Finished deployment operations...")
// ARM does some stupid stuff with output keys, turn them
// all into upper case for better matching
for k, v := range outputs {
newKey := strings.ToUpper(k)
outputs[newKey] = v
}
for _, output := range step.Outputs {
// ToUpper the key because of the case weirdness with ARM outputs
v, ok := outputs[strings.ToUpper(output.Key)]
if !ok {
return fmt.Errorf("couldn't find output key")
}
err := m.WriteMixinOutputToFile(output.Name, []byte(fmt.Sprintf("%v", v)))
if err != nil {
return errors.Wrapf(err, "unable to write output '%s'", output.Name)
}
}
return nil
}