diff --git a/build/terraform b/build/terraform index cb1d66c38763..df2ad1f78ce4 160000 --- a/build/terraform +++ b/build/terraform @@ -1 +1 @@ -Subproject commit cb1d66c38763f8a86984486dd6d9b87ef3b7283a +Subproject commit df2ad1f78ce4fab0958a9cc1745d65a729ad9e4a diff --git a/build/terraform-beta b/build/terraform-beta index 02195f9f0c24..2f3959869f93 160000 --- a/build/terraform-beta +++ b/build/terraform-beta @@ -1 +1 @@ -Subproject commit 02195f9f0c24db8f76371a35e551649b1f805cc4 +Subproject commit 2f3959869f939a07b0fee8ab10fb82a542505251 diff --git a/third_party/terraform/data_sources/data_source_container_registry_image.go b/third_party/terraform/data_sources/data_source_container_registry_image.go index 093784b5f3fc..e7791b8d9bc2 100644 --- a/third_party/terraform/data_sources/data_source_container_registry_image.go +++ b/third_party/terraform/data_sources/data_source_container_registry_image.go @@ -2,6 +2,7 @@ package google import ( "fmt" + "strings" "github.com/hashicorp/terraform/helper/schema" ) @@ -48,10 +49,11 @@ func containerRegistryImageRead(d *schema.ResourceData, meta interface{}) error d.Set("project", project) region, ok := d.GetOk("region") var url_base string + escapedProject := strings.Replace(project, ":", "/", -1) if ok && region != nil && region != "" { - url_base = fmt.Sprintf("%s.gcr.io/%s", region, project) + url_base = fmt.Sprintf("%s.gcr.io/%s", region, escapedProject) } else { - url_base = fmt.Sprintf("gcr.io/%s", project) + url_base = fmt.Sprintf("gcr.io/%s", escapedProject) } tag, t_ok := d.GetOk("tag") digest, d_ok := d.GetOk("digest") diff --git a/third_party/terraform/data_sources/data_source_container_registry_repository.go b/third_party/terraform/data_sources/data_source_container_registry_repository.go index 1ddcae3b60b5..d2d0bbe828b3 100644 --- a/third_party/terraform/data_sources/data_source_container_registry_repository.go +++ b/third_party/terraform/data_sources/data_source_container_registry_repository.go @@ -2,6 +2,7 @@ package google import ( "fmt" + "strings" "github.com/hashicorp/terraform/helper/schema" ) @@ -35,10 +36,11 @@ func containerRegistryRepoRead(d *schema.ResourceData, meta interface{}) error { } d.Set("project", project) region, ok := d.GetOk("region") + escapedProject := strings.Replace(project, ":", "/", -1) if ok && region != nil && region != "" { - d.Set("repository_url", fmt.Sprintf("%s.gcr.io/%s", region, project)) + d.Set("repository_url", fmt.Sprintf("%s.gcr.io/%s", region, escapedProject)) } else { - d.Set("repository_url", fmt.Sprintf("gcr.io/%s", project)) + d.Set("repository_url", fmt.Sprintf("gcr.io/%s", escapedProject)) } d.SetId(d.Get("repository_url").(string)) return nil diff --git a/third_party/terraform/tests/data_source_container_registry_test.go b/third_party/terraform/tests/data_source_container_registry_test.go index 0829a5d82023..5e006e9dfbd2 100644 --- a/third_party/terraform/tests/data_source_container_registry_test.go +++ b/third_party/terraform/tests/data_source_container_registry_test.go @@ -9,7 +9,7 @@ import ( func TestDataSourceGoogleContainerRegistryRepository(t *testing.T) { t.Parallel() - resourceName := "data.google_container_registry_repository.default" + resourceName := "data.google_container_registry_repository.test" resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -21,6 +21,8 @@ func TestDataSourceGoogleContainerRegistryRepository(t *testing.T) { resource.TestCheckResourceAttrSet(resourceName, "project"), resource.TestCheckResourceAttrSet(resourceName, "region"), resource.TestCheckResourceAttr(resourceName, "repository_url", "bar.gcr.io/foo"), + resource.TestCheckResourceAttrSet(resourceName+"Scoped", "project"), + resource.TestCheckResourceAttr(resourceName+"Scoped", "repository_url", "bar.gcr.io/example.com/foo"), ), }, }, @@ -28,10 +30,14 @@ func TestDataSourceGoogleContainerRegistryRepository(t *testing.T) { } const testAccCheckGoogleContainerRegistryRepo_basic = ` -data "google_container_registry_repository" "default" { +data "google_container_registry_repository" "test" { project = "foo" region = "bar" } +data "google_container_registry_repository" "testScoped" { + project = "example.com:foo" + region = "bar" +} ` func TestDataSourceGoogleContainerRegistryImage(t *testing.T) { @@ -51,6 +57,8 @@ func TestDataSourceGoogleContainerRegistryImage(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "image_url", "bar.gcr.io/foo/baz"), resource.TestCheckResourceAttr(resourceName+"2", "image_url", "bar.gcr.io/foo/baz:qux"), resource.TestCheckResourceAttr(resourceName+"3", "image_url", "bar.gcr.io/foo/baz@1234"), + resource.TestCheckResourceAttrSet(resourceName+"Scoped", "project"), + resource.TestCheckResourceAttr(resourceName+"Scoped", "image_url", "bar.gcr.io/example.com/foo/baz:qux"), ), }, }, @@ -75,4 +83,10 @@ data "google_container_registry_image" "test3" { name = "baz" digest = "1234" } +data "google_container_registry_image" "testScoped" { + project = "example.com:foo" + region = "bar" + name = "baz" + tag = "qux" +} `