terraform-google-modules / terraform-example-foundation

Shows how the CFT modules can be composed to build a secure cloud foundation
https://cloud.google.com/architecture/security-foundations
Apache License 2.0
1.18k stars 701 forks source link

Validate parent_folder early #1284

Closed lpezet closed 1 week ago

lpezet commented 1 week ago

TL;DR

Documentation says parent_folder must be a numerical value. I used the name of the folder instead by mistake, and process started fine, created groups and other resources before breaking because the value of parent_folder was not valid. Input validation here would make process more robust and reliable.

Terraform Resources

# 0-bootstrap/variables.tf
...
variable "parent_folder" {
  description = "Optional - for an organization with existing projects or for development/validation. It will place all the example foundation resources under the provided folder instead of the root organization. The value is the numeric folder ID. The folder must already exist."
  type        = string
  default     = ""
}
...

### Detailed design

```markdown
Multiple options are possible:
1. Use of `check` block
2. Use of `google_folder` resource, as done in test/setup/main.tf (resource google_folder.test_folder)
3. Use of `validation` inside the variable `parent_folder`, as done in 0-bootstrap/variables.tf (variable `groups`)

Additional information

Based on the documentation, using the google_folder resource would validate the folder exists (and therefore is also a valid numerical value).