GoogleCloudPlatform / cloud-foundation-toolkit

The Cloud Foundation toolkit provides GCP best practices as code.
Apache License 2.0
947 stars 450 forks source link

Launchpad doesn't handle nested folders #535

Closed morgante closed 4 years ago

morgante commented 4 years ago

CFT Launchpad doesn't seem to currently support nested folders.

This is the config used:

apiVersion: cft.dev/v1alpha1
kind: Organization
spec:
  # TODO: capture real org ID
  id: 12345678
  folders:
  - id: "dev"
    displayName: "dev"
    folders:
    - id: "shared"
      displayName: "shared"
  - id: "prod"
    displayName: "production"
    folders:
      - id: "shared"
        displayName: "shared"

Command: cft lp generate CloudFoundation.yaml -d terraform

Actual output:

2020/01/10 16:36:47 debug: output location terraform
2020/01/10 16:36:47 debug: output flavor Terraform
2020/01/10 16:36:47 1 YAML documents loaded
Resource Map [4]:
  * Folder.dev <- []
  * Folder.prod <- []
  * Folder.qa <- []
  * Organization.12345678 <- [Folder.dev, Folder.prod, Folder.qa]
Organization.12345678 ("")
  + Folder.dev ("dev") < Organization.12345678
  + Folder.prod ("production") < Organization.12345678
  + Folder.qa ("QA") < Organization.12345678

Note that the shared folders don't show up anywhere.

morgante commented 4 years ago

@mikeweng Can you handle fixing this and adding appropriate tests?

mikeweng commented 4 years ago

I completely forget to test nested folders! Added code for it.

In your example config, it helped reveals 3 things:

  1. shared folder is not detected. Due to folder's validate() didn't recursively call subfolder's validate().
  2. the YAML definition should not be correct since shared cannot have 2 parents, dev and prod at the same time. Added code to fail on this condition.
  3. How assembledOrg.org initialization can be handled cleaner.

Test are added as well. Thanks!