Skip to content

Commit 7ec7c73

Browse files
authored
Merge pull request #131 from RedisLabs/fix/destroying-alerts
Allowing empty lists when updating Alerts
2 parents 4b6c94b + cf54f39 commit 7ec7c73

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

database_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ func TestDatabase_Update(t *testing.T) {
383383
SourceIP: redis.StringSlice("10.0.0.1"),
384384
ClientSSLCertificate: redis.String("something"),
385385
Password: redis.String("fooBar"),
386-
Alerts: []*databases.UpdateAlert{
386+
Alerts: &[]*databases.UpdateAlert{
387387
{
388388
Name: redis.String("dataset-size"),
389389
Value: redis.Int(80),

service/databases/model.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,14 @@ type UpdateDatabase struct {
171171
SourceIP []*string `json:"sourceIp,omitempty"`
172172
ClientSSLCertificate *string `json:"clientSslCertificate,omitempty"`
173173
Password *string `json:"password,omitempty"`
174-
Alerts []*UpdateAlert `json:"alerts,omitempty"`
175-
EnableTls *bool `json:"enableTls,omitempty"`
176-
RemoteBackup *DatabaseBackupConfig `json:"remoteBackup,omitempty"`
174+
175+
// It's important to use a pointer here, because the terraform user may want to send an empty list.
176+
// In that case, the developer must pass a (pointer to a) non-nil, zero-length slice
177+
// If the developer really wants to omit this value, passing a nil slice value would work
178+
Alerts *[]*UpdateAlert `json:"alerts,omitempty"`
179+
180+
EnableTls *bool `json:"enableTls,omitempty"`
181+
RemoteBackup *DatabaseBackupConfig `json:"remoteBackup,omitempty"`
177182
}
178183

179184
func (o UpdateDatabase) String() string {

service/databases/model_active_active.go

+15-13
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,19 @@ func (o LocalThroughput) String() string {
8888
}
8989

9090
type UpdateActiveActiveDatabase struct {
91-
DryRun *bool `json:"dryRun,omitempty"`
92-
MemoryLimitInGB *float64 `json:"memoryLimitInGb,omitempty"`
93-
SupportOSSClusterAPI *bool `json:"supportOSSClusterApi,omitempty"`
94-
UseExternalEndpointForOSSClusterAPI *bool `json:"useExternalEndpointForOSSClusterApi,omitempty"`
95-
ClientSSLCertificate *string `json:"clientSslCertificate,omitempty"`
96-
EnableTls *bool `json:"enableTls,omitempty"`
97-
GlobalDataPersistence *string `json:"globalDataPersistence,omitempty"`
98-
GlobalPassword *string `json:"globalPassword,omitempty"`
99-
GlobalSourceIP []*string `json:"globalSourceIp,omitempty"`
100-
GlobalAlerts []*UpdateAlert `json:"globalAlerts,omitempty"`
101-
Regions []*LocalRegionProperties `json:"regions,omitempty"`
102-
DataEvictionPolicy *string `json:"dataEvictionPolicy,omitempty"`
91+
DryRun *bool `json:"dryRun,omitempty"`
92+
MemoryLimitInGB *float64 `json:"memoryLimitInGb,omitempty"`
93+
SupportOSSClusterAPI *bool `json:"supportOSSClusterApi,omitempty"`
94+
UseExternalEndpointForOSSClusterAPI *bool `json:"useExternalEndpointForOSSClusterApi,omitempty"`
95+
ClientSSLCertificate *string `json:"clientSslCertificate,omitempty"`
96+
EnableTls *bool `json:"enableTls,omitempty"`
97+
GlobalDataPersistence *string `json:"globalDataPersistence,omitempty"`
98+
GlobalPassword *string `json:"globalPassword,omitempty"`
99+
GlobalSourceIP []*string `json:"globalSourceIp,omitempty"`
100+
// Using a pointer to allow empty slices to be serialised/sent
101+
GlobalAlerts *[]*UpdateAlert `json:"globalAlerts,omitempty"`
102+
Regions []*LocalRegionProperties `json:"regions,omitempty"`
103+
DataEvictionPolicy *string `json:"dataEvictionPolicy,omitempty"`
103104
}
104105

105106
func (o UpdateActiveActiveDatabase) String() string {
@@ -113,7 +114,8 @@ type LocalRegionProperties struct {
113114
DataPersistence *string `json:"dataPersistence,omitempty"`
114115
Password *string `json:"password,omitempty"`
115116
SourceIP []*string `json:"sourceIp,omitempty"`
116-
Alerts []*UpdateAlert `json:"alerts,omitempty"`
117+
// Using a pointer to allow empty slices to be serialised/sent
118+
Alerts *[]*UpdateAlert `json:"alerts,omitempty"`
117119
}
118120

119121
func (o LocalRegionProperties) String() string {

0 commit comments

Comments
 (0)