Search code examples
azureterraformterraform-provider-azureazure-rm

How to deploy a Windows VM with Terraform Azure CAF?


I want to deploy a Windows VM with Azure Cloud Adoption Framework (CAF) using Terraform. In the example of configuration.tfvars, all the configuration is done.But I cannot find the correct terraform code to deploy this tfvars configuration.

The windows vm module is here.

So far, i have written the code below:

module "caf_virtual_machine" {
  source  = "aztfmod/caf/azurerm//modules/compute/virtual_machine"
  version = "5.0.0"
  # belows are the 7 required variables 

  base_tags = var.tags
  client_config = 
  global_settings = var.global_settings
  location = var.location
  resource_group_name = var.resource_group_name
  settings = 
  vnets =  var.vnets  
}

So the vnets, global_settings, resource_group_name variables already exists in the configuration.tfvars. I have added tags and location variables to the configuration.tfvars.

But what should i enter to settings and client_config variables?


Solution

  • The virtual machine is a private module. You should use it by calling the base CAF module.

    The Readme of the terraform registry explains how to leverage the core CAF module - https://registry.terraform.io/modules/aztfmod/caf/azurerm/latest/submodules/virtual_machine

    Source code of an example: https://github.com/aztfmod/terraform-azurerm-caf/tree/master/examples/compute/virtual_machine/211-vm-bastion-winrm-agents/registry

    You have a library of configuration files examples showing how to deploy virtual machines

    https://github.com/aztfmod/terraform-azurerm-caf/tree/master/examples/compute/virtual_machine

       module "caf" {
        source  = "aztfmod/caf/azurerm"
        version = "5.0.0"
        
        global_settings    = var.global_settings
        tags               = var.tags
        resource_groups    = var.resource_groups
        storage_accounts   = var.storage_accounts
        keyvaults          = var.keyvaults
        managed_identities = var.managed_identities
        role_mapping       = var.role_mapping
        
        diagnostics = {
          # Get the diagnostics settings of services to create
          diagnostic_log_analytics    = var.diagnostic_log_analytics
          diagnostic_storage_accounts = var.diagnostic_storage_accounts
        }
        
        compute = {
          virtual_machines = var.virtual_machines
        }
        
        networking = {
          vnets                             = var.vnets
          network_security_group_definition = var.network_security_group_definition
          public_ip_addresses               = var.public_ip_addresses
        }
        
        security = {
          dynamic_keyvault_secrets = var.dynamic_keyvault_secrets
        }
      }
    

    Note - it is recommended to leverage the VScode devcontainer provided in the source repository to execute the terraform deployment. The devcontainer includes the tooling required to deploy Azure solutions.