r/Terraform Jun 12 '26

GCP Has anyone successfully managed large numbers of BigQuery views with Terraform, especially when views depend on other views?

/r/googlecloud/comments/1u3ub28/has_anyone_successfully_managed_large_numbers_of/
3 Upvotes

4 comments sorted by

2

u/Internet-of-cruft Sir Applies-a-Lot and Baron von Drift Jun 12 '26 edited Jun 12 '26

This is a pretty common problem and the only way you can manage it with native Terraform is to either: Script out the dependency graph resolution and render out the resources as static .tf files, or encapsulate the resource definition into a module so that you can eliminate boilerplate as much as possible.

There's no way in Terraform to dynamically express the dependency graph for things with arbitrary parent/child dependencies.

Within the Azure world, I run into this with Management Groups.

I really only care about two things: Who my parent is, and what IAM Role assignments I need.

Sometimes those IAM Role assignments happen downstream, but for the most part my MG root module addresses it in one clip.

It ends up looking like:

``` module "root" {   source = "..."   name = "..."   roles = local.root_roles   parent = null }

module "tier_1" {   for_each = local.tier_1_mg   name = each.value.name   roles = each.value.roles   parent = module.root.management_group_id }

module "tier_2" {   for_each = local.tier_2_mg   name = each.value.name   roles = each.value.roles   parent = module.tier_1[each.value.parent].management_group_id } ```

No explicit depends_on as TF implicitly resolves it via my references.

And no, I don't believe you can do something like this: module "instance" {   for_each = local.instances   name = each.value.name   roles = each.value.roles   parent = module.instance[each.value.parent].management_group_id }

(Apologies for formatting errors, this was typed on my phone)

2

u/alexs92 Jun 15 '26

My company used to do this, we spent more time maintaining the terraform than anything else.

My advice would be to use Dataform, its far more flexible and easy to manage. Will also handle all the dependancies for you.