Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

computeDiskUserRegexString in resource_compute_disk.go should also accept projectIds that contain ":" or "." #1145

Merged
merged 5 commits into from
Mar 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion google/resource_compute_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

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

var (
Expand Down
32 changes: 32 additions & 0 deletions google/resource_compute_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,38 @@ func TestAccComputeDisk_deleteDetach(t *testing.T) {
})
}

func TestAccComputeDisk_computeDiskUserRegex(t *testing.T) {

shouldPass := []string{

"https://www.googleapis.com/compute/v1/projects/project-id/zones/us-central1/instances/123",
"https://www.googleapis.com/compute/v1/projects/123123/zones/us-central1/instances/123",
"https://www.googleapis.com/compute/v1/projects/hashicorptest.net:project-123/zones/us-central1/instances/123",
"https://www.googleapis.com/compute/v1/projects/123/zones/456/instances/789",
}

shouldFail := []string{
"https://www.googleapis.com/compute/v1/projects/project#/zones/us-central1/instances/123",
"https://www.googleapis.com/compute/v1/projects/project/zones/us-central#/instances/123",
"https://www.googleapis.com/compute/v1/projects/project/zones/us-central1/instances/?",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks right - can you add a shouldFail test for "foo.com:bar:baz", and "foo.com:"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, though of course those should fail, I meant as project names:
"https://www.googleapis.com/compute/v1/projects/foo.com:bar:baz/zones/us-central1/instances/123".

"https://www.googleapis.com/compute/v1/projects/foo.com:bar:baz/zones/us-central1/instances/?",
"https://www.googleapis.com/compute/v1/projects/foo.com:/zones/us-central1/instances/?",
}

for _, element := range shouldPass {
if !computeDiskUserRegex.MatchString(element) {
t.Error("computeDiskUserRegex should match on '" + element + "' but doesn't")
}
}

for _, element := range shouldFail {
if computeDiskUserRegex.MatchString(element) {
t.Error("computeDiskUserRegex shouldn't match on '" + element + "' but does")
}
}

}

func testAccCheckComputeDiskDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)

Expand Down