Skip to content

scafeman/terraform-azurerm-vmss-cloudinit

 
 

Repository files navigation

Deploys a group of Cloud-Init enabled Virtual Machines in a Scale Set

Build Status

This Terraform module deploys a Virtual Machines Scale Set in Azure, initializes the VMs using Cloud-int for cloud-init-enabled virtual machine images, and returns the id of the VM scale set deployed.

This module requires a network and loadbalancer to be provided separately such as the "Azure/network/azurerm" and "Azure/loadbalancer/azurerm" modules.

Visit this website for more information about cloud-init. Some quick tips:

  • Troubleshoot logging via /var/log/cloud-init.log
  • Relevant applied cloud configuration information can be found in the /var/lib/cloud/instance directory
  • By default this module will create a new txt file /tmp/terraformtest to validate if cloud-init worked

To override the cloud-init configuration, place a file called cloudconfig.tpl in the root of the module directory with the cloud-init contents or update the cloudconfig_file variable with the location of the file containing the desired configuration.

Valid values for vm_os_simple are the latest versions of:

  • UbuntuServer = 16.04-LTS
  • UbuntuServer14 = 14.04.5-LTS
  • RHEL = RedHat Enterprise Linux 7
  • CentOS = CentOS 7
  • CoreOS = CoreOS Stable

Usage

provider "azurerm" {
  version = "~> 1.0"
}

variable "resource_group_name" {
  default = "terraform-vmss-cloudinit"
}

variable "location" {
  default = "eastus"
}

module "network" {
  source              = "Azure/network/azurerm"
  location            = "${var.location}"
  resource_group_name = "${var.resource_group_name}"
}

module "loadbalancer" {
  source              = "Azure/loadbalancer/azurerm"
  resource_group_name = "${var.resource_group_name}"
  location            = "${var.location}"
  prefix              = "terraform-test"

  "remote_port" {
    ssh = ["Tcp", "22"]
  }

  "lb_port" {
    http = ["80", "Tcp", "80"]
  }
}

module "vmss-cloudinit" {
  source                                 = "Azure/vmss-cloudinit/azurerm"
  resource_group_name                    = "${var.resource_group_name}"
  cloudconfig_file                       = "${path.module}/cloudconfig.tpl"
  location                               = "${var.location}"
  vm_size                                = "Standard_DS2_v2"
  admin_username                         = "azureuser"
  admin_password                         = "ComplexPassword"
  ssh_key                                = "~/.ssh/id_rsa.pub"
  nb_instance                            = 2
  vm_os_simple                           = "UbuntuServer"
  vnet_subnet_id                         = "${module.network.vnet_subnets[0]}"
  load_balancer_backend_address_pool_ids = "${module.loadbalancer.azurerm_lb_backend_address_pool_id}"
}

output "vmss_id" {
  value = "${module.vmss-cloudinit.vmss_id}"
}

Test

Configurations

We provide 2 ways to build, run, and test the module on a local development machine. Native (Mac/Linux) or Docker.

Native (Mac/Linux)

Prerequisites

Quick Run

We provide simple script to quickly set up module development environment:

$ curl -sSL https://raw.githubusercontent.com/Azure/terramodtest/master/tool/env_setup.sh | sudo bash

Then simply run it in local shell:

$ cd $GOPATH/src/{directory_name}/
$ bundle install
$ rake build
$ rake e2e

Docker

We provide a Dockerfile to build a new image based FROM the microsoft/terraform-test Docker hub image which adds additional tools / packages specific for this module (see Custom Image section). Alternatively use only the microsoft/terraform-test Docker hub image by using these instructions.

Prerequisites

Custom Image

This builds the custom image:

$ docker build --build-arg BUILD_ARM_SUBSCRIPTION_ID=$ARM_SUBSCRIPTION_ID --build-arg BUILD_ARM_CLIENT_ID=$ARM_CLIENT_ID --build-arg BUILD_ARM_CLIENT_SECRET=$ARM_CLIENT_SECRET --build-arg BUILD_ARM_TENANT_ID=$ARM_TENANT_ID -t azure-vmss-cloudinit .

This runs the build and unit tests:

$ docker run --rm azure-vmss-cloudinit /bin/bash -c "bundle install && rake build"

This runs the end to end tests:

$ docker run --rm azure-vmss-cloudinit /bin/bash -c "bundle install && rake e2e"

This runs the full tests:

$ docker run --rm azure-vmss-cloudinit /bin/bash -c "bundle install && rake full"

Authors

Originally created by David Tesar

License

MIT

About

Terraform AzureRM module registry to create a VM Scaleset initialized via cloud-init scripts

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • HCL 60.6%
  • Go 21.7%
  • Dockerfile 8.5%
  • Ruby 8.0%
  • Smarty 1.2%