diff --git a/build/terraform b/build/terraform index bcf010a9581f..151d06368f74 160000 --- a/build/terraform +++ b/build/terraform @@ -1 +1 @@ -Subproject commit bcf010a9581fc5a91cbde7e8d7c8d41b45b58777 +Subproject commit 151d06368f74096abb186408175a4b09dc814880 diff --git a/build/terraform-beta b/build/terraform-beta index 9ad3f858ba37..73c8ee8311ba 160000 --- a/build/terraform-beta +++ b/build/terraform-beta @@ -1 +1 @@ -Subproject commit 9ad3f858ba3721b0562bad0e18afc922d156db64 +Subproject commit 73c8ee8311ba6d287a12fc29c20b4baa9c1e9758 diff --git a/build/terraform-mapper b/build/terraform-mapper index b21db16738db..48033b7bc1e8 160000 --- a/build/terraform-mapper +++ b/build/terraform-mapper @@ -1 +1 @@ -Subproject commit b21db16738db65bc0a426782821887e3b267e52d +Subproject commit 48033b7bc1e8c29030e30b65b3a17e7d66cc6044 diff --git a/third_party/terraform/utils/config.go.erb b/third_party/terraform/utils/config.go.erb index 54702c7f73cd..f535d5b71e4c 100644 --- a/third_party/terraform/utils/config.go.erb +++ b/third_party/terraform/utils/config.go.erb @@ -564,6 +564,7 @@ func (c *Config) LoadAndValidate() error { c.clientHealthcare.BasePath = healthcareClientBasePath <% end -%> + c.Region = GetRegionFromRegionSelfLink(c.Region) return nil } diff --git a/third_party/terraform/utils/self_link_helpers.go b/third_party/terraform/utils/self_link_helpers.go index 1ae06e1fd1af..fff3e87f6f5b 100644 --- a/third_party/terraform/utils/self_link_helpers.go +++ b/third_party/terraform/utils/self_link_helpers.go @@ -145,3 +145,15 @@ func GetLocationalResourcePropertiesFromSelfLinkString(selfLink string) (string, s := strings.Split(parsed.Path, "/") return s[4], s[6], s[8], nil } + +// return the region a selfLink is referring to +func GetRegionFromRegionSelfLink(selfLink string) string { + re := regexp.MustCompile("/compute/[a-zA-Z0-9]*/projects/[a-zA-Z0-9-]*/regions/([a-zA-Z0-9-]*)") + switch { + case re.MatchString(selfLink): + if res := re.FindStringSubmatch(selfLink); len(res) == 2 && res[1] != "" { + return res[1] + } + } + return selfLink +} diff --git a/third_party/terraform/utils/self_link_helpers_test.go b/third_party/terraform/utils/self_link_helpers_test.go index d6aed6a6937e..a9b674344731 100644 --- a/third_party/terraform/utils/self_link_helpers_test.go +++ b/third_party/terraform/utils/self_link_helpers_test.go @@ -110,3 +110,15 @@ func TestSelfLinkNameHash(t *testing.T) { } } } + +func TestGetRegionFromRegionSelfLink(t *testing.T) { + cases := map[string]string{ + "https://www.googleapis.com/compute/v1/projects/test/regions/europe-west3": "europe-west3", + "europe-west3": "europe-west3", + } + for input, expected := range cases { + if result := GetRegionFromRegionSelfLink(input); result != expected { + t.Errorf("expected to get %q from %q, got %q", expected, input, result) + } + } +}