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

Add lien support to project-factory #64

Merged
merged 1 commit into from
Dec 11, 2018
Merged

Conversation

adrienthebo
Copy link
Contributor

This commit adds a lien variable and backing logic to add liens to
GCP projects. This allows users to prevent projects from being
unintentionally deleted.

Because the lien is a Terraform resource, it's still possible to delete
the project with an errant `terraform destroy.

main.tf Show resolved Hide resolved
@lilithmooncohen lilithmooncohen self-requested a review November 9, 2018 20:18
Copy link

@lilithmooncohen lilithmooncohen left a comment

Choose a reason for hiding this comment

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

👍

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.

Great work, just one change.

variables.tf Outdated

variable "lien" {
description = "Add a lien on the project to prevent accidental deletion"
default = false
Copy link
Contributor

Choose a reason for hiding this comment

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

Our standard is to use the strings "true" and "false" for boolean variables.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed in amended commit 4483ccd

@adrienthebo adrienthebo force-pushed the adrienthebo/lien-resource branch from 0a7de1d to 4483ccd Compare November 9, 2018 21:09
@adrienthebo
Copy link
Contributor Author

Fixed up the default value for the lien variable, and added a negative test to the minimal fixture asserting that there are no liens.

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.

Still needs more work to match our standard of boolean variables as strings.

Project lien
*****************************************/
resource "google_resource_manager_lien" "lien" {
count = "${var.lien ? 1 : 0}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that a string is being used, you need to check for the string explicitly. See how we handle random 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.

When we check the random_project_id variable we don't do an explicit string comparison, as given by the following snippet from `main.tf:

locals {
  temp_project_id        = "${var.random_project_id ? format("%s-%s",var.name,random_id.random_project_id_suffix.hex) : var.name}"
  # [...]
}

I've also tested the behavior in the terraform console:

> "${"true" ? 1 : 0}"
1
> "${"false" ? 1 : 0}"
0
> "${"shrug" ? 1 : 0}"
__builtin_StringToBool: strconv.ParseBool: parsing "shrug": invalid syntax in:

${"${"shrug" ? 1 : 0}"}

That behaves as expected, only allowing true or false and rejecting other strings.

If we do an explicit string comparison, we lose the validation of the input as a boolean:

> "${"true" == "true" ? 1 : 0 }"
1
> "${"false" == "true" ? 1 : 0 }"
0
> "${"shrug" == "true" ? 1 : 0 }"
0

Have I missed something with how we should handle booleans?

Copy link
Contributor

Choose a reason for hiding this comment

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

The issue is we're relying on Terraform's implicit coercion from "true" to 1 which is not guaranteed.

https://www.terraform.io/docs/configuration/variables.html#booleans

Choose a reason for hiding this comment

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

Mirroring @morgante's comment here. Once that's resolved have a 👍 from me.

Copy link
Contributor

Choose a reason for hiding this comment

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

@adrienthebo Where did we land on this? Would like to merge soon.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Per the earlier discussion, this comparison is valid but we should use "true" over true as the variable input. I've updated the use of the bare true in the tests and updated this PR.

This commit adds a `lien` variable and backing logic to add liens to
GCP projects. This allows users to prevent projects from being
unintentionally deleted.

Because the lien is a Terraform resource, it's still possible to delete
the project with an errant `terraform destroy.
@adrienthebo adrienthebo force-pushed the adrienthebo/lien-resource branch from 4483ccd to 730bf88 Compare December 11, 2018 19:35
@morgante morgante merged commit 696a5a2 into master Dec 11, 2018
@adrienthebo adrienthebo deleted the adrienthebo/lien-resource branch December 13, 2018 00:18
@adrienthebo
Copy link
Contributor Author

Thanks!

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.

4 participants