Source repo import. (#2020)

This commit is contained in:
Nathan McKinley 2018-09-11 10:55:55 -07:00 committed by GitHub
parent 65669fc6d6
commit aab9e9e0c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 0 deletions

View File

@ -14,6 +14,10 @@ func resourceSourceRepoRepository() *schema.Resource {
Delete: resourceSourceRepoRepositoryDelete,
//Update: not supported,
Importer: &schema.ResourceImporter{
State: resourceSourceRepoRepositoryImport,
},
Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
@ -114,3 +118,17 @@ func buildRepositoryName(project, name string) string {
repositoryName := "projects/" + project + "/repos/" + name
return repositoryName
}
func resourceSourceRepoRepositoryImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
config := meta.(*Config)
parseImportId([]string{"projects/(?P<project>[^/]+)/repos/(?P<name>[^/]+)", "(?P<project>[^/]+)/(?P<name>[^/]+)", "(?P<name>[^/]+)"}, d, config)
// Replace import id for the resource id
id, err := replaceVars(d, config, "projects/{{project}}/repos/{{name}}")
if err != nil {
return nil, fmt.Errorf("Error constructing id: %s", err)
}
d.SetId(id)
return []*schema.ResourceData{d}, nil
}

View File

@ -25,6 +25,11 @@ func TestAccSourceRepoRepository_basic(t *testing.T) {
"google_sourcerepo_repository.acceptance", repositoryName),
),
},
resource.TestStep{
ResourceName: "google_sourcerepo_repository.acceptance",
ImportState: true,
ImportStateVerify: true,
},
},
})
}