-
Notifications
You must be signed in to change notification settings - Fork 31
/
location.go
163 lines (148 loc) · 5.28 KB
/
location.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package locations
import "github.com/dtcookie/hcl"
type Locations []*Location
func (me Locations) Schema() map[string]*hcl.Schema {
return map[string]*hcl.Schema{
"location": {
Type: hcl.TypeList,
Description: "The name of the location",
Optional: true,
Elem: &hcl.Resource{Schema: new(Location).Schema()},
},
}
}
func (me *Locations) MarshalHCL() (map[string]interface{}, error) {
result := map[string]interface{}{}
entries := []interface{}{}
for _, entry := range *me {
if marshalled, err := entry.MarshalHCL(); err == nil {
entries = append(entries, marshalled)
} else {
return nil, err
}
}
result["location"] = entries
return result, nil
}
type Location struct {
ID string `json:"id"` // The unique id of the location
Name string `json:"name"` // The name of the location
Type LocationType `json:"type"` // Defines the actual set of fields depending on the value. See one of the following objects: \n\n* `PUBLIC` -> PublicSyntheticLocation \n* `PRIVATE` -> PrivateSyntheticLocation \n* `CLUSTER` -> PrivateSyntheticLocation
Status *Status `json:"status"` // The status of the location: \n\n* `ENABLED`: The location is displayed as active in the UI. You can assign monitors to the location. \n* `DISABLED`: The location is displayed as inactive in the UI. You can't assign monitors to the location. Monitors already assigned to the location will stay there and will be executed from the location. \n* `HIDDEN`: The location is not displayed in the UI. You can't assign monitors to the location. You can only set location as `HIDDEN` when no monitor is assigned to it
CloudPlatform *CloudPlatform `json:"cloudPlatform"` // The cloud provider where the location is hosted. \n\n Only applicable to `PUBLIC` locations
IPs []string `json:"ips"` // The list of IP addresses assigned to the location. \n\n Only applicable to `PUBLIC` locations
Stage *Stage `json:"stage"` // The release stage of the location
}
func (me *Location) Schema() map[string]*hcl.Schema {
return map[string]*hcl.Schema{
"id": {
Type: hcl.TypeString,
Description: "The unique ID of the location",
Optional: true,
},
"name": {
Type: hcl.TypeString,
Description: "The name of the location",
Optional: true,
},
"type": {
Type: hcl.TypeString,
Description: "The type of the location. Supported values are `PUBLIC`, `PRIVATE` and `CLUSTER`",
Optional: true,
},
"status": {
Type: hcl.TypeString,
Description: "The status of the location: \n\n* `ENABLED`: The location is displayed as active in the UI. You can assign monitors to the location. \n* `DISABLED`: The location is displayed as inactive in the UI. You can't assign monitors to the location. Monitors already assigned to the location will stay there and will be executed from the location. \n* `HIDDEN`: The location is not displayed in the UI. You can't assign monitors to the location. You can only set location as `HIDDEN` when no monitor is assigned to it",
Optional: true,
Computed: true,
},
"stage": {
Type: hcl.TypeString,
Description: "The release stage of the location",
Optional: true,
Computed: true,
},
"cloud_platform": {
Type: hcl.TypeString,
Description: "The cloud provider where the location is hosted. \n\n Only applicable to `PUBLIC` locations",
Optional: true,
Computed: true,
},
"ips": {
Type: hcl.TypeList,
Description: "The list of IP addresses assigned to the location. \n\n Only applicable to `PUBLIC` locations",
Elem: &hcl.Schema{Type: hcl.TypeString},
Optional: true,
Computed: true,
},
}
}
func (me *Location) MarshalHCL() (map[string]interface{}, error) {
result := map[string]interface{}{}
result["id"] = me.ID
result["name"] = me.Name
result["type"] = string(me.Type)
if me.Stage != nil {
result["stage"] = string(*me.Stage)
}
if me.Status != nil {
result["status"] = string(*me.Status)
}
if me.CloudPlatform != nil {
result["cloud_platform"] = string(*me.CloudPlatform)
}
if me.IPs != nil {
result["ips"] = append([]string{}, me.IPs...)
}
return result, nil
}
type Stage string
var Stages = struct {
Beta Stage
ComingSoon Stage
GA Stage
}{
Stage("BETA"),
Stage("COMING_SOON"),
Stage("GA"),
}
type CloudPlatform string
var CloudPlatforms = struct {
Alibaba CloudPlatform
AmaconEC2 CloudPlatform
Azure CloudPlatform
DynatraceCloud CloudPlatform
GoogleCloud CloudPlatform
Interoute CloudPlatform
Other CloudPlatform
Undefined CloudPlatform
}{
CloudPlatform("ALIBABA"),
CloudPlatform("AMAZON_EC2"),
CloudPlatform("AZURE"),
CloudPlatform("DYNATRACE_CLOUD"),
CloudPlatform("GOOGLE_CLOUD"),
CloudPlatform("INTEROUTE"),
CloudPlatform("OTHER"),
CloudPlatform("UNDEFINED"),
}
type Status string
var Statuses = struct {
Disabled Status
Enabled Status
Hidden Status
}{
Status("DISABLED"),
Status("ENABLED"),
Status("HIDDEN"),
}
type LocationType string
var LocationTypes = struct {
Public LocationType
Private LocationType
Cluster LocationType
}{
LocationType("PUBLIC"),
LocationType("PRIVATE"),
LocationType("CLUSTER"),
}