terraform/examples/azure-vmss-ubuntu/main.tf

128 lines
4.2 KiB
Terraform
Raw Normal View History

provider/azurerm: Example of VM Scale Set with Ubuntu (#15290) * initial commit - 101-vm-from-user-image * changed branch name * not deploying - storage problems * provisions vm but image not properly prepared * storage not correct * provisions properly * changed main.tf to azuredeploy.tf * added tfvars and info for README * tfvars ignored and corrected file ext * added CI config; added sane defaults for variables; updated deployment script, added mac specific deployment for local testing * deploy.sh to be executable * executable deploy files * added CI files; changed vars * prep for PR * removal of old folder * prep for PR * wrong args for travis * more PR prep * updated README * commented out variables in terraform.tfvars * Topic 101 vm from user image (#2) * initial commit - 101-vm-from-user-image * added tfvars and info for README * added CI config; added sane defaults for variables; updated deployment script, added mac specific deployment for local testing * prep for PR * added new template * oops, left off master * prep for PR * correct repository for destination * renamed scripts to be more intuitive; added check for docker * merge vm simple; vm from image * initial commit * deploys locally * updated deploy * changed to allow http & https (like ARM tmplt) * changed host_name & host_name variable desc * merge master * added new constructs/naming for deploy scripts, etc. * suppress az login output * merge of CI config * prep for PR * took out armviz button and minor README changes * changed host_name * fixed merge conflicts * changed host_name variable * updating Hashicorp's changes to merged simple linux branch * updating files to merge w/master and prep for Hashicorp pr * Revert "updating files to merge w/master and prep for Hashicorp pr" This reverts commit b850cd5d2a858eff073fc5a1097a6813d0f8b362. * Revert "updating Hashicorp's changes to merged simple linux branch" This reverts commit dbaf8d14a9cdfcef0281919671357f6171ebd4e6. * work in progress; waiting on support for lb inbound nat & autoscale settings * changing .travis.yml for this branch * updated deploy validation; readme; travis.yml * in progress; lb inbound nat pool id argument added * deploys vmss, not autoscale (no resource) * merging hashicorp master into this branch * chmod for deploy scripts * cleaned up main.tf * ran tf fmt * fixed typo in travis.yml * pinning azuresdk/azure-cli-python version * typo * adding comments * provisions withouth autoscale * fixed clean up to destroy rg * renamed example directory * reverted to Hashicorp's travis.yml * merge conflict - return line * merge conflict - white space * updated README
2017-06-15 18:28:11 +02:00
# provider "azurerm" {
# subscription_id = "${var.subscription_id}"
# client_id = "${var.client_id}"
# client_secret = "${var.client_secret}"
# tenant_id = "${var.tenant_id}"
# }
resource "azurerm_resource_group" "rg" {
name = "${var.resource_group}"
location = "${var.location}"
}
resource "azurerm_virtual_network" "vnet" {
name = "${var.resource_group}vnet"
location = "${azurerm_resource_group.rg.location}"
address_space = ["10.0.0.0/16"]
resource_group_name = "${azurerm_resource_group.rg.name}"
}
resource "azurerm_subnet" "subnet" {
name = "subnet"
address_prefix = "10.0.0.0/24"
resource_group_name = "${azurerm_resource_group.rg.name}"
virtual_network_name = "${azurerm_virtual_network.vnet.name}"
}
resource "azurerm_public_ip" "pip" {
name = "${var.hostname}-pip"
location = "${azurerm_resource_group.rg.location}"
resource_group_name = "${azurerm_resource_group.rg.name}"
public_ip_address_allocation = "Dynamic"
domain_name_label = "${var.hostname}"
}
resource "azurerm_lb" "lb" {
name = "LoadBalancer"
location = "${azurerm_resource_group.rg.location}"
resource_group_name = "${azurerm_resource_group.rg.name}"
depends_on = ["azurerm_public_ip.pip"]
frontend_ip_configuration {
name = "LBFrontEnd"
public_ip_address_id = "${azurerm_public_ip.pip.id}"
}
}
resource "azurerm_lb_backend_address_pool" "backlb" {
name = "BackEndAddressPool"
resource_group_name = "${azurerm_resource_group.rg.name}"
loadbalancer_id = "${azurerm_lb.lb.id}"
}
resource "azurerm_lb_nat_pool" "np" {
resource_group_name = "${azurerm_resource_group.rg.name}"
loadbalancer_id = "${azurerm_lb.lb.id}"
name = "NATPool"
protocol = "Tcp"
frontend_port_start = 50000
frontend_port_end = 50119
backend_port = 22
frontend_ip_configuration_name = "LBFrontEnd"
}
resource "azurerm_storage_account" "stor" {
name = "${var.resource_group}stor"
location = "${azurerm_resource_group.rg.location}"
resource_group_name = "${azurerm_resource_group.rg.name}"
account_type = "${var.storage_account_type}"
}
resource "azurerm_storage_container" "vhds" {
name = "vhds"
resource_group_name = "${azurerm_resource_group.rg.name}"
storage_account_name = "${azurerm_storage_account.stor.name}"
container_access_type = "blob"
}
resource "azurerm_virtual_machine_scale_set" "scaleset" {
name = "autoscalewad"
location = "${azurerm_resource_group.rg.location}"
resource_group_name = "${azurerm_resource_group.rg.name}"
upgrade_policy_mode = "Manual"
overprovision = true
depends_on = ["azurerm_lb.lb", "azurerm_virtual_network.vnet"]
sku {
name = "${var.vm_sku}"
tier = "Standard"
capacity = "${var.instance_count}"
}
os_profile {
computer_name_prefix = "${var.vmss_name}"
admin_username = "${var.admin_username}"
admin_password = "${var.admin_password}"
}
os_profile_linux_config {
disable_password_authentication = false
}
network_profile {
name = "${var.hostname}-nic"
primary = true
ip_configuration {
name = "${var.hostname}ipconfig"
subnet_id = "${azurerm_subnet.subnet.id}"
load_balancer_backend_address_pool_ids = ["${azurerm_lb_backend_address_pool.backlb.id}"]
load_balancer_inbound_nat_rules_ids = ["${element(azurerm_lb_nat_pool.np.*.id, count.index)}"]
}
}
storage_profile_os_disk {
name = "${var.hostname}"
caching = "ReadWrite"
create_option = "FromImage"
vhd_containers = ["${azurerm_storage_account.stor.primary_blob_endpoint}${azurerm_storage_container.vhds.name}"]
}
storage_profile_image_reference {
publisher = "${var.image_publisher}"
offer = "${var.image_offer}"
sku = "${var.ubuntu_os_version}"
version = "latest"
}
}