-
Notifications
You must be signed in to change notification settings - Fork 32
/
settings.go
111 lines (104 loc) · 3.91 KB
/
settings.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
/**
* @license
* Copyright 2020 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ipmappings
import (
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/opt"
"github.com/dynatrace-oss/terraform-provider-dynatrace/terraform/hcl"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
type Settings struct {
City *string `json:"city,omitempty"` // The city name of the location.
CountryCode string `json:"countryCode"` // The country code of the location. \n\n Use the alpha-2 code of the [ISO 3166-2 standard](https://dt-url.net/iso3166-2), (for example, `AT` for Austria or `PL` for Poland).
Ip string `json:"ip"` // Single IP or IP range start address
IpTo *string `json:"ipTo,omitempty"` // IP range end
Latitude *float64 `json:"latitude,omitempty"` // Latitude
Longitude *float64 `json:"longitude,omitempty"` // Longitude
RegionCode *string `json:"regionCode,omitempty"` // The region code of the location. \n\n For the [USA](https://dt-url.net/iso3166us) or [Canada](https://dt-url.net/iso3166ca) use ISO 3166-2 state codes without `US-` or `CA-` prefix. \n\n For the rest of the world use [FIPS 10-4 codes](https://dt-url.net/fipscodes) without country prefix.
}
func (me *Settings) Name() string {
return me.Ip
}
func (me *Settings) Schema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"city": {
Type: schema.TypeString,
Description: "The city name of the location.",
Optional: true,
},
"country_code": {
Type: schema.TypeString,
Description: "The country code of the location. \n\n Use the alpha-2 code of the [ISO 3166-2 standard](https://dt-url.net/iso3166-2), (for example, `AT` for Austria or `PL` for Poland).",
Required: true,
},
"ip": {
Type: schema.TypeString,
Description: "Single IP or IP range start address",
Required: true,
},
"ip_to": {
Type: schema.TypeString,
Description: "IP range end",
Optional: true,
},
"latitude": {
Type: schema.TypeFloat,
Description: "Latitude",
Optional: true,
},
"longitude": {
Type: schema.TypeFloat,
Description: "Longitude",
Optional: true,
},
"region_code": {
Type: schema.TypeString,
Description: "The region code of the location. \n\n For the [USA](https://dt-url.net/iso3166us) or [Canada](https://dt-url.net/iso3166ca) use ISO 3166-2 state codes without `US-` or `CA-` prefix. \n\n For the rest of the world use [FIPS 10-4 codes](https://dt-url.net/fipscodes) without country prefix.",
Optional: true,
},
}
}
func (me *Settings) MarshalHCL(properties hcl.Properties) error {
return properties.EncodeAll(map[string]any{
"city": me.City,
"country_code": me.CountryCode,
"ip": me.Ip,
"ip_to": me.IpTo,
"latitude": me.Latitude,
"longitude": me.Longitude,
"region_code": me.RegionCode,
})
}
func (me *Settings) UnmarshalHCL(decoder hcl.Decoder) error {
err := decoder.DecodeAll(map[string]any{
"city": &me.City,
"country_code": &me.CountryCode,
"ip": &me.Ip,
"ip_to": &me.IpTo,
"latitude": &me.Latitude,
"longitude": &me.Longitude,
"region_code": &me.RegionCode,
})
if me.City != nil {
if me.Latitude == nil {
me.Latitude = opt.NewFloat64(0)
}
if me.Longitude == nil {
me.Longitude = opt.NewFloat64(0)
}
}
return err
}