Skip to content

Commit ed690e9

Browse files
committed
Randomise the test policy names to support reruns
1 parent 972959c commit ed690e9

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

internal/kibana/synthetics/private_location/acc_test.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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,14 +30,15 @@ var (
2930

3031
func 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) + `
4042
resource "elasticstack_kibana_synthetics_private_location" "test" {
4143
label = "pl-test-label"
4244
agent_policy_id = elasticstack_fleet_agent_policy.test_policy.policy_id
@@ -63,7 +65,7 @@ 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) + `
6769
resource "elasticstack_kibana_synthetics_private_location" "test" {
6870
label = "pl-test-label"
6971
agent_policy_id = elasticstack_fleet_agent_policy.test_policy.policy_id
@@ -78,7 +80,7 @@ resource "elasticstack_kibana_synthetics_private_location" "test" {
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) + `
8284
resource "elasticstack_kibana_synthetics_private_location" "test" {
8385
label = "pl-test-label-2"
8486
agent_policy_id = elasticstack_fleet_agent_policy.test_policy_default.policy_id
@@ -103,7 +105,7 @@ 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) + `
107109
resource "elasticstack_kibana_synthetics_private_location" "test" {
108110
label = "pl-test-label-2"
109111
agent_policy_id = elasticstack_fleet_agent_policy.test_policy_default.policy_id
@@ -119,7 +121,7 @@ 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) + `
123125
resource "elasticstack_kibana_synthetics_private_location" "test" {
124126
label = "pl-test-label-2"
125127
agent_policy_id = elasticstack_fleet_agent_policy.test_policy_default.policy_id
@@ -139,7 +141,7 @@ 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) + `
143145
resource "elasticstack_kibana_synthetics_private_location" "test" {
144146
label = "pl-test-label-2"
145147
agent_policy_id = elasticstack_fleet_agent_policy.test_policy_default.policy_id
@@ -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(`
167169
resource "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

Comments
 (0)