@@ -333,6 +333,75 @@ func TestAccResourceIntegrationPolicySecrets(t *testing.T) {
333333 })
334334}
335335
336+ func TestAccIntegrationPolicyInputs (t * testing.T ) {
337+ policyName := sdkacctest .RandStringFromCharSet (22 , sdkacctest .CharSetAlphaNum )
338+
339+ resource .Test (t , resource.TestCase {
340+ PreCheck : func () { acctest .PreCheck (t ) },
341+ CheckDestroy : checkResourceIntegrationPolicyDestroy ,
342+ Steps : []resource.TestStep {
343+ {
344+ ProtoV6ProviderFactories : acctest .Providers ,
345+ SkipFunc : versionutils .CheckIfVersionIsUnsupported (minVersionIntegrationPolicy ),
346+ ConfigDirectory : acctest .NamedTestCaseDirectory ("create" ),
347+ ConfigVariables : config.Variables {
348+ "policy_name" : config .StringVariable (policyName ),
349+ },
350+ Check : resource .ComposeTestCheckFunc (
351+ resource .TestCheckResourceAttr ("elasticstack_fleet_integration_policy.test_policy" , "name" , policyName ),
352+ resource .TestCheckResourceAttr ("elasticstack_fleet_integration_policy.test_policy" , "description" , "Kafka Integration Policy" ),
353+ resource .TestCheckResourceAttr ("elasticstack_fleet_integration_policy.test_policy" , "integration_name" , "kafka" ),
354+ // Check enabled inputs
355+ resource .TestCheckResourceAttr ("elasticstack_fleet_integration_policy.test_policy" , "inputs.kafka-logfile.enabled" , "true" ),
356+ resource .TestCheckResourceAttr ("elasticstack_fleet_integration_policy.test_policy" , "inputs.kafka-kafka/metrics.enabled" , "true" ),
357+ // Check enabled streams
358+ resource .TestCheckResourceAttr ("elasticstack_fleet_integration_policy.test_policy" , "inputs.kafka-logfile.streams.kafka.log.enabled" , "true" ),
359+ resource .TestCheckResourceAttr ("elasticstack_fleet_integration_policy.test_policy" , "inputs.kafka-kafka/metrics.streams.kafka.broker.enabled" , "true" ),
360+ resource .TestCheckResourceAttr ("elasticstack_fleet_integration_policy.test_policy" , "inputs.kafka-kafka/metrics.streams.kafka.consumergroup.enabled" , "true" ),
361+ // Check disabled stream
362+ resource .TestCheckResourceAttr ("elasticstack_fleet_integration_policy.test_policy" , "inputs.kafka-kafka/metrics.streams.kafka.partition.enabled" , "false" ),
363+ // Check vars
364+ resource .TestCheckResourceAttr ("elasticstack_fleet_integration_policy.test_policy" , "inputs.kafka-kafka/metrics.vars" , `{"hosts":["localhost:9092"],"period":"10s","ssl.certificate_authorities":[]}` ),
365+ // Check unspecified, disabled by default input
366+ resource .TestCheckNoResourceAttr ("elasticstack_fleet_integration_policy.test_policy" , "inputs.kafka-jolokia/metrics" ),
367+ ),
368+ },
369+ {
370+ ProtoV6ProviderFactories : acctest .Providers ,
371+ SkipFunc : versionutils .CheckIfVersionIsUnsupported (minVersionIntegrationPolicy ),
372+ ConfigDirectory : acctest .NamedTestCaseDirectory ("update_disabled_input" ),
373+ ConfigVariables : config.Variables {
374+ "policy_name" : config .StringVariable (policyName ),
375+ },
376+ Check : resource .ComposeTestCheckFunc (
377+ resource .TestCheckResourceAttr ("elasticstack_fleet_integration_policy.test_policy" , "name" , policyName ),
378+ resource .TestCheckResourceAttr ("elasticstack_fleet_integration_policy.test_policy" , "description" , "Kafka Integration Policy - Updated" ),
379+ // Check that disabling an input works correctly
380+ resource .TestCheckResourceAttr ("elasticstack_fleet_integration_policy.test_policy" , "inputs.kafka-logfile.enabled" , "false" ),
381+ resource .TestCheckResourceAttr ("elasticstack_fleet_integration_policy.test_policy" , "inputs.kafka-kafka/metrics.enabled" , "true" ),
382+ // Vars should remain the same since we didn't change them
383+ resource .TestCheckResourceAttr ("elasticstack_fleet_integration_policy.test_policy" , "inputs.kafka-kafka/metrics.vars" , `{"hosts":["localhost:9092"],"period":"10s","ssl.certificate_authorities":[]}` ),
384+ ),
385+ },
386+ {
387+ ProtoV6ProviderFactories : acctest .Providers ,
388+ SkipFunc : versionutils .CheckIfVersionIsUnsupported (minVersionIntegrationPolicy ),
389+ ConfigDirectory : acctest .NamedTestCaseDirectory ("update_enabled_input" ),
390+ ConfigVariables : config.Variables {
391+ "policy_name" : config .StringVariable (policyName ),
392+ },
393+ Check : resource .ComposeTestCheckFunc (
394+ resource .TestCheckResourceAttr ("elasticstack_fleet_integration_policy.test_policy" , "name" , policyName ),
395+ // Check that updating an enabled input's vars triggers a change
396+ resource .TestCheckResourceAttr ("elasticstack_fleet_integration_policy.test_policy" , "inputs.kafka-kafka/metrics.streams.kafka.consumergroup.vars" , `{"topics":["don't mention the war, I mentioned it once but I think I got away with it"]}` ),
397+ // Disabled input should remain disabled
398+ resource .TestCheckResourceAttr ("elasticstack_fleet_integration_policy.test_policy" , "inputs.kafka-logfile.enabled" , "false" ),
399+ ),
400+ },
401+ },
402+ })
403+ }
404+
336405func checkResourceIntegrationPolicyDestroy (s * terraform.State ) error {
337406 client , err := clients .NewAcceptanceTestingClient ()
338407 if err != nil {
0 commit comments