Activating a list of GCP APIs for a list of Projects using Terraform

Viewed 58

I have two lists

projects = ["prj01", "prj02", "prj03", "prj04", "prj05", "prj06", ]

apis = ["api1", "api2", "api3", "api4", "api5", "api6", "api7", "api8", "api9", "api10", ]

Using Terraform, I need to loop through the projects list one at a time and apply all the apis to each of the projects.

Can someone help me with this please.

1 Answers

Terraform builtin function setproduct allows you to create a new list after applying cartesian product.

E.g. setproduct(["prj01","prj02"], ["api1", "api2"])

this will result in a new list:

[
 [ "prj01", "api1" ], 
 [ "prj01", "api2" ]
],
[
 [ "prj02", "api1" ], 
 [ "prj02", "api2" ]
]

You can read more about this function at: https://www.terraform.io/language/functions/setproduct

Related