@@ -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 (`
212237provider "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
226252data "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+
232259func testAccResourceAgentPolicyCreateWithGlobalDataTags (id string , skipDestroy bool ) string {
233260 return fmt .Sprintf (`
234261provider "elasticstack" {
0 commit comments