@@ -2,6 +2,7 @@ package integration_test
22
33import (
44 "context"
5+ "fmt"
56 "regexp"
67 "testing"
78
@@ -10,11 +11,15 @@ import (
1011 "github.com/elastic/terraform-provider-elasticstack/internal/clients/fleet"
1112 "github.com/elastic/terraform-provider-elasticstack/internal/versionutils"
1213 "github.com/hashicorp/go-version"
14+ sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
1315 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1416 "github.com/stretchr/testify/require"
1517)
1618
17- var minVersionIntegration = version .Must (version .NewVersion ("8.6.0" ))
19+ var (
20+ minVersionIntegration = version .Must (version .NewVersion ("8.6.0" ))
21+ minVersionIntegrationPolicy = version .Must (version .NewVersion ("8.10.0" ))
22+ )
1823
1924func TestAccResourceIntegrationFromSDK (t * testing.T ) {
2025 resource .Test (t , resource.TestCase {
@@ -72,6 +77,40 @@ func TestAccResourceIntegration(t *testing.T) {
7277 })
7378}
7479
80+ func TestAccResourceIntegrationWithPolicy (t * testing.T ) {
81+ policyName := sdkacctest .RandStringFromCharSet (22 , sdkacctest .CharSetAlphaNum )
82+ resource .Test (t , resource.TestCase {
83+ PreCheck : func () { acctest .PreCheck (t ) },
84+ ProtoV6ProviderFactories : acctest .Providers ,
85+ Steps : []resource.TestStep {
86+ {
87+ SkipFunc : versionutils .CheckIfVersionIsUnsupported (minVersionIntegrationPolicy ),
88+ Config : testAccResourceIntegrationWithPolicy (policyName , "1.16.0" ),
89+ Check : resource .ComposeTestCheckFunc (
90+ resource .TestCheckResourceAttr ("elasticstack_fleet_integration.test_integration" , "name" , "tcp" ),
91+ resource .TestCheckResourceAttr ("elasticstack_fleet_integration.test_integration" , "version" , "1.16.0" ),
92+ ),
93+ },
94+ {
95+ SkipFunc : versionutils .CheckIfVersionIsUnsupported (minVersionIntegrationPolicy ),
96+ Config : testAccResourceIntegrationWithPolicy (policyName , "1.17.0" ),
97+ Check : resource .ComposeTestCheckFunc (
98+ resource .TestCheckResourceAttr ("elasticstack_fleet_integration.test_integration" , "name" , "tcp" ),
99+ resource .TestCheckResourceAttr ("elasticstack_fleet_integration.test_integration" , "version" , "1.17.0" ),
100+ ),
101+ },
102+ {
103+ SkipFunc : versionutils .CheckIfVersionIsUnsupported (minVersionIntegrationPolicy ),
104+ ResourceName : "elasticstack_fleet_integration.test_integration" ,
105+ Config : testAccResourceIntegrationWithPolicy (policyName , "1.17.0" ),
106+ ImportState : true ,
107+ ImportStateVerify : true ,
108+ ExpectError : regexp .MustCompile ("Resource Import Not Implemented" ),
109+ },
110+ },
111+ })
112+ }
113+
75114func TestAccResourceIntegrationDeleted (t * testing.T ) {
76115 resource .Test (t , resource.TestCase {
77116 PreCheck : func () { acctest .PreCheck (t ) },
@@ -122,6 +161,65 @@ resource "elasticstack_fleet_integration" "test_integration" {
122161}
123162`
124163
164+ func testAccResourceIntegrationWithPolicy (policyName , version string ) string {
165+ return fmt .Sprintf (`
166+ provider "elasticstack" {
167+ elasticsearch {}
168+ kibana {}
169+ }
170+
171+ resource "elasticstack_fleet_integration" "test_integration" {
172+ name = "tcp"
173+ version = "%s"
174+ force = true
175+ skip_destroy = true
176+ }
177+
178+ // An agent policy to hold the integration policy.
179+ resource "elasticstack_fleet_agent_policy" "sample" {
180+ name = "%s"
181+ namespace = "default"
182+ description = "A sample agent policy"
183+ monitor_logs = true
184+ monitor_metrics = true
185+ skip_destroy = false
186+ }
187+
188+ // The associated enrollment token.
189+ data "elasticstack_fleet_enrollment_tokens" "sample" {
190+ policy_id = elasticstack_fleet_agent_policy.sample.policy_id
191+ }
192+
193+ // The integration policy.
194+ resource "elasticstack_fleet_integration_policy" "sample" {
195+ name = "%s"
196+ namespace = "default"
197+ description = "A sample integration policy"
198+ agent_policy_id = elasticstack_fleet_agent_policy.sample.policy_id
199+ integration_name = elasticstack_fleet_integration.test_integration.name
200+ integration_version = elasticstack_fleet_integration.test_integration.version
201+
202+ input {
203+ input_id = "tcp-tcp"
204+ streams_json = jsonencode({
205+ "tcp.generic" : {
206+ "enabled" : true,
207+ "vars" : {
208+ "listen_address" : "localhost",
209+ "listen_port" : 8080,
210+ "data_stream.dataset" : "tcp.generic",
211+ "tags" : [],
212+ "syslog_options" : "field: message\n#format: auto\n#timezone: Local\n",
213+ "ssl" : "#certificate: |\n# -----BEGIN CERTIFICATE-----\n# ...\n# -----END CERTIFICATE-----\n#key: |\n# -----BEGIN PRIVATE KEY-----\n# ...\n# -----END PRIVATE KEY-----\n",
214+ "custom" : ""
215+ }
216+ }
217+ })
218+ }
219+ }
220+ ` , version , policyName , policyName )
221+ }
222+
125223const testAccResourceIntegrationDeleted = `
126224provider "elasticstack" {
127225 elasticsearch {}
0 commit comments