Skip to content

Commit 976bfaf

Browse files
Added UpdateContext
1 parent a15068c commit 976bfaf

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

aquasec/resource_monitoring_system.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ func resourceMonitoringSystem() *schema.Resource {
1212
return &schema.Resource{
1313
CreateContext: resourceMonitoringSystemCreate,
1414
ReadContext: resourceMonitoringSystemRead,
15+
UpdateContext: resourceMonitoringSYstemUpdate,
1516
DeleteContext: resourceMonitoringSystemDelete,
1617
Importer: &schema.ResourceImporter{
1718
StateContext: schema.ImportStatePassthroughContext,
@@ -110,6 +111,36 @@ func resourceMonitoringSystemRead(ctx context.Context, d *schema.ResourceData, m
110111
return nil
111112
}
112113

114+
func resourceMonitoringSYstemUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
115+
ac := m.(*client.Client)
116+
oldName := d.Id()
117+
118+
if d.HasChanges("interval", "enabled", "token", "type") {
119+
enabled := d.Get("enabled").(bool)
120+
interval := d.Get("interval").(int)
121+
msType := d.Get("type").(string)
122+
var tokenPtr *string
123+
if v, ok := d.GetOk("token"); ok {
124+
s := v.(string)
125+
if s != "" {
126+
tokenPtr = &s
127+
}
128+
}
129+
130+
monitor := client.MonitoringSystem{
131+
Name: oldName,
132+
Enabled: enabled,
133+
Token: tokenPtr,
134+
Interval: interval,
135+
Type: msType,
136+
}
137+
err := ac.UpdateMonitoringSystem(monitor)
138+
if err != nil {
139+
return diag.FromErr(err)
140+
}
141+
}
142+
return resourceMonitoringSystemRead(ctx, d, m)
143+
}
113144
func resourceMonitoringSystemDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
114145
ac := m.(*client.Client)
115146
name := d.Get("name").(string)

client/monitoring_system.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (cli *Client) CreateMonitoringSystem(monitoringSystem MonitoringSystem) err
109109
return nil
110110
}
111111

112-
/* func (cli *Client) UpdateMonitoringSystem(monitoringSystem MonitoringSystem) error {
112+
func (cli *Client) UpdateMonitoringSystem(monitoringSystem MonitoringSystem) error {
113113
payload, err := json.Marshal(monitoringSystem)
114114
if err != nil {
115115
return err
@@ -131,7 +131,7 @@ func (cli *Client) CreateMonitoringSystem(monitoringSystem MonitoringSystem) err
131131
return errors.Errorf(data)
132132
}
133133
return nil
134-
} */
134+
}
135135

136136
func (cli *Client) DeleteMonitoringSystem(monitoringSystem MonitoringSystem) error {
137137
payload, err := json.Marshal(monitoringSystem)

0 commit comments

Comments
 (0)