Skip to content

Commit 98038d0

Browse files
committed
split synthetics monitor resources in tests between http and tcp to preven deletion of same private location across tests.
1 parent 5ccf103 commit 98038d0

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

internal/kibana/synthetics/acc_test.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ resource "elasticstack_kibana_synthetics_monitor" "%s" {
2222
name = "TestHttpMonitorResource - %s"
2323
space_id = "testacc"
2424
schedule = 5
25-
private_locations = [elasticstack_kibana_synthetics_private_location.test.label]
25+
private_locations = [elasticstack_kibana_synthetics_private_location.%s.label]
2626
enabled = true
2727
tags = ["a", "b"]
2828
alert = {
@@ -53,7 +53,7 @@ resource "elasticstack_kibana_synthetics_monitor" "%s" {
5353
name = "TestHttpMonitorResource Updated - %s"
5454
space_id = "testacc"
5555
schedule = 10
56-
private_locations = [elasticstack_kibana_synthetics_private_location.test.label]
56+
private_locations = [elasticstack_kibana_synthetics_private_location.%s.label]
5757
enabled = false
5858
tags = ["c", "d", "e"]
5959
alert = {
@@ -114,7 +114,7 @@ resource "elasticstack_kibana_synthetics_monitor" "%s" {
114114
name = "TestTcpMonitorResource - %s"
115115
space_id = "default"
116116
schedule = 5
117-
private_locations = [elasticstack_kibana_synthetics_private_location.test.label]
117+
private_locations = [elasticstack_kibana_synthetics_private_location.%s.label]
118118
enabled = true
119119
tags = ["a", "b"]
120120
alert = {
@@ -142,7 +142,7 @@ resource "elasticstack_kibana_synthetics_monitor" "%s" {
142142
name = "TestTcpMonitorResource Updated - %s"
143143
space_id = "default"
144144
schedule = 10
145-
private_locations = [elasticstack_kibana_synthetics_private_location.test.label]
145+
private_locations = [elasticstack_kibana_synthetics_private_location.%s.label]
146146
enabled = false
147147
tags = ["c", "d", "e"]
148148
alert = {
@@ -173,8 +173,8 @@ func TestSyntheticMonitorHTTPResource(t *testing.T) {
173173

174174
name := sdkacctest.RandStringFromCharSet(22, sdkacctest.CharSetAlphaNum)
175175
id := "http-monitor"
176-
httpMonitorId, config := testHttpMonitorConfig(id, httpMonitorConfig, name)
177-
_, configUpdated := testHttpMonitorConfig(id, httpMonitorUpdated, name)
176+
httpMonitorId, config := testMonitorConfig(id, httpMonitorConfig, name)
177+
_, configUpdated := testMonitorConfig(id, httpMonitorUpdated, name)
178178

179179
resource.Test(t, resource.TestCase{
180180
PreCheck: func() { acctest.PreCheck(t) },
@@ -270,8 +270,8 @@ func TestSyntheticMonitorTCPResource(t *testing.T) {
270270

271271
name := sdkacctest.RandStringFromCharSet(22, sdkacctest.CharSetAlphaNum)
272272
id := "tcp-monitor"
273-
tcpMonitorId, config := testHttpMonitorConfig(id, tcpMonitorConfig, name)
274-
_, configUpdated := testHttpMonitorConfig(id, tcpMonitorUpdated, name)
273+
tcpMonitorId, config := testMonitorConfig(id, tcpMonitorConfig, name)
274+
_, configUpdated := testMonitorConfig(id, tcpMonitorUpdated, name)
275275

276276
resource.Test(t, resource.TestCase{
277277
PreCheck: func() { acctest.PreCheck(t) },
@@ -354,9 +354,11 @@ func TestSyntheticMonitorTCPResource(t *testing.T) {
354354
})
355355
}
356356

357-
func testHttpMonitorConfig(id, cfg, name string) (string, string) {
357+
func testMonitorConfig(id, cfg, name string) (string, string) {
358358

359359
resourceId := "elasticstack_kibana_synthetics_monitor." + id
360+
privateLocationId := "pl-" + id
361+
agentPolicyId := "apl-" + id
360362

361363
provider := fmt.Sprintf(`
362364
provider "elasticstack" {
@@ -365,7 +367,7 @@ provider "elasticstack" {
365367
fleet{}
366368
}
367369
368-
resource "elasticstack_fleet_agent_policy" "test" {
370+
resource "elasticstack_fleet_agent_policy" "%s" {
369371
name = "TestMonitorResource Agent Policy - %s"
370372
namespace = "testacc"
371373
description = "TestMonitorResource Agent Policy"
@@ -374,14 +376,14 @@ resource "elasticstack_fleet_agent_policy" "test" {
374376
skip_destroy = false
375377
}
376378
377-
resource "elasticstack_kibana_synthetics_private_location" "test" {
379+
resource "elasticstack_kibana_synthetics_private_location" "%s" {
378380
label = "TestMonitorResource-label-%s"
379381
space_id = "testacc"
380-
agent_policy_id = elasticstack_fleet_agent_policy.test.policy_id
382+
agent_policy_id = elasticstack_fleet_agent_policy.%s.policy_id
381383
}
382-
`, name, name)
384+
`, agentPolicyId, name, privateLocationId, name, agentPolicyId)
383385

384-
config := fmt.Sprintf(cfg, id, name)
386+
config := fmt.Sprintf(cfg, id, name, privateLocationId)
385387

386388
return resourceId, provider + config
387389
}

0 commit comments

Comments
 (0)