-
Notifications
You must be signed in to change notification settings - Fork 547
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
Conversation
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.
👍
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.
Great work, just one change.
variables.tf
Outdated
|
||
variable "lien" { | ||
description = "Add a lien on the project to prevent accidental deletion" | ||
default = false |
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.
Our standard is to use the strings "true" and "false" for boolean variables.
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.
Changed in amended commit 4483ccd
0a7de1d
to
4483ccd
Compare
Fixed up the default value for the |
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.
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}" |
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.
Now that a string is being used, you need to check for the string explicitly. See how we handle random ID.
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.
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?
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.
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
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.
Mirroring @morgante's comment here. Once that's resolved have a 👍 from me.
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.
@adrienthebo Where did we land on this? Would like to merge soon.
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.
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.
4483ccd
to
730bf88
Compare
Thanks! |
This commit adds a
lien
variable and backing logic to add liens toGCP 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.