-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Folder support: Assign/Reassign a google project to a folder. #438
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,15 +24,44 @@ var ( | |
originalPolicy *cloudresourcemanager.Policy | ||
) | ||
|
||
// Test that a Project resource can be created without an organization | ||
func TestAccGoogleProject_createWithoutOrg(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We run our acceptance tests using a service account (not user credentials). Unfortunately, a service account belongs to an org and therefor, cannot create a project without a parent organization. One solution: we could add a skip if a service account is used. This means we could run it locally but they wouldn't be ran by our CI server. @paddycarver Any other solutions for this? Running user credentials for the CI server? Not sure it is safe/worth it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added logic to skip the test if a service account is used. @paddycarver if you have a better suggestion, we can fix it in a separate PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm late to the party here--sorry, I was out of office on Thursday--but IIRC we were talking about the possibility of getting the service account our CI runs with whitelisted for creating a project without a parent organisation, though I've lost track of where that discussion landed or what its current status is. That's my preferred solution, honestly, but we can follow up on this with a more permanent fix in a separate PR. |
||
creds := multiEnvSearch(credsEnvVars) | ||
if strings.Contains(creds, "iam.gserviceaccount.com") { | ||
t.Skip("Service accounts cannot create projects without a parent. Requires user credentials.") | ||
} | ||
|
||
pid := "terraform-" + acctest.RandString(10) | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
// This step creates a new project | ||
resource.TestStep{ | ||
Config: testAccGoogleProject_createWithoutOrg(pid, pname), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckGoogleProjectExists("google_project.acceptance", pid), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that you can create folders, you can add acceptance tests for assigning a project to a folder and moving a project from a folder to an org and vice versa. Since you will be on vacation, I can also take care of writing the new tests. LMK what you prefer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That sounds great. I won't have time for this till middle of next month, and so it would be great if you could add the tests with folder creation and movement between folders. I'll circle back in case you don't have time in the next couple of weeks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oki. I will write these tests today. Thanks! |
||
// Test that a Project resource can be created and an IAM policy | ||
// associated | ||
func TestAccGoogleProject_create(t *testing.T) { | ||
skipIfEnvNotSet(t, | ||
[]string{ | ||
"GOOGLE_ORG", | ||
}..., | ||
) | ||
|
||
pid := "terraform-" + acctest.RandString(10) | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
// This step imports an existing project | ||
// This step creates a new project | ||
resource.TestStep{ | ||
Config: testAccGoogleProject_create(pid, pname, org), | ||
Check: resource.ComposeTestCheckFunc( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add
d.Set("folder_id", "")
here. and the same for the `org_id field in the folder case below. The reason is that if you move a project from a folder to an org outside of Terraform, we want Terraform to clear the other field when reading the state.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.