terraform-azurerm-caf

repository·main·Indexed 20 days ago

https://github.com/aztfmod/terraform-azurerm-caf

A Terraform module based on the Microsoft Cloud Adoption Framework (CAF) for Azure, designed to provision Azure resources following best practices. It can be used as a standalone module or as part of larger Azure Terraform Landing Zones. The module follows an iterative pattern, allowing users to define multiple objects (such as API Management, App Configuration, App Insights, Automation, Azure Active Directory, and Cognitive Services) within a single module call using a map structure.

Tokens
108.6K
Snippets
266
Records
390
Agent score
69%

What's inside terraform-azurerm-caf

  1. Use for_each instead of count for resource iteration

    main

    When creating resources iteratively, prefer for_each over count. Using for_each provides:

    1. Reliable lifecycles: Deleting one item in a list doesn't cause a cascade of recreations like count might.
    2. Key-based access: You can use the iteration key to reference specific resources in other modules.
    3. Log visibility: Clearer visibility in Terraform logs.
    resource "azurerm_log_analytics_solution" "la_solution" {
      for_each = var.solution_plan_map
    
        solution_name         = each.key
        location              = var.location
        resource_group_name   = var.resource_group_name
        workspace_resource_id = azurerm_log_analytics_workspace.log_analytics.id
        workspace_name        = azurerm_log_analytics_workspace.log_analytics.name
    
      plan {
        product   = each.value.product
        publisher = each.value.publisher
      }
    }
  2. Use the iterative object pattern for CAF modules

    main

    The CAF Terraform module is designed to be iterative. Instead of defining individual resources for every component, you provide a map of objects to a specific configuration key. Each key in the map represents a unique instance of the resource you want to create. Use the following structure to define multiple objects:

    resource_to_be_created = {
      object1 = {
        # configuration details
      }
      object2 = {
        # configuration details
      }
    }
    resource_to_be_created = {
      object1 = {
        #configuration details as below
      }
      object2 = {
        #configuration details as below
      }
    }
  3. Use the iterative pattern to create multiple objects

    main

    The CAF Terraform module is designed to be iterative. Instead of creating separate module blocks for every resource, you provide a map of objects to the relevant configuration attribute. This allows you to manage multiple instances of the same resource type (like Load Balancers) within a single module instantiation.

    # Pattern for defining multiple objects
    resource_to_be_created = {
      object1 = {
        # configuration details
      }
      object2 = {
        # configuration details
      }
    }
  4. Iterative object instantiation in CAF Terraform

    main

    The CAF Terraform module is designed to be iterative. Instead of defining single resources, you provide a map of objects to the specific resource key. This allows you to instantiate multiple instances of the same resource type within a single module call.

    Use the following structure for any resource object:

    resource_key = {
      object_id_1 = {
        # configuration details
      }
      object_id_2 = {
        # configuration details
      }
    }
    resource_to_be_created = {
      object1 = {
        # configuration details
      }
      object2 = {
        # configuration details
      }
    }
  5. Module Output conventions

    main

    To maintain consistency across the CAF module, all sub-modules should implement a minimal set of standard output variables. Additionally, any output containing identifiers or secrets must be marked as sensitive to prevent exposure in log files.

    Standard output variables:

    • id: Returns the object identifiers.
    • name: Returns the object name.
    • object: Returns the full resource object.
  6. Define multiple Redis Cache objects iteratively

    main

    The CAF Terraform module uses an iterative pattern. Instead of defining separate resources for every instance, you provide a map of objects to the module. Each key in the map represents a unique object identifier, and the value is a configuration object containing the specific details for that instance.

    # Example of the iterative structure used for object definitions
    resource_to_be_created = {
      object1 = {
        # configuration details
      }
      object2 = {
        # configuration details
      }
    }
  7. Iterative object pattern in CAF Terraform

    main

    The CAF Terraform module uses an iterative pattern for resource creation. Instead of defining individual resources, you provide a map of objects to the corresponding module argument. Each key in the map acts as a unique identifier for that specific instance of the resource.

    Example structure:

    resource_to_be_created = {
      object1 = {
        # configuration details
      }
      object2 = {
        # configuration details
      }
    }
  8. How the iterative object pattern works in CAF Terraform

    main

    The CAF Terraform module uses an iterative pattern for resource creation. Instead of defining individual resources, you provide a map of objects. Each key in the map represents a unique object identifier, and the value is a configuration object containing the specific details for that instance. This allows you to scale your landing zone by adding more entries to the map without adding more module blocks.

    resource_to_be_created = {
      object1 = {
        # configuration details
      }
      object2 = {
        # configuration details
      }
    }
  9. How the CAF Terraform module handles iterative objects

    main

    The CAF Terraform module follows an iterative pattern. Instead of creating individual resources for every instance, you provide a map of objects to the relevant configuration attribute. Each key in the map represents a unique object identifier, and the value contains the specific configuration details for that instance. This allows you to manage multiple related resources (like multiple recovery vaults) within a single module block.

    # Pattern for defining multiple objects
    resource_to_be_created = {
      object1 = {
        # configuration details
      }
      object2 = {
        # configuration details
      }
    }
  10. How the iterative object structure works in CAF

    main

    The CAF Terraform module uses an iterative pattern. Instead of creating separate module blocks for every resource, you provide a map where each key represents a unique object identifier and the value contains that object's specific configuration details. This allows you to manage multiple instances of a resource type (like SQL Servers) within one module instantiation.

    # Example of the iterative map structure used for resource configuration
    resource_to_be_created = {
      object1 = {
        # configuration details for the first instance
      }
      object2 = {
        # configuration details for the second instance
      }
    }