Skip to content

Commit ed31bfa

Browse files
committed
Add supports_agentless parameter
1 parent 77c15d2 commit ed31bfa

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

internal/fleet/agent_policy/models.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type agentPolicyModel struct {
3434
MonitorMetrics types.Bool `tfsdk:"monitor_metrics"`
3535
SysMonitoring types.Bool `tfsdk:"sys_monitoring"`
3636
SkipDestroy types.Bool `tfsdk:"skip_destroy"`
37+
SupportsAgentless types.Bool `tfsdk:"supports_agentless"`
3738
GlobalDataTags types.Map `tfsdk:"global_data_tags"` //> globalDataTagsModel
3839
}
3940

@@ -67,6 +68,7 @@ func (model *agentPolicyModel) populateFromAPI(ctx context.Context, data *kbapi.
6768
model.MonitoringOutputId = types.StringPointerValue(data.MonitoringOutputId)
6869
model.Name = types.StringValue(data.Name)
6970
model.Namespace = types.StringValue(data.Namespace)
71+
model.SupportsAgentless = types.BoolPointerValue(data.SupportsAgentless)
7072
if utils.Deref(data.GlobalDataTags) != nil {
7173
diags := diag.Diagnostics{}
7274
var map0 = make(map[string]globalDataTagsItemModel)
@@ -166,6 +168,7 @@ func (model *agentPolicyModel) toAPICreateModel(ctx context.Context, serverVersi
166168
MonitoringOutputId: model.MonitoringOutputId.ValueStringPointer(),
167169
Name: model.Name.ValueString(),
168170
Namespace: model.Namespace.ValueString(),
171+
SupportsAgentless: model.SupportsAgentless.ValueBoolPointer(),
169172
}
170173

171174
tags, diags := model.convertGlobalDataTags(ctx, serverVersion)
@@ -195,6 +198,7 @@ func (model *agentPolicyModel) toAPIUpdateModel(ctx context.Context, serverVersi
195198
MonitoringOutputId: model.MonitoringOutputId.ValueStringPointer(),
196199
Name: model.Name.ValueString(),
197200
Namespace: model.Namespace.ValueString(),
201+
SupportsAgentless: model.SupportsAgentless.ValueBoolPointer(),
198202
}
199203

200204
tags, diags := model.convertGlobalDataTags(ctx, serverVersion)

internal/fleet/agent_policy/resource_test.go

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,29 @@ func TestAccResourceAgentPolicyFromSDK(t *testing.T) {
3636
},
3737
},
3838
SkipFunc: versionutils.CheckIfVersionIsUnsupported(minVersionAgentPolicy),
39-
Config: testAccResourceAgentPolicyCreate(policyName, false),
39+
Config: testAccResourceAgentPolicyCreate(policyName, false, false),
4040
Check: resource.ComposeTestCheckFunc(
4141
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "name", fmt.Sprintf("Policy %s", policyName)),
4242
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "namespace", "default"),
4343
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "description", "Test Agent Policy"),
4444
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "monitor_logs", "true"),
4545
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "monitor_metrics", "false"),
4646
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "skip_destroy", "false"),
47+
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "supports_agentless", "false"),
4748
),
4849
},
4950
{
5051
ProtoV6ProviderFactories: acctest.Providers,
5152
SkipFunc: versionutils.CheckIfVersionIsUnsupported(minVersionAgentPolicy),
52-
Config: testAccResourceAgentPolicyCreate(policyName, false),
53+
Config: testAccResourceAgentPolicyCreate(policyName, false, false),
5354
Check: resource.ComposeTestCheckFunc(
5455
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "name", fmt.Sprintf("Policy %s", policyName)),
5556
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "namespace", "default"),
5657
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "description", "Test Agent Policy"),
5758
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "monitor_logs", "true"),
5859
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "monitor_metrics", "false"),
5960
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "skip_destroy", "false"),
61+
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "supports_agentless", "false"),
6062
),
6163
},
6264
},
@@ -76,14 +78,37 @@ func TestAccResourceAgentPolicy(t *testing.T) {
7678
Steps: []resource.TestStep{
7779
{
7880
SkipFunc: versionutils.CheckIfVersionIsUnsupported(minVersionAgentPolicy),
79-
Config: testAccResourceAgentPolicyCreate(policyName, false),
81+
Config: testAccResourceAgentPolicyCreate(policyName, false, false),
8082
Check: resource.ComposeTestCheckFunc(
8183
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "name", fmt.Sprintf("Policy %s", policyName)),
8284
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "namespace", "default"),
8385
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "description", "Test Agent Policy"),
8486
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "monitor_logs", "true"),
8587
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "monitor_metrics", "false"),
8688
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "skip_destroy", "false"),
89+
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "supports_agentless", "false"),
90+
resource.TestCheckResourceAttrWith("elasticstack_fleet_agent_policy.test_policy", "policy_id", func(value string) error {
91+
originalPolicyId = value
92+
93+
if len(value) == 0 {
94+
return errors.New("expected policy_id to be non empty")
95+
}
96+
97+
return nil
98+
}),
99+
),
100+
},
101+
{
102+
SkipFunc: versionutils.CheckIfVersionIsUnsupported(minVersionAgentPolicy),
103+
Config: testAccResourceAgentPolicyCreate(policyName, false, true),
104+
Check: resource.ComposeTestCheckFunc(
105+
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "name", fmt.Sprintf("Policy %s", policyName)),
106+
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "namespace", "default"),
107+
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "description", "Test Agent Policy"),
108+
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "monitor_logs", "true"),
109+
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "monitor_metrics", "false"),
110+
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "skip_destroy", "false"),
111+
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "supports_agentless", "true"),
87112
resource.TestCheckResourceAttrWith("elasticstack_fleet_agent_policy.test_policy", "policy_id", func(value string) error {
88113
originalPolicyId = value
89114

@@ -177,7 +202,7 @@ func TestAccResourceAgentPolicySkipDestroy(t *testing.T) {
177202
Steps: []resource.TestStep{
178203
{
179204
SkipFunc: versionutils.CheckIfVersionIsUnsupported(minVersionAgentPolicy),
180-
Config: testAccResourceAgentPolicyCreate(policyName, true),
205+
Config: testAccResourceAgentPolicyCreate(policyName, true, false),
181206
Check: resource.ComposeTestCheckFunc(
182207
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "name", fmt.Sprintf("Policy %s", policyName)),
183208
resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "namespace", "default"),
@@ -207,7 +232,7 @@ func TestAccResourceAgentPolicyWithBadGlobalDataTags(t *testing.T) {
207232
})
208233
}
209234

210-
func testAccResourceAgentPolicyCreate(id string, skipDestroy bool) string {
235+
func testAccResourceAgentPolicyCreate(id string, skipDestroy bool, supportsAgentless bool) string {
211236
return fmt.Sprintf(`
212237
provider "elasticstack" {
213238
elasticsearch {}
@@ -221,14 +246,16 @@ resource "elasticstack_fleet_agent_policy" "test_policy" {
221246
monitor_logs = true
222247
monitor_metrics = false
223248
skip_destroy = %t
249+
supports_agentless = %t
224250
}
225251
226252
data "elasticstack_fleet_enrollment_tokens" "test_policy" {
227253
policy_id = elasticstack_fleet_agent_policy.test_policy.policy_id
228254
}
229255
230-
`, fmt.Sprintf("Policy %s", id), skipDestroy)
256+
`, fmt.Sprintf("Policy %s", id), skipDestroy, supportsAgentless)
231257
}
258+
232259
func testAccResourceAgentPolicyCreateWithGlobalDataTags(id string, skipDestroy bool) string {
233260
return fmt.Sprintf(`
234261
provider "elasticstack" {

internal/fleet/agent_policy/schema.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ func getSchema() schema.Schema {
8686
Description: "Set to true if you do not wish the agent policy to be deleted at destroy time, and instead just remove the agent policy from the Terraform state.",
8787
Optional: true,
8888
},
89+
"supports_agentless": schema.BoolAttribute{
90+
Description: "Set to true to enable agentless data collection.",
91+
Optional: true,
92+
},
8993
"sys_monitoring": schema.BoolAttribute{
9094
Description: "Enable collection of system logs and metrics.",
9195
Optional: true,

0 commit comments

Comments
 (0)