mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-02 00:31:04 +00:00
Add more import paths for google_service_account. (#2261)
This commit is contained in:
parent
2f6b39ee21
commit
78f9957623
@ -17,7 +17,7 @@ func resourceGoogleServiceAccount() *schema.Resource {
|
|||||||
Delete: resourceGoogleServiceAccountDelete,
|
Delete: resourceGoogleServiceAccountDelete,
|
||||||
Update: resourceGoogleServiceAccountUpdate,
|
Update: resourceGoogleServiceAccountUpdate,
|
||||||
Importer: &schema.ResourceImporter{
|
Importer: &schema.ResourceImporter{
|
||||||
State: schema.ImportStatePassthrough,
|
State: resourceGoogleServiceAccountImport,
|
||||||
},
|
},
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"email": &schema.Schema{
|
"email": &schema.Schema{
|
||||||
@ -316,3 +316,20 @@ func saMergeBindings(bindings []*iam.Binding) []*iam.Binding {
|
|||||||
|
|
||||||
return rb
|
return rb
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func resourceGoogleServiceAccountImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
|
||||||
|
config := meta.(*Config)
|
||||||
|
parseImportId([]string{
|
||||||
|
"projects/(?P<project>[^/]+)/serviceAccounts/(?P<email>[^/]+)",
|
||||||
|
"(?P<project>[^/]+)/(?P<email>[^/]+)",
|
||||||
|
"(?P<email>[^/]+)"}, d, config)
|
||||||
|
|
||||||
|
// Replace import id for the resource id
|
||||||
|
id, err := replaceVars(d, config, "projects/{{project}}/serviceAccounts/{{email}}")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("Error constructing id: %s", err)
|
||||||
|
}
|
||||||
|
d.SetId(id)
|
||||||
|
|
||||||
|
return []*schema.ResourceData{d}, nil
|
||||||
|
}
|
||||||
|
@ -18,6 +18,7 @@ func TestAccServiceAccount_basic(t *testing.T) {
|
|||||||
displayName := "Terraform Test"
|
displayName := "Terraform Test"
|
||||||
displayName2 := "Terraform Test Update"
|
displayName2 := "Terraform Test Update"
|
||||||
project := getTestProjectFromEnv()
|
project := getTestProjectFromEnv()
|
||||||
|
expectedEmail := fmt.Sprintf("%s@%s.iam.gserviceaccount.com", accountId, project)
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
@ -32,6 +33,19 @@ func TestAccServiceAccount_basic(t *testing.T) {
|
|||||||
},
|
},
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
ResourceName: "google_service_account.acceptance",
|
ResourceName: "google_service_account.acceptance",
|
||||||
|
ImportStateId: fmt.Sprintf("projects/%s/serviceAccounts/%s", project, expectedEmail),
|
||||||
|
ImportState: true,
|
||||||
|
ImportStateVerify: true,
|
||||||
|
},
|
||||||
|
resource.TestStep{
|
||||||
|
ResourceName: "google_service_account.acceptance",
|
||||||
|
ImportStateId: fmt.Sprintf("%s/%s", project, expectedEmail),
|
||||||
|
ImportState: true,
|
||||||
|
ImportStateVerify: true,
|
||||||
|
},
|
||||||
|
resource.TestStep{
|
||||||
|
ResourceName: "google_service_account.acceptance",
|
||||||
|
ImportStateId: expectedEmail,
|
||||||
ImportState: true,
|
ImportState: true,
|
||||||
ImportStateVerify: true,
|
ImportStateVerify: true,
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user