Terraform create and bootstrap Azure subscriptions

Viewed 623

We are currently developing a Terraform project which helps us manage Azure Subscriptions for our internal customers. Essentially it takes a couple of inputs and then

  • Generates the WAN backend infrastructure (virtual WAN, express-route, ...)
  • For each subscription (there will be potentially hundreds):
    • Create the subscription
    • Create a service principal and assign permissions
    • Create a vNet within the subscription
    • Connect it to the central vWAN
    • Create a Git project with boilerplate terraform for the new subscription, having the vNet as data source

The idea is to manage only necessary things from the central project and then have individual projects manage the subscriptions contents.

My question though is: I can do almost all I've mentioned above, I fail to find a way to create vNets within the created subscriptions though. The subscription is part of the provider configuration and hence one provider is required for each subscriptions being generated. How do I manage to create resources in (potentially many) created subscriptions if the subscription is part of the provider?

Tried different ways to automatically generate the providers based on the subscription input, but there's a few problems with it: I know I can use multiple providers, but not in combination with a for_each structure. I also cannot use Modules for this, as modules containing provider blocks are incompatible with the for_each for modules introduced in TF 0.13.

How can I achieve to create a high amount of subscriptions and provision a vNet in them from a single Terraform project?

0 Answers
Related