Skip to content

Commit b6434ba

Browse files
authored
Apply the sys_monitoring attribute during creation (#792)
* Apply the sys_monitoring attribute during creation * Changelog
1 parent a62b3f2 commit b6434ba

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## [Unreleased]
22

3+
- Fix handling of `sys_monitoring` in `elasticstack_fleet_agent_policy` ([#792](https://github.com/elastic/terraform-provider-elasticstack/pull/792))
4+
35
## [0.11.7] - 2024-09-20
46

57
- Add the `alerts_filter` field to the `actions` in the Create Rule API ([#774](https://github.com/elastic/terraform-provider-elasticstack/pull/774))

internal/clients/fleet/fleet.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,16 @@ func ReadAgentPolicy(ctx context.Context, client *Client, id string) (*fleetapi.
6666
}
6767

6868
// CreateAgentPolicy creates a new agent policy.
69-
func CreateAgentPolicy(ctx context.Context, client *Client, req fleetapi.AgentPolicyCreateRequest) (*fleetapi.AgentPolicy, diag.Diagnostics) {
70-
resp, err := client.API.CreateAgentPolicyWithResponse(ctx, req)
69+
func CreateAgentPolicy(ctx context.Context, client *Client, req fleetapi.AgentPolicyCreateRequest, sysMonitoring bool) (*fleetapi.AgentPolicy, diag.Diagnostics) {
70+
resp, err := client.API.CreateAgentPolicyWithResponse(ctx, req, func(ctx context.Context, req *http.Request) error {
71+
if sysMonitoring {
72+
qs := req.URL.Query()
73+
qs.Add("sys_monitoring", "true")
74+
req.URL.RawQuery = qs.Encode()
75+
}
76+
77+
return nil
78+
})
7179
if err != nil {
7280
return nil, diag.FromErr(err)
7381
}

internal/fleet/agent_policy_resource.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func ResourceAgentPolicy() *schema.Resource {
6363
Description: "Enable collection of system logs and metrics.",
6464
Type: schema.TypeBool,
6565
Optional: true,
66+
ForceNew: true,
6667
},
6768
"monitor_logs": {
6869
Description: "Enable collection of agent logs.",
@@ -140,7 +141,8 @@ func resourceAgentPolicyCreate(ctx context.Context, d *schema.ResourceData, meta
140141
}
141142
req.MonitoringEnabled = &monitoringValues
142143

143-
policy, diags := fleet.CreateAgentPolicy(ctx, fleetClient, req)
144+
sysMonitoring := d.Get("sys_monitoring").(bool)
145+
policy, diags := fleet.CreateAgentPolicy(ctx, fleetClient, req, sysMonitoring)
144146
if diags.HasError() {
145147
return diags
146148
}

0 commit comments

Comments
 (0)