/
schema_resource.go
205 lines (199 loc) · 6.41 KB
/
schema_resource.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package databasepostgresql
import (
"github.com/hashicorp/go-cty/cty"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/linode/terraform-provider-linode/v2/linode/helper"
)
var resourceSchema = map[string]*schema.Schema{
// Required fields
"engine_id": {
Type: schema.TypeString,
Description: "The Managed Database engine in engine/version format. (e.g. mysql/8.0.30)",
Required: true,
ForceNew: true,
},
"label": {
Type: schema.TypeString,
Description: "A unique, user-defined string referring to the Managed Database.",
Required: true,
},
"region": {
Type: schema.TypeString,
Description: "The region to use for the Managed Database.",
Required: true,
ForceNew: true,
},
"type": {
Type: schema.TypeString,
Description: "The Linode Instance type used by the Managed Database for its nodes.",
Required: true,
ForceNew: true,
},
// Optional fields
"allow_list": {
Type: schema.TypeSet,
Description: "A list of IP addresses that can access the Managed Database. " +
"Each item can be a single IP address or a range in CIDR format.",
Optional: true,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"cluster_size": {
Type: schema.TypeInt,
Description: "The number of Linode Instance nodes deployed to the Managed Database. Defaults to 1.",
Optional: true,
Default: 1,
ForceNew: true,
// We should enforce this during plan to prevent invalid DBs from being attempted
ValidateDiagFunc: validation.ToDiagFunc(validation.IntInSlice([]int{1, 3})),
},
"replication_type": {
Type: schema.TypeString,
Description: "The replication method used for the Managed Database. " +
"Must be `none` for a single node cluster. " +
"Must be `asynch` or `semi_synch` for a high availability cluster.",
Optional: true,
Default: "none",
ForceNew: true,
ValidateDiagFunc: validation.ToDiagFunc(validation.All(
validation.StringInSlice([]string{"none", "asynch", "semi_synch"}, false),
)),
},
"replication_commit_type": {
Type: schema.TypeString,
Description: "The synchronization level of the replicating server." +
"Must be `local` or `off` for the `asynch` replication type. " +
"Must be `on`, `remote_write`, or `remote_apply` for the `semi_synch` replication type.",
Optional: true,
Default: "off",
ForceNew: true,
ValidateDiagFunc: validation.ToDiagFunc(validation.All(
validation.StringInSlice([]string{"on", "local", "remote_write", "remote_apply", "off"}, false),
)),
},
"encrypted": {
Type: schema.TypeBool,
Description: "Whether the Managed Databases is encrypted.",
Optional: true,
Default: false,
ForceNew: true,
},
"ssl_connection": {
Type: schema.TypeBool,
Description: "Whether to require SSL credentials to establish a connection to the Managed Database.",
Optional: true,
Default: false,
ForceNew: true,
},
"updates": {
Type: schema.TypeList,
Description: "Configuration settings for automated patch update maintenance for the Managed Database.",
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"day_of_week": {
Type: schema.TypeString,
Description: "The day to perform maintenance.",
Required: true,
ValidateDiagFunc: func(i interface{}, path cty.Path) diag.Diagnostics {
if _, err := helper.ExpandDayOfWeek(i.(string)); err != nil {
return diag.FromErr(err)
}
return nil
},
},
"duration": {
Type: schema.TypeInt,
Description: "The maximum maintenance window time in hours.",
Required: true,
ValidateDiagFunc: validation.ToDiagFunc(validation.IntBetween(1, 3)),
},
"frequency": {
Type: schema.TypeString,
Description: "Whether maintenance occurs on a weekly or monthly basis.",
Required: true,
ValidateDiagFunc: validation.ToDiagFunc(
validation.StringInSlice([]string{"weekly", "monthly"}, true)),
},
"hour_of_day": {
Type: schema.TypeInt,
Description: "The hour to begin maintenance based in UTC time.",
Required: true,
ValidateDiagFunc: validation.ToDiagFunc(validation.IntBetween(0, 23)),
},
"week_of_month": {
Type: schema.TypeInt,
Description: "The week of the month to perform monthly frequency updates." +
" Required for monthly frequency updates.",
ValidateDiagFunc: validation.ToDiagFunc(validation.IntBetween(1, 4)),
Optional: true,
Default: nil,
},
},
},
},
// Computed fields
"ca_cert": {
Type: schema.TypeString,
Description: "The base64-encoded SSL CA certificate for the Managed Database instance.",
Computed: true,
Sensitive: true,
},
"created": {
Type: schema.TypeString,
Description: "When this Managed Database was created.",
Computed: true,
},
"engine": {
Type: schema.TypeString,
Description: "The Managed Database engine.",
Computed: true,
},
// In an attempt to simplify provider/config logic, these should be flattened in schema
"host_primary": {
Type: schema.TypeString,
Description: "The primary host for the Managed Database.",
Computed: true,
},
"host_secondary": {
Type: schema.TypeString,
Description: "The secondary host for the Managed Database.",
Computed: true,
},
"port": {
Type: schema.TypeInt,
Description: "The access port for this Managed Database.",
Computed: true,
},
"root_password": {
Type: schema.TypeString,
Description: "The randomly-generated root password for the Managed Database instance.",
Computed: true,
Sensitive: true,
},
"status": {
Type: schema.TypeString,
Description: "The operating status of the Managed Database.",
Computed: true,
},
"updated": {
Type: schema.TypeString,
Description: "When this Managed Database was last updated.",
Computed: true,
},
"root_username": {
Type: schema.TypeString,
Description: "The root username for the Managed Database instance.",
Computed: true,
Sensitive: true,
},
"version": {
Type: schema.TypeString,
Description: "The Managed Database engine version.",
Computed: true,
},
}