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

Allow project name to be changed separately from project ID #154

Merged

Conversation

thefirstofthe300
Copy link
Contributor

Fixes #132.

@thefirstofthe300 thefirstofthe300 marked this pull request as ready for review March 1, 2019 19:58
Copy link
Contributor

@aaron-lane aaron-lane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The project_id interface needs to be added to the gsuite_enabled module.

We should test these changes against the minimal suite converged from the master branch. Are there any unexpected consequences just from updating? Can the name be changed without destroying resources?

@thefirstofthe300
Copy link
Contributor Author

The project_id interface needs to be added to the gsuite_enabled module.

I think you are referring to this change?

We should test these changes against the minimal suite converged from the master branch. Are there any unexpected consequences just from updating? Can the name be changed without destroying resources?

https://gist.github.com/thefirstofthe300/d72f2d563196e1fce1ab36b734e64fdb

The minimal test converges properly. The full test suite recreates the project because the project ID changes. The precondition being rebuilt is due to an old container version being used and causing the shell command to fail. I'm going to be submitting a PR tomorrow to update the container and make targets since the targets themselves fail right now.

@aaron-lane
Copy link
Contributor

@thefirstofthe300:

Apologies: I missed the changes to gsuite_enabled. 😊

With respect to testing the full suite, can you verify the impact of changing only the name?

Copy link
Contributor

@morgante morgante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looks good except dropping local.project_id.

s_account_fmt = "${format("serviceAccount:%s", google_service_account.default_service_account.email)}"
api_s_account = "${format("%[email protected]", local.project_number)}"
api_s_account = "${format("%[email protected]", google_project.main.number)}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't this continue to reference project_number?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The net effect of this change is a no-op. It removes a level of indirection since local.project_number is referring to google_project.main.number. I see no purpose for continuing to use local.project_number. It makes things a bit more difficult to read so I would much prefer to remove it.

@@ -26,18 +26,17 @@ resource "random_id" "random_project_id_suffix" {
*****************************************/
locals {
group_id = "${var.manage_group ? format("group:%s", var.group_email) : ""}"
project_id = "${google_project.main.project_id}"
project_number = "${google_project.main.number}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why drop local.project_number?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The local here is a level of indirection that is unnecessary, IMHO.

Copy link
Contributor

@morgante morgante Mar 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's easier to manage this in one place instead of having to update it on every resource.

project_org_id = "${var.folder_id != "" ? "" : var.org_id}"
project_folder_id = "${var.folder_id != "" ? var.folder_id : ""}"
temp_project_id = "${var.random_project_id ? format("%s-%s",var.name,random_id.random_project_id_suffix.hex) : var.name}"
project_id = "${var.project_id == "" ? var.name : var.project_id}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should continue to have project_id reference the actual project created.

We can move the conditional check into the project ID itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This local doesn't necessarily refer to the value that will be used to set the project's ID. I'll rename these variables to make the naming a bit more sane.

@@ -104,7 +103,7 @@ resource "google_resource_manager_lien" "lien" {
resource "google_project_service" "project_services" {
count = "${length(var.activate_apis)}"

project = "${local.project_id}"
project = "${google_project.main.project_id}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep local.project_id unless there's a reason we can't, similarly for all cases of this replacement.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am of the opinion that the project_id local should be removed or repurposed to make the project_id generation more clear. It also adds a layer of redirection that seems unnecessary so my comments on dropping the project_number local applies as well.

Copy link
Contributor Author

@thefirstofthe300 thefirstofthe300 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made a couple of tweaks around local naming.

I'm not sold on the idea of using locals that are equivalent to resource outputs. We should be using the resource outputs directly and avoid declaring those locals.

@@ -26,18 +26,17 @@ resource "random_id" "random_project_id_suffix" {
*****************************************/
locals {
group_id = "${var.manage_group ? format("group:%s", var.group_email) : ""}"
project_id = "${google_project.main.project_id}"
project_number = "${google_project.main.number}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The local here is a level of indirection that is unnecessary, IMHO.

s_account_fmt = "${format("serviceAccount:%s", google_service_account.default_service_account.email)}"
api_s_account = "${format("%[email protected]", local.project_number)}"
api_s_account = "${format("%[email protected]", google_project.main.number)}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The net effect of this change is a no-op. It removes a level of indirection since local.project_number is referring to google_project.main.number. I see no purpose for continuing to use local.project_number. It makes things a bit more difficult to read so I would much prefer to remove it.

@@ -104,7 +103,7 @@ resource "google_resource_manager_lien" "lien" {
resource "google_project_service" "project_services" {
count = "${length(var.activate_apis)}"

project = "${local.project_id}"
project = "${google_project.main.project_id}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am of the opinion that the project_id local should be removed or repurposed to make the project_id generation more clear. It also adds a layer of redirection that seems unnecessary so my comments on dropping the project_number local applies as well.

morgante
morgante previously approved these changes Mar 6, 2019
Copy link
Contributor

@morgante morgante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can merge, but I'm unconvinced that spreading ${google_project.main.project_id} into a dozen locations instead of referencing ${local.project_id} everywhere is superior.

@@ -51,10 +63,6 @@
end
end

it "includes the Google App Engine API service account user" do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thefirstofthe300 Please do not introduce completely unrelated changes into a different PR. Is this somehow related to the other functionality in this PR and I missed it?

@morgante morgante merged commit 30770cf into terraform-google-modules:master Mar 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants