Terraform with Modules example for basic AVD(or any Azure) Environment

Edit(03/09/2022):  To anyone who might have been trying to use this, after receiving some usage feedback, I've made a ton of changes to turn this into something that actually works.  Officially v1.0.

I completed some TF code that should make lives easier.  It builds all the basics necessary for an AVD environment but it could really be used to build the basics of any Azure environment.  It's modularized, so the root main.tf file is used to provide different variables if needed, but there's a default provided for almost everything.

Find the public repo here: https://github.com/chad-neal/avdtf-with-modules.

To make use of this, clone the repo.  In the root main.tf you'll find variable declarations in module blocks.  These link to the same variables declared in each modules' variables.tf.  Specify them in the root to change what the defaults are set to.  Or don't, if you're happy with what I've done.  Comment out, or delete, the module blocks that you don't need/want to use.  "Terraform apply" is looking at the root main.tf, then reading each of the child modules' configurations to decide which resources to build.

Anywhere you find a declaration like module.rg.rg_name, for example, it links to the outputs.tf file stored with the module.  In this example, in ./Modules/RG/outputs.tf, there's an object named "rg_name".  The value of this object is coming right from the main.tf of ./modules/rg where I specify the configuration for the resource.  Keep in mind that you can concatenate names, use wildcards, and all kinds of other things in outputs.tf to meet your needs.


Leave a comment