Skip to content

Commit 5ea98d2

Browse files
derflohnat-henderson
authored andcommitted
Loosen regex in computeDiskUserRegexString - accept ":" or "." (#1145)
1 parent 1d64cc5 commit 5ea98d2

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

google/resource_compute_disk.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
)
1414

1515
const (
16-
computeDiskUserRegexString = "^(?:https://www.googleapis.com/compute/v1/projects/)?([-_a-zA-Z0-9]*)/zones/([-_a-zA-Z0-9]*)/instances/([-_a-zA-Z0-9]*)$"
16+
computeDiskUserRegexString = "^(?:https://www.googleapis.com/compute/v1/projects/)?(" + ProjectRegex + ")/zones/([-_a-zA-Z0-9]*)/instances/([-_a-zA-Z0-9]*)$"
1717
)
1818

1919
var (

google/resource_compute_disk_test.go

+32
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,38 @@ func TestAccComputeDisk_deleteDetach(t *testing.T) {
372372
})
373373
}
374374

375+
func TestAccComputeDisk_computeDiskUserRegex(t *testing.T) {
376+
377+
shouldPass := []string{
378+
379+
"https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1/instances/123",
380+
"https://www.googleapis.com/compute/v1/projects/123123/zones/us-central1/instances/123",
381+
"https://www.googleapis.com/compute/v1/projects/hashicorptest.net:project-123/zones/us-central1/instances/123",
382+
"https://www.googleapis.com/compute/v1/projects/123/zones/456/instances/789",
383+
}
384+
385+
shouldFail := []string{
386+
"https://www.googleapis.com/compute/v1/projects/project#/zones/us-central1/instances/123",
387+
"https://www.googleapis.com/compute/v1/projects/project/zones/us-central#/instances/123",
388+
"https://www.googleapis.com/compute/v1/projects/project/zones/us-central1/instances/?",
389+
"https://www.googleapis.com/compute/v1/projects/foo.com:bar:baz/zones/us-central1/instances/?",
390+
"https://www.googleapis.com/compute/v1/projects/foo.com:/zones/us-central1/instances/?",
391+
}
392+
393+
for _, element := range shouldPass {
394+
if !computeDiskUserRegex.MatchString(element) {
395+
t.Error("computeDiskUserRegex should match on '" + element + "' but doesn't")
396+
}
397+
}
398+
399+
for _, element := range shouldFail {
400+
if computeDiskUserRegex.MatchString(element) {
401+
t.Error("computeDiskUserRegex shouldn't match on '" + element + "' but does")
402+
}
403+
}
404+
405+
}
406+
375407
func testAccCheckComputeDiskDestroy(s *terraform.State) error {
376408
config := testAccProvider.Meta().(*Config)
377409

0 commit comments

Comments
 (0)