@@ -2,6 +2,7 @@ package integration_test
22
33import (
44 "context"
5+ "fmt"
56 "regexp"
67 "testing"
78
@@ -10,6 +11,7 @@ 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)
@@ -48,22 +50,31 @@ func TestAccResourceIntegrationFromSDK(t *testing.T) {
4850}
4951
5052func TestAccResourceIntegration (t * testing.T ) {
53+ policyName := sdkacctest .RandStringFromCharSet (22 , sdkacctest .CharSetAlphaNum )
5154 resource .Test (t , resource.TestCase {
5255 PreCheck : func () { acctest .PreCheck (t ) },
5356 ProtoV6ProviderFactories : acctest .Providers ,
5457 Steps : []resource.TestStep {
5558 {
5659 SkipFunc : versionutils .CheckIfVersionIsUnsupported (minVersionIntegration ),
57- Config : testAccResourceIntegration ,
60+ Config : testAccResourceIntegrationWithPolicy ( policyName , "1.16.0" ) ,
5861 Check : resource .ComposeTestCheckFunc (
5962 resource .TestCheckResourceAttr ("elasticstack_fleet_integration.test_integration" , "name" , "tcp" ),
6063 resource .TestCheckResourceAttr ("elasticstack_fleet_integration.test_integration" , "version" , "1.16.0" ),
6164 ),
6265 },
66+ {
67+ SkipFunc : versionutils .CheckIfVersionIsUnsupported (minVersionIntegration ),
68+ Config : testAccResourceIntegrationWithPolicy (policyName , "1.17.0" ),
69+ Check : resource .ComposeTestCheckFunc (
70+ resource .TestCheckResourceAttr ("elasticstack_fleet_integration.test_integration" , "name" , "tcp" ),
71+ resource .TestCheckResourceAttr ("elasticstack_fleet_integration.test_integration" , "version" , "1.17.0" ),
72+ ),
73+ },
6374 {
6475 SkipFunc : versionutils .CheckIfVersionIsUnsupported (minVersionIntegration ),
6576 ResourceName : "elasticstack_fleet_integration.test_integration" ,
66- Config : testAccResourceIntegration ,
77+ Config : testAccResourceIntegrationWithPolicy ( policyName , "1.17.0" ) ,
6778 ImportState : true ,
6879 ImportStateVerify : true ,
6980 ExpectError : regexp .MustCompile ("Resource Import Not Implemented" ),
@@ -122,6 +133,65 @@ resource "elasticstack_fleet_integration" "test_integration" {
122133}
123134`
124135
136+ func testAccResourceIntegrationWithPolicy (policyName , version string ) string {
137+ return fmt .Sprintf (`
138+ provider "elasticstack" {
139+ elasticsearch {}
140+ kibana {}
141+ }
142+
143+ resource "elasticstack_fleet_integration" "test_integration" {
144+ name = "tcp"
145+ version = "%s"
146+ force = true
147+ skip_destroy = true
148+ }
149+
150+ // An agent policy to hold the integration policy.
151+ resource "elasticstack_fleet_agent_policy" "sample" {
152+ name = "%s"
153+ namespace = "default"
154+ description = "A sample agent policy"
155+ monitor_logs = true
156+ monitor_metrics = true
157+ skip_destroy = false
158+ }
159+
160+ // The associated enrollment token.
161+ data "elasticstack_fleet_enrollment_tokens" "sample" {
162+ policy_id = elasticstack_fleet_agent_policy.sample.policy_id
163+ }
164+
165+ // The integration policy.
166+ resource "elasticstack_fleet_integration_policy" "sample" {
167+ name = "%s"
168+ namespace = "default"
169+ description = "A sample integration policy"
170+ agent_policy_id = elasticstack_fleet_agent_policy.sample.policy_id
171+ integration_name = elasticstack_fleet_integration.test_integration.name
172+ integration_version = elasticstack_fleet_integration.test_integration.version
173+
174+ input {
175+ input_id = "tcp-tcp"
176+ streams_json = jsonencode({
177+ "tcp.generic" : {
178+ "enabled" : true,
179+ "vars" : {
180+ "listen_address" : "localhost",
181+ "listen_port" : 8080,
182+ "data_stream.dataset" : "tcp.generic",
183+ "tags" : [],
184+ "syslog_options" : "field: message\n#format: auto\n#timezone: Local\n",
185+ "ssl" : "#certificate: |\n# -----BEGIN CERTIFICATE-----\n# ...\n# -----END CERTIFICATE-----\n#key: |\n# -----BEGIN PRIVATE KEY-----\n# ...\n# -----END PRIVATE KEY-----\n",
186+ "custom" : ""
187+ }
188+ }
189+ })
190+ }
191+ }
192+ ` , version , policyName , policyName )
193+ }
194+
125195const testAccResourceIntegrationDeleted = `
126196provider "elasticstack" {
127197 elasticsearch {}
0 commit comments