Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project iam policy import. #1875

Merged
merged 2 commits into from
Aug 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion google/resource_google_project_iam_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func resourceGoogleProjectIamPolicy() *schema.Resource {
Update: resourceGoogleProjectIamPolicyUpdate,
Delete: resourceGoogleProjectIamPolicyDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
State: resourceGoogleProjectIamPolicyImport,
},

Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -264,6 +264,11 @@ func resourceGoogleProjectIamPolicyDelete(d *schema.ResourceData, meta interface
return nil
}

func resourceGoogleProjectIamPolicyImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
d.Set("project", d.Id())
return []*schema.ResourceData{d}, nil
}

// Subtract all bindings in policy b from policy a, and return the result
func subtractIamPolicy(a, b *cloudresourcemanager.Policy) *cloudresourcemanager.Policy {
am := rolesToMembersMap(a.Bindings)
Expand Down
8 changes: 8 additions & 0 deletions google/resource_google_project_iam_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,14 @@ func TestAccProjectIamPolicy_basic(t *testing.T) {
testAccCheckGoogleProjectIamPolicyIsMerged("google_project_iam_policy.acceptance", "data.google_iam_policy.admin", pid),
),
},
resource.TestStep{
ResourceName: "google_project_iam_policy.acceptance",
ImportState: true,
// Skipping the normal "ImportStateVerify" - Unfortunately, it's not
// really possible to make the imported policy match exactly, since
// the policy depends on the service account being used to create the
// project.
},
// Finally, remove the custom IAM policy from config and apply, then
// confirm that the project is in its original state.
resource.TestStep{
Expand Down