@@ -10,6 +10,7 @@ import (
1010 "github.com/elastic/terraform-provider-elasticstack/internal/acctest"
1111 "github.com/elastic/terraform-provider-elasticstack/internal/versionutils"
1212 "github.com/hashicorp/go-version"
13+ sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
1314 "github.com/hashicorp/terraform-plugin-testing/helper/resource"
1415)
1516
@@ -29,26 +30,27 @@ var (
2930
3031func TestSyntheticPrivateLocationResource (t * testing.T ) {
3132 resourceId := "elasticstack_kibana_synthetics_private_location.test"
33+ randomSuffix := sdkacctest .RandStringFromCharSet (4 , sdkacctest .CharSetAlphaNum )
3234 resource .Test (t , resource.TestCase {
3335 PreCheck : func () { acctest .PreCheck (t ) },
3436 ProtoV6ProviderFactories : acctest .Providers ,
3537 Steps : []resource.TestStep {
3638 // Create and Read testing
3739 {
3840 SkipFunc : versionutils .CheckIfVersionIsUnsupported (minKibanaPrivateLocationAPIVersion ),
39- Config : testConfig ("testacc" , "test_policy" ) + `
41+ Config : testConfig ("testacc" , "test_policy" , randomSuffix ) + fmt . Sprintf ( `
4042resource "elasticstack_kibana_synthetics_private_location" "test" {
41- label = "pl-test-label"
43+ label = "pl-test-label-%s "
4244 agent_policy_id = elasticstack_fleet_agent_policy.test_policy.policy_id
4345 tags = ["a", "b"]
4446 geo = {
4547 lat = 42.42
4648 lon = -42.42
4749 }
4850}
49- ` ,
51+ ` , randomSuffix ),
5052 Check : resource .ComposeAggregateTestCheckFunc (
51- resource .TestCheckResourceAttr (resourceId , "label" , "pl-test-label" ),
53+ resource .TestCheckResourceAttr (resourceId , "label" , fmt . Sprintf ( "pl-test-label-%s" , randomSuffix ) ),
5254 resource .TestCheckResourceAttrSet (resourceId , "agent_policy_id" ),
5355 resource .TestCheckResourceAttr (resourceId , "tags.#" , "2" ),
5456 resource .TestCheckResourceAttr (resourceId , "tags.0" , "a" ),
@@ -63,34 +65,34 @@ resource "elasticstack_kibana_synthetics_private_location" "test" {
6365 ResourceName : resourceId ,
6466 ImportState : true ,
6567 ImportStateVerify : true ,
66- Config : testConfig ("testacc" , "test_policy" ) + `
68+ Config : testConfig ("testacc" , "test_policy" , randomSuffix ) + fmt . Sprintf ( `
6769resource "elasticstack_kibana_synthetics_private_location" "test" {
68- label = "pl-test-label"
70+ label = "pl-test-label-%s "
6971 agent_policy_id = elasticstack_fleet_agent_policy.test_policy.policy_id
7072 tags = ["a", "b"]
7173 geo = {
7274 lat = 42.42
7375 lon = -42.42
7476 }
7577}
76- ` ,
78+ ` , randomSuffix ),
7779 },
7880 // Update and Read testing
7981 {
8082 SkipFunc : versionutils .CheckIfVersionIsUnsupported (minKibanaPrivateLocationAPIVersion ),
81- Config : testConfig ("default" , "test_policy_default" ) + `
83+ Config : testConfig ("default" , "test_policy_default" , randomSuffix ) + fmt . Sprintf ( `
8284resource "elasticstack_kibana_synthetics_private_location" "test" {
83- label = "pl-test-label-2"
85+ label = "pl-test-label-2-%s "
8486 agent_policy_id = elasticstack_fleet_agent_policy.test_policy_default.policy_id
8587 tags = ["c", "d", "e"]
8688 geo = {
8789 lat = -33.21
8890 lon = -33.21
8991 }
9092}
91- ` ,
93+ ` , randomSuffix ),
9294 Check : resource .ComposeAggregateTestCheckFunc (
93- resource .TestCheckResourceAttr (resourceId , "label" , "pl-test-label-2" ),
95+ resource .TestCheckResourceAttr (resourceId , "label" , fmt . Sprintf ( "pl-test-label-2-%s" , randomSuffix ) ),
9496 resource .TestCheckResourceAttrSet (resourceId , "agent_policy_id" ),
9597 resource .TestCheckResourceAttr (resourceId , "tags.#" , "3" ),
9698 resource .TestCheckResourceAttr (resourceId , "tags.0" , "c" ),
@@ -103,14 +105,14 @@ resource "elasticstack_kibana_synthetics_private_location" "test" {
103105 // Update and Read testing
104106 {
105107 SkipFunc : versionutils .CheckIfVersionIsUnsupported (minKibanaPrivateLocationAPIVersion ),
106- Config : testConfig ("default" , "test_policy_default" ) + `
108+ Config : testConfig ("default" , "test_policy_default" , randomSuffix ) + fmt . Sprintf ( `
107109resource "elasticstack_kibana_synthetics_private_location" "test" {
108- label = "pl-test-label-2"
110+ label = "pl-test-label-2-%s "
109111 agent_policy_id = elasticstack_fleet_agent_policy.test_policy_default.policy_id
110112}
111- ` ,
113+ ` , randomSuffix ),
112114 Check : resource .ComposeAggregateTestCheckFunc (
113- resource .TestCheckResourceAttr (resourceId , "label" , "pl-test-label-2" ),
115+ resource .TestCheckResourceAttr (resourceId , "label" , fmt . Sprintf ( "pl-test-label-2-%s" , randomSuffix ) ),
114116 resource .TestCheckResourceAttrSet (resourceId , "agent_policy_id" ),
115117 resource .TestCheckNoResourceAttr (resourceId , "tags" ),
116118 resource .TestCheckNoResourceAttr (resourceId , "geo" ),
@@ -119,15 +121,15 @@ resource "elasticstack_kibana_synthetics_private_location" "test" {
119121 // Update and Read testing
120122 {
121123 SkipFunc : versionutils .CheckIfVersionIsUnsupported (minKibanaPrivateLocationAPIVersion ),
122- Config : testConfig ("default" , "test_policy_default" ) + `
124+ Config : testConfig ("default" , "test_policy_default" , randomSuffix ) + fmt . Sprintf ( `
123125resource "elasticstack_kibana_synthetics_private_location" "test" {
124- label = "pl-test-label-2"
126+ label = "pl-test-label-2-%s "
125127 agent_policy_id = elasticstack_fleet_agent_policy.test_policy_default.policy_id
126128 tags = ["c", "d", "e"]
127129}
128- ` ,
130+ ` , randomSuffix ),
129131 Check : resource .ComposeAggregateTestCheckFunc (
130- resource .TestCheckResourceAttr (resourceId , "label" , "pl-test-label-2" ),
132+ resource .TestCheckResourceAttr (resourceId , "label" , fmt . Sprintf ( "pl-test-label-2-%s" , randomSuffix ) ),
131133 resource .TestCheckResourceAttrSet (resourceId , "agent_policy_id" ),
132134 resource .TestCheckResourceAttr (resourceId , "tags.#" , "3" ),
133135 resource .TestCheckResourceAttr (resourceId , "tags.0" , "c" ),
@@ -139,18 +141,18 @@ resource "elasticstack_kibana_synthetics_private_location" "test" {
139141 // Update and Read testing
140142 {
141143 SkipFunc : versionutils .CheckIfVersionIsUnsupported (minKibanaPrivateLocationAPIVersion ),
142- Config : testConfig ("default" , "test_policy_default" ) + `
144+ Config : testConfig ("default" , "test_policy_default" , randomSuffix ) + fmt . Sprintf ( `
143145resource "elasticstack_kibana_synthetics_private_location" "test" {
144- label = "pl-test-label-2"
146+ label = "pl-test-label-2-%s "
145147 agent_policy_id = elasticstack_fleet_agent_policy.test_policy_default.policy_id
146148 geo = {
147149 lat = -33.21
148150 lon = -33.21
149151 }
150152}
151- ` ,
153+ ` , randomSuffix ),
152154 Check : resource .ComposeAggregateTestCheckFunc (
153- resource .TestCheckResourceAttr (resourceId , "label" , "pl-test-label-2" ),
155+ resource .TestCheckResourceAttr (resourceId , "label" , fmt . Sprintf ( "pl-test-label-2-%s" , randomSuffix ) ),
154156 resource .TestCheckResourceAttrSet (resourceId , "agent_policy_id" ),
155157 resource .TestCheckNoResourceAttr (resourceId , "tags" ),
156158 resource .TestCheckResourceAttr (resourceId , "geo.lat" , "-33.21" ),
@@ -162,15 +164,15 @@ resource "elasticstack_kibana_synthetics_private_location" "test" {
162164 })
163165}
164166
165- func testConfig (namespace , agentPolicy string ) string {
167+ func testConfig (namespace , agentPolicy , randomSuffix string ) string {
166168 return providerConfig + fmt .Sprintf (`
167169resource "elasticstack_fleet_agent_policy" "%s" {
168- name = "Private Location Agent Policy - %s"
170+ name = "Private Location Agent Policy - %s - %s "
169171 namespace = "%s"
170172 description = "TestPrivateLocationResource Agent Policy"
171173 monitor_logs = true
172174 monitor_metrics = true
173175 skip_destroy = false
174176}
175- ` , agentPolicy , agentPolicy , namespace )
177+ ` , agentPolicy , agentPolicy , randomSuffix , namespace )
176178}
0 commit comments