Skip to content

Commit 1d1ce9d

Browse files
author
ccushing
committed
DNS Zone tests name collision free
1 parent 743ff87 commit 1d1ce9d

File tree

1 file changed

+28
-27
lines changed

1 file changed

+28
-27
lines changed

provider/dns_zone_test.go

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const (
1919
resource "oci_dns_zone" "test_zone" {
2020
#Required
2121
compartment_id = "${var.compartment_id}"
22-
name = "${data.oci_identity_tenancy.test_tenancy.name}.${var.zone_name}"
22+
name = "${data.oci_identity_tenancy.test_tenancy.name}.{{.token}}.oci-zone-test"
2323
zone_type = "${var.zone_zone_type}"
2424
}
2525
`
@@ -28,7 +28,7 @@ resource "oci_dns_zone" "test_zone" {
2828
resource "oci_dns_zone" "test_zone" {
2929
#Required
3030
compartment_id = "${var.compartment_id}"
31-
name = "${data.oci_identity_tenancy.test_tenancy.name}.${var.zone_name}"
31+
name = "${data.oci_identity_tenancy.test_tenancy.name}.{{.token}}.oci-zone-test"
3232
zone_type = "SECONDARY"
3333
3434
#Optional
@@ -53,7 +53,7 @@ variable "zone_external_masters_port" { default = 53 } // (the only allowed val
5353
variable "zone_external_masters_tsig_algorithm" { default = "hmac-sha1" }
5454
variable "zone_external_masters_tsig_name" { default = "name" }
5555
variable "zone_external_masters_tsig_secret" { default = "c2VjcmV0" }
56-
variable "zone_name" { default = "oci-test" }
56+
variable "zone_name" { default = "oci-zone-test" }
5757
variable "zone_zone_type" { default = "PRIMARY" }
5858
5959
`
@@ -68,12 +68,13 @@ func TestDnsZoneResource_basic(t *testing.T) {
6868
provider := testAccProvider
6969
config := testProviderConfig()
7070

71-
compartmentId := getRequiredEnvSetting("compartment_ocid")
71+
compartmentId := getEnvSettingWithBlankDefault("compartment_ocid")
7272
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
7373

7474
resourceName := "oci_dns_zone.test_zone"
7575
datasourceName := "data.oci_dns_zones.test_zones"
7676

77+
_, tokenFn := tokenize()
7778
var resId string
7879

7980
resource.Test(t, resource.TestCase{
@@ -85,10 +86,10 @@ func TestDnsZoneResource_basic(t *testing.T) {
8586
Steps: []resource.TestStep{
8687
// test PRIMARY zone creation
8788
{
88-
Config: config + ZonePropertyVariables + compartmentIdVariableStr + ZoneRequiredOnlyResource,
89+
Config: tokenFn(config+ZonePropertyVariables+compartmentIdVariableStr+ZoneRequiredOnlyResource, nil),
8990
Check: resource.ComposeAggregateTestCheckFunc(
9091
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
91-
resource.TestMatchResourceAttr(resourceName, "name", regexp.MustCompile("\\.oci-test")),
92+
resource.TestMatchResourceAttr(resourceName, "name", regexp.MustCompile("\\.oci-zone-test")),
9293
resource.TestCheckResourceAttr(resourceName, "zone_type", "PRIMARY"),
9394

9495
func(s *terraform.State) (err error) {
@@ -102,7 +103,7 @@ func TestDnsZoneResource_basic(t *testing.T) {
102103
// This will put the zone in a bad state and cause any records in this zone to fail during PATCH.
103104
/*
104105
{
105-
Config: config + ZonePropertyVariables + compartmentIdVariableStr + ZoneResourceConfig,
106+
Config: tokenFn(config + ZonePropertyVariables + compartmentIdVariableStr + ZoneResourceConfig, nil),
106107
Check: resource.ComposeAggregateTestCheckFunc(
107108
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
108109
resource.TestCheckResourceAttr(resourceName, "external_masters.#", "1"),
@@ -112,7 +113,7 @@ func TestDnsZoneResource_basic(t *testing.T) {
112113
resource.TestCheckResourceAttr(resourceName, "external_masters.0.tsig.0.algorithm", "hmac-sha1"),
113114
resource.TestCheckResourceAttr(resourceName, "external_masters.0.tsig.0.name", "name"),
114115
resource.TestCheckResourceAttr(resourceName, "external_masters.0.tsig.0.secret", "c2VjcmV0"),
115-
resource.TestMatchResourceAttr(resourceName, "name", regexp.MustCompile("\\.oci-test")),
116+
resource.TestMatchResourceAttr(resourceName, "name", regexp.MustCompile("\\.oci-zone-test")),
116117
resource.TestCheckResourceAttr(resourceName, "zone_type", "SECONDARY"),
117118
118119
func(s *terraform.State) (err error) {
@@ -128,88 +129,88 @@ func TestDnsZoneResource_basic(t *testing.T) {
128129
*/
129130
// verify datasource
130131
{
131-
Config: config + ZonePropertyVariables + `
132+
Config: tokenFn(config+ZonePropertyVariables+`
132133
data "oci_dns_zones" "test_zones" {
133134
compartment_id = "${var.compartment_id}"
134135
filter {
135136
name = "id"
136137
values = ["${oci_dns_zone.test_zone.id}"]
137138
}
138139
}
139-
` + compartmentIdVariableStr + ZoneRequiredOnlyResource,
140+
`+compartmentIdVariableStr+ZoneRequiredOnlyResource, nil),
140141
Check: resource.ComposeAggregateTestCheckFunc(
141142
resource.TestCheckResourceAttr(datasourceName, "compartment_id", compartmentId),
142143
resource.TestCheckResourceAttr(datasourceName, "zones.#", "1"),
143144
),
144145
},
145146
{
146-
Config: config + ZonePropertyVariables + `
147+
Config: tokenFn(config+ZonePropertyVariables+`
147148
data "oci_dns_zones" "test_zones" {
148149
compartment_id = "${var.compartment_id}"
149-
name = "${data.oci_identity_tenancy.test_tenancy.name}.oci-test"
150+
name = "${data.oci_identity_tenancy.test_tenancy.name}.{{.token}}.oci-zone-test"
150151
}
151-
` + compartmentIdVariableStr + ZoneRequiredOnlyResource,
152+
`+compartmentIdVariableStr+ZoneRequiredOnlyResource, nil),
152153
Check: resource.ComposeAggregateTestCheckFunc(
153-
resource.TestMatchResourceAttr(datasourceName, "name", regexp.MustCompile("\\.oci-test")),
154+
resource.TestMatchResourceAttr(datasourceName, "name", regexp.MustCompile("\\.oci-zone-test")),
154155
resource.TestCheckResourceAttr(datasourceName, "zones.#", "1"),
155156
),
156157
},
157158
{
158-
Config: config + ZonePropertyVariables + `
159+
Config: tokenFn(config+ZonePropertyVariables+`
159160
data "oci_dns_zones" "test_zones" {
160161
compartment_id = "${var.compartment_id}"
161-
name_contains = "oci-test"
162+
name_contains = "oci-zone-test"
162163
}
163-
` + compartmentIdVariableStr + ZoneRequiredOnlyResource,
164+
`+compartmentIdVariableStr+ZoneRequiredOnlyResource, nil),
164165
Check: resource.ComposeAggregateTestCheckFunc(
165-
resource.TestCheckResourceAttr(datasourceName, "name_contains", "oci-test"),
166+
resource.TestCheckResourceAttr(datasourceName, "name_contains", "oci-zone-test"),
166167
resource.TestCheckResourceAttrSet(datasourceName, "zones.#"),
167168
),
168169
},
169170
{
170-
Config: config + ZonePropertyVariables + `
171+
Config: tokenFn(config+ZonePropertyVariables+`
171172
data "oci_dns_zones" "test_zones" {
172173
compartment_id = "${var.compartment_id}"
173174
state = "ACTIVE"
174175
}
175-
` + compartmentIdVariableStr + ZoneRequiredOnlyResource,
176+
`+compartmentIdVariableStr+ZoneRequiredOnlyResource, nil),
176177
Check: resource.ComposeAggregateTestCheckFunc(
177178
resource.TestCheckResourceAttr(datasourceName, "state", "ACTIVE"),
178179
resource.TestCheckResourceAttrSet(datasourceName, "zones.#"),
179180
),
180181
},
181182
{
182-
Config: config + ZonePropertyVariables + `
183+
Config: tokenFn(config+ZonePropertyVariables+`
183184
data "oci_dns_zones" "test_zones" {
184185
compartment_id = "${var.compartment_id}"
185186
zone_type = "PRIMARY"
186187
}
187-
` + compartmentIdVariableStr + ZoneRequiredOnlyResource,
188+
`+compartmentIdVariableStr+ZoneRequiredOnlyResource, nil),
188189
Check: resource.ComposeAggregateTestCheckFunc(
189190
resource.TestCheckResourceAttr(datasourceName, "zone_type", "PRIMARY"),
190191
resource.TestCheckResourceAttrSet(datasourceName, "zones.#"),
191192
),
192193
},
193194
{
194-
Config: config + ZonePropertyVariables + `
195+
Config: tokenFn(config+ZonePropertyVariables+`
195196
data "oci_dns_zones" "test_zones" {
196197
compartment_id = "${var.compartment_id}"
197198
time_created_greater_than_or_equal_to = "2018-04-10T19:01:09.000-00:00"
198199
}
199-
` + compartmentIdVariableStr + ZoneRequiredOnlyResource,
200+
`+compartmentIdVariableStr+ZoneRequiredOnlyResource, nil),
200201
Check: resource.ComposeAggregateTestCheckFunc(
201202
resource.TestCheckResourceAttr(datasourceName, "compartment_id", compartmentId),
202203
resource.TestCheckResourceAttr(datasourceName, "time_created_greater_than_or_equal_to", "2018-04-10T19:01:09.000-00:00"),
203204
resource.TestCheckResourceAttrSet(datasourceName, "zones.#"),
204205
),
205206
},
206207
{
207-
Config: config + ZonePropertyVariables + `
208+
Config: tokenFn(config+ZonePropertyVariables+`
208209
data "oci_dns_zones" "test_zones" {
209210
compartment_id = "${var.compartment_id}"
210211
time_created_less_than = "2022-04-10T19:01:09.000-00:00"
211212
}
212-
` + compartmentIdVariableStr + ZoneRequiredOnlyResource,
213+
`+compartmentIdVariableStr+ZoneRequiredOnlyResource, nil),
213214
Check: resource.ComposeAggregateTestCheckFunc(
214215
resource.TestCheckResourceAttr(datasourceName, "compartment_id", compartmentId),
215216
resource.TestCheckResourceAttr(datasourceName, "time_created_less_than", "2022-04-10T19:01:09.000-00:00"),
@@ -218,7 +219,7 @@ data "oci_dns_zones" "test_zones" {
218219
},
219220
// verify resource import
220221
{
221-
Config: config,
222+
Config: tokenFn(config, nil),
222223
ImportState: true,
223224
ImportStateVerify: true,
224225
ResourceName: resourceName,

0 commit comments

Comments
 (0)