Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Declaring variables for terraform configuration
- variable "ARM_SUBSCRIPTION_ID" {}
- variable "ARM_CLIENT_ID" {}
- variable "ARM_CLIENT_SECRET" {}
- variable "ARM_TENANT_ID" {}
- # Declare env variable
- variable "env" {}
- # Declare storage account details
- variable "sto_acc_tier_std" {}
- variable "sto_acc_rep_type_lrs" {}
- # Declare Host basename
- variable "ax_base_hostname" {}
- # Declare VM details
- variable "image_publisher" {}
- variable "image_offer_win" {}
- variable "sku_2016_datacentre" {}
- variable "image_version" {}
- # End of declaring variables
- # Declaring various resources
- ###################################################################################################
- # Standard for Declaring Terraform Internal Variables
- ###################################################################################################
- # tf-{abbreviated resource type}-{Environment Name}
- # rg - Resource Group
- # vn - Virtual Network
- # sn - Subnet
- # ni - Network Interface
- # sa - Storage Account
- # vm - Virtual Machine
- # mdsk - Managed Disk
- # as - Availability Set
- ###################################################################################################
- #
- ###################################################################################################
- # Resource Group
- resource "azurerm_resource_group" "tf-rg-cluster-internal" {
- name = "rg_app"
- location = "southeastasia"
- tags {
- environment = "${var.env}"
- }
- }
- # Reference existing resource group for Virtual Network
- data "azurerm_resource_group" "tf-rg-cluster-external" {
- name = "rg_vnets"
- }
- # Reference existing Virtual Network
- data "azurerm_virtual_network" "tf-vn-cluster" {
- name = "vnet_frednxt_groups_preprod"
- resource_group_name = "${data.azurerm_resource_group.tf-rg-cluster-external.name}"
- }
- # Reference existing subnet
- # # Virtual Network
- # resource "azurerm_virtual_network" "tf-vn-cluster" {
- # name = "cluster-vn"
- # address_space = ["10.0.0.0/16"]
- # location = "${azurerm_resource_group.tf-rg-cluster.location}"
- # resource_group_name = "${azurerm_resource_group.tf-rg-cluster.name}"
- # }
- # Subnet
- data "azurerm_subnet" "tf-sn-cluster" {
- name = "subnet_app"
- virtual_network_name = "${data.azurerm_virtual_network.tf-vn-cluster.name}"
- resource_group_name = "${data.azurerm_resource_group.tf-rg-cluster-external.name}"
- }
- # resource "azurerm_subnet" "tf-sn-cluster" {
- # name = "cluster-sn"
- # resource_group_name = "${azurerm_resource_group.tf-rg-cluster.name}"
- # virtual_network_name = "${azurerm_virtual_network.tf-vn-cluster.name}"
- # address_prefix = "10.0.2.0/24"
- # }
- # Network Interface
- resource "azurerm_network_interface" "tf-ni-cluster" {
- count = 5
- name = "${var.ax_base_hostname}-NI-${count.index}"
- location = "${azurerm_resource_group.tf-rg-cluster-internal.location}"
- resource_group_name = "${azurerm_resource_group.tf-rg-cluster-internal.name}"
- ip_configuration {
- name = "${var.ax_base_hostname}_${count.index}.IP"
- subnet_id = "${data.azurerm_subnet.tf-sn-cluster.id}"
- private_ip_address_allocation = "static"
- private_ip_address ="10.100.1.${count.index+5}"
- }
- tags {
- environment = "${var.env}"
- }
- }
- # Storage Account
- resource "azurerm_storage_account" "tf-sa-cluster" {
- name = "${lower(var.ax_base_hostname)}stoacc${count.index}"
- location = "${azurerm_resource_group.tf-rg-cluster-internal.location}"
- resource_group_name = "${azurerm_resource_group.tf-rg-cluster-internal.name}"
- account_tier = "${var.sto_acc_tier_std}"
- account_replication_type = "${var.sto_acc_rep_type_lrs}"
- tags {
- environment = "${var.env}"
- }
- }
- # Optional Managed Data Disk
- resource "azurerm_managed_disk" "tf-mdsk-cluster" {
- count = 5
- name = "${var.ax_base_hostname}-DATADISK-${count.index}"
- location = "${azurerm_resource_group.tf-rg-cluster-internal.location}"
- resource_group_name = "${azurerm_resource_group.tf-rg-cluster-internal.name}"
- storage_account_type = "Standard_LRS"
- create_option = "Empty"
- disk_size_gb = "1024"
- }
- # Availability Set
- resource "azurerm_availability_set" "tf-as-cluster" {
- name = "avset"
- location = "${azurerm_resource_group.tf-rg-cluster-internal.location}"
- resource_group_name = "${azurerm_resource_group.tf-rg-cluster-internal.name}"
- platform_fault_domain_count = 2
- platform_update_domain_count = 2
- managed = true
- tags {
- environment = "${var.env}"
- }
- }
- resource "azurerm_virtual_machine" "tf-vm-cluster" {
- count = 5
- name = "${var.ax_base_hostname}-${count.index}"
- location = "${azurerm_resource_group.tf-rg-cluster-internal.location}"
- availability_set_id = "${azurerm_availability_set.tf-as-cluster.id}"
- resource_group_name = "${azurerm_resource_group.tf-rg-cluster-internal.name}"
- network_interface_ids = ["${element(azurerm_network_interface.tf-ni-cluster.*.id, count.index)}"]
- vm_size = "Standard_DS1_v2"
- # Uncomment this line to delete the OS disk automatically when deleting the VM
- delete_os_disk_on_termination = true
- # Uncomment this line to delete the data disks automatically when deleting the VM
- delete_data_disks_on_termination = true
- storage_image_reference {
- publisher = "${var.image_publisher}"
- offer = "${var.image_offer_win}"
- sku = "${var.sku_2016_datacentre}"
- version = "${var.image_version}"
- }
- storage_os_disk {
- name = "${var.ax_base_hostname}-OS-DISK-${count.index}"
- caching = "ReadWrite"
- create_option = "FromImage"
- managed_disk_type = "Standard_LRS"
- }
- # Optional data disks
- storage_data_disk {
- name = "${element(azurerm_managed_disk.tf-mdsk-cluster.*.name, count.index)}"
- managed_disk_id = "${element(azurerm_managed_disk.tf-mdsk-cluster.*.id, count.index)}"
- create_option = "Attach"
- lun = 0
- disk_size_gb = "${element(azurerm_managed_disk.tf-mdsk-cluster.*.disk_size_gb, count.index)}"
- }
- storage_data_disk {
- name = "${element(azurerm_managed_disk.tf-mdsk-cluster.*.name, count.index+1)}"
- managed_disk_id = "${element(azurerm_managed_disk.tf-mdsk-cluster.*.id, count.index)}"
- create_option = "Attach"
- lun = 1
- disk_size_gb = "${element(azurerm_managed_disk.tf-mdsk-cluster.*.disk_size_gb, count.index)}"
- }
- os_profile {
- computer_name = "${var.ax_base_hostname}-${count.index}"
- admin_username = "scmadmin"
- admin_password = "HashDollar135"
- }
- os_profile_windows_config {
- enable_automatic_upgrades = false
- }
- tags {
- environment = "${var.env}"
- }
- }
Add Comment
Please, Sign In to add comment