This repository has been archived by the owner on Jul 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 100
/
provision.go
80 lines (72 loc) · 2.09 KB
/
provision.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
package eventhubs
import (
"context"
"fmt"
"github.com/Azure/open-service-broker-azure/pkg/service"
uuid "github.com/satori/go.uuid"
)
func (s *serviceManager) GetProvisioner(
service.Plan,
) (service.Provisioner, error) {
return service.NewProvisioner(
service.NewProvisioningStep("preProvision", s.preProvision),
service.NewProvisioningStep("deployARMTemplate", s.deployARMTemplate),
)
}
func (s *serviceManager) preProvision(
context.Context,
service.Instance,
) (service.InstanceDetails, error) {
return &instanceDetails{
ARMDeploymentName: uuid.NewV4().String(),
EventHubName: uuid.NewV4().String(),
EventHubNamespace: "eh-" + uuid.NewV4().String(),
}, nil
}
func (s *serviceManager) deployARMTemplate(
_ context.Context,
instance service.Instance,
) (service.InstanceDetails, error) {
dt := instance.Details.(*instanceDetails)
tagsObj := instance.ProvisioningParameters.GetObject("tags")
tags := make(map[string]string, len(tagsObj.Data))
for k := range tagsObj.Data {
tags[k] = tagsObj.GetString(k)
}
outputs, err := s.armDeployer.Deploy(
dt.ARMDeploymentName,
instance.ProvisioningParameters.GetString("resourceGroup"),
instance.ProvisioningParameters.GetString("location"),
armTemplateBytes,
map[string]interface{}{
"location": instance.ProvisioningParameters.GetString("location"), // nolint: lll
"eventHubName": dt.EventHubName,
"eventHubNamespace": dt.EventHubNamespace,
"eventHubSku": instance.Plan.
GetProperties().Extended["eventHubSku"],
},
map[string]interface{}{},
tags,
)
if err != nil {
return nil, fmt.Errorf("error deploying ARM template: %s", err)
}
var ok bool
connectionString, ok := outputs["connectionString"].(string)
if !ok {
return nil, fmt.Errorf(
"error retrieving connection string from deployment: %s",
err,
)
}
dt.ConnectionString = service.SecureString(connectionString)
primaryKey, ok := outputs["primaryKey"].(string)
if !ok {
return nil, fmt.Errorf(
"error retrieving primary key from deployment: %s",
err,
)
}
dt.PrimaryKey = service.SecureString(primaryKey)
return dt, err
}