diff --git a/google/iam_source_repo_repository.go b/google/iam_source_repo_repository.go index 0796b037e1f..7af23791ff3 100644 --- a/google/iam_source_repo_repository.go +++ b/google/iam_source_repo_repository.go @@ -15,6 +15,7 @@ package google import ( "fmt" + "regexp" "github.com/hashicorp/errwrap" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -32,10 +33,18 @@ var SourceRepoRepositoryIamSchema = map[string]*schema.Schema{ Type: schema.TypeString, Required: true, ForceNew: true, - DiffSuppressFunc: compareSelfLinkOrResourceName, + DiffSuppressFunc: SourceRepoRepositoryDiffSuppress, }, } +func SourceRepoRepositoryDiffSuppress(_, old, new string, _ *schema.ResourceData) bool { + oldParts := regexp.MustCompile("projects/[^/]+/repos/").Split(old, -1) + if len(oldParts) == 2 { + return oldParts[1] == new + } + return new == old +} + type SourceRepoRepositoryIamUpdater struct { project string repository string @@ -56,7 +65,7 @@ func SourceRepoRepositoryIamUpdaterProducer(d *schema.ResourceData, config *Conf } // We may have gotten either a long or short name, so attempt to parse long name if possible - m, err := getImportIdQualifiers([]string{"projects/(?P[^/]+)/repos/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)"}, d, config, d.Get("repository").(string)) + m, err := getImportIdQualifiers([]string{"projects/(?P[^/]+)/repos/(?P.+)", "(?P.+)"}, d, config, d.Get("repository").(string)) if err != nil { return nil, err } @@ -87,7 +96,7 @@ func SourceRepoRepositoryIdParseFunc(d *schema.ResourceData, config *Config) err } values["project"] = project - m, err := getImportIdQualifiers([]string{"projects/(?P[^/]+)/repos/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)"}, d, config, d.Id()) + m, err := getImportIdQualifiers([]string{"projects/(?P[^/]+)/repos/(?P.+)", "(?P.+)"}, d, config, d.Id()) if err != nil { return err } diff --git a/google/iam_source_repo_repository_generated_test.go b/google/iam_source_repo_repository_generated_test.go index 27f6bf0a573..4bfd2a6cfea 100644 --- a/google/iam_source_repo_repository_generated_test.go +++ b/google/iam_source_repo_repository_generated_test.go @@ -39,7 +39,7 @@ func TestAccSourceRepoRepositoryIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_sourcerepo_repository_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/repos/%s roles/viewer", getTestProjectFromEnv(), fmt.Sprintf("my-repository%s", context["random_suffix"])), + ImportStateId: fmt.Sprintf("projects/%s/repos/%s roles/viewer", getTestProjectFromEnv(), fmt.Sprintf("my-repository/%s", context["random_suffix"])), ImportState: true, ImportStateVerify: true, }, @@ -49,7 +49,7 @@ func TestAccSourceRepoRepositoryIamBindingGenerated(t *testing.T) { }, { ResourceName: "google_sourcerepo_repository_iam_binding.foo", - ImportStateId: fmt.Sprintf("projects/%s/repos/%s roles/viewer", getTestProjectFromEnv(), fmt.Sprintf("my-repository%s", context["random_suffix"])), + ImportStateId: fmt.Sprintf("projects/%s/repos/%s roles/viewer", getTestProjectFromEnv(), fmt.Sprintf("my-repository/%s", context["random_suffix"])), ImportState: true, ImportStateVerify: true, }, @@ -75,7 +75,7 @@ func TestAccSourceRepoRepositoryIamMemberGenerated(t *testing.T) { }, { ResourceName: "google_sourcerepo_repository_iam_member.foo", - ImportStateId: fmt.Sprintf("projects/%s/repos/%s roles/viewer user:admin@hashicorptest.com", getTestProjectFromEnv(), fmt.Sprintf("my-repository%s", context["random_suffix"])), + ImportStateId: fmt.Sprintf("projects/%s/repos/%s roles/viewer user:admin@hashicorptest.com", getTestProjectFromEnv(), fmt.Sprintf("my-repository/%s", context["random_suffix"])), ImportState: true, ImportStateVerify: true, }, @@ -100,7 +100,7 @@ func TestAccSourceRepoRepositoryIamPolicyGenerated(t *testing.T) { }, { ResourceName: "google_sourcerepo_repository_iam_policy.foo", - ImportStateId: fmt.Sprintf("projects/%s/repos/%s", getTestProjectFromEnv(), fmt.Sprintf("my-repository%s", context["random_suffix"])), + ImportStateId: fmt.Sprintf("projects/%s/repos/%s", getTestProjectFromEnv(), fmt.Sprintf("my-repository/%s", context["random_suffix"])), ImportState: true, ImportStateVerify: true, }, @@ -111,7 +111,7 @@ func TestAccSourceRepoRepositoryIamPolicyGenerated(t *testing.T) { func testAccSourceRepoRepositoryIamMember_basicGenerated(context map[string]interface{}) string { return Nprintf(` resource "google_sourcerepo_repository" "my-repo" { - name = "my-repository%{random_suffix}" + name = "my-repository/%{random_suffix}" } resource "google_sourcerepo_repository_iam_member" "foo" { @@ -126,7 +126,7 @@ resource "google_sourcerepo_repository_iam_member" "foo" { func testAccSourceRepoRepositoryIamPolicy_basicGenerated(context map[string]interface{}) string { return Nprintf(` resource "google_sourcerepo_repository" "my-repo" { - name = "my-repository%{random_suffix}" + name = "my-repository/%{random_suffix}" } data "google_iam_policy" "foo" { @@ -147,7 +147,7 @@ resource "google_sourcerepo_repository_iam_policy" "foo" { func testAccSourceRepoRepositoryIamBinding_basicGenerated(context map[string]interface{}) string { return Nprintf(` resource "google_sourcerepo_repository" "my-repo" { - name = "my-repository%{random_suffix}" + name = "my-repository/%{random_suffix}" } resource "google_sourcerepo_repository_iam_binding" "foo" { @@ -162,7 +162,7 @@ resource "google_sourcerepo_repository_iam_binding" "foo" { func testAccSourceRepoRepositoryIamBinding_updateGenerated(context map[string]interface{}) string { return Nprintf(` resource "google_sourcerepo_repository" "my-repo" { - name = "my-repository%{random_suffix}" + name = "my-repository/%{random_suffix}" } resource "google_sourcerepo_repository_iam_binding" "foo" { diff --git a/google/resource_source_repo_repository.go b/google/resource_source_repo_repository.go index cfc4f22e0cd..32921f5549c 100644 --- a/google/resource_source_repo_repository.go +++ b/google/resource_source_repo_repository.go @@ -264,9 +264,8 @@ func resourceSourceRepoRepositoryDelete(d *schema.ResourceData, meta interface{} func resourceSourceRepoRepositoryImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { config := meta.(*Config) if err := parseImportId([]string{ - "projects/(?P[^/]+)/repos/(?P[^/]+)", - "(?P[^/]+)/(?P[^/]+)", - "(?P[^/]+)", + "projects/(?P[^/]+)/repos/(?P.+)", + "(?P.+)", }, d, config); err != nil { return nil, err } diff --git a/google/resource_source_repo_repository_generated_test.go b/google/resource_source_repo_repository_generated_test.go index cc2f663ee09..99d15189cf4 100644 --- a/google/resource_source_repo_repository_generated_test.go +++ b/google/resource_source_repo_repository_generated_test.go @@ -51,7 +51,7 @@ func TestAccSourceRepoRepository_sourcerepoRepositoryBasicExample(t *testing.T) func testAccSourceRepoRepository_sourcerepoRepositoryBasicExample(context map[string]interface{}) string { return Nprintf(` resource "google_sourcerepo_repository" "my-repo" { - name = "my-repository%{random_suffix}" + name = "my-repository/%{random_suffix}" } `, context) } diff --git a/website/docs/r/sourcerepo_repository.html.markdown b/website/docs/r/sourcerepo_repository.html.markdown index 6837d729750..11182ea10b3 100644 --- a/website/docs/r/sourcerepo_repository.html.markdown +++ b/website/docs/r/sourcerepo_repository.html.markdown @@ -41,7 +41,7 @@ To get more information about Repository, see: ```hcl resource "google_sourcerepo_repository" "my-repo" { - name = "my-repository" + name = "my-repository/" } ```
@@ -139,7 +139,6 @@ Repository can be imported using any of these accepted formats: ``` $ terraform import google_sourcerepo_repository.default projects/{{project}}/repos/{{name}} -$ terraform import google_sourcerepo_repository.default {{project}}/{{name}} $ terraform import google_sourcerepo_repository.default {{name}} ``` diff --git a/website/docs/r/sourcerepo_repository_iam.html.markdown b/website/docs/r/sourcerepo_repository_iam.html.markdown index ff42da1b0cd..34332f72aef 100644 --- a/website/docs/r/sourcerepo_repository_iam.html.markdown +++ b/website/docs/r/sourcerepo_repository_iam.html.markdown @@ -113,7 +113,6 @@ exported: For all import syntaxes, the "resource in question" can take any of the following forms: * projects/{{project}}/repos/{{name}} -* {{project}}/{{name}} * {{name}} Any variables not passed in the import command will be taken from the provider configuration.