DevOps Classroom notes 19/Jan/2025

Terraform

Sharing Modules

  • Modules can be shared with others using
    • network drives (nfs)
    • git
    • Terraform Cloud

Lets create a Module Repository

  • We have create a Module repo with one module to create virtual network Refer Here
  • This module is hosted on github Refer Here for url

Lets use this module

  • Refer Here for the changes done
  • We have used the module

    • by using a source with reference to a tag and subfolder in git repo source = "github.com/dummyrepos/lttfmodules//azure/vnet?ref=v1.0.1"
    • configured azurerm backend
  • Exercise: use the module to create 4 subnets in your azure account using module at https://github.com/dummyrepos/lttfmodules

Multiple Environment Creation

  • When terraform template is configured with a backend it allows only one user to execute and stores the state in remote location
  • Now lets assume we have a usecase, where we are using the same template for multiple environments then backend is not enough
  • Generally template refers to one enivornment, (apply => environment)
  • To handle multiple environments from same template and same folder with same backend terraform uses workspaces.
  • Terraform workspaces are enabled by default, if your are not using workspaces you are indirectly using default workspace.

Best Practices for multiple environments

  • Create a backend
  • Create a tfvars file per environment
  • create workspaces with names equivlaent to your environments (dev, qa, staging, prod)
  • Now from CI/CD pipelines select the workspace post init and apply using a tfvars file using auto apporove
  • Ideally terraform template should call reusable modules
  • Ensure lint and security scans are followed and errors are fixed.

Exercise:

  • Learn markdown format to document your modules.

Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Animated Social Media Icons by Acurax Responsive Web Designing Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube