mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-03 08:42:39 +00:00
Source repo import. (#2020)
This commit is contained in:
parent
65669fc6d6
commit
aab9e9e0c2
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user