-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from devwithkrishna/feature/vmss-linux
Feature/vmss linux
- Loading branch information
Showing
9 changed files
with
375 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#cloud-config | ||
package_update: true | ||
packages: | ||
- unzip | ||
- git | ||
- wget | ||
- apt-transport-https | ||
- software-properties-common | ||
- azure-cli | ||
- terraform | ||
- ca-certificates | ||
- curl | ||
- gnupg | ||
- lsb-release | ||
runcmd: | ||
- sudo apt-get update | ||
- sudo apt install nginx -y | ||
- sudo curl -fsSL https://get.docker.com -o get-docker.sh | ||
- sudo sh ./get-docker.sh | ||
- docker --info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
data "azurerm_subnet" "subnet" { | ||
name = var.subnet_name | ||
resource_group_name = var.vnet_resource_group | ||
virtual_network_name = var.vnet_name | ||
} | ||
|
||
data "local_file" "cloudinit" { | ||
filename = "${path.module}/cloudinit.conf" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
resource "azurerm_public_ip" "lb_pub_ip" { | ||
name = "${var.vmss_name}-publicip" | ||
location = azurerm_resource_group.rg.location | ||
resource_group_name = azurerm_resource_group.rg.name | ||
allocation_method = "Static" | ||
} | ||
|
||
resource "azurerm_lb" "lb" { | ||
name = "${var.vmss_name}-lb" | ||
location = azurerm_resource_group.rg.location | ||
resource_group_name = azurerm_resource_group.rg.name | ||
sku = var.load_balancer_sku | ||
|
||
frontend_ip_configuration { | ||
name = "${var.vmss_name}-frontend-ip" | ||
public_ip_address_id = azurerm_public_ip.lb_pub_ip.id | ||
} | ||
} | ||
|
||
resource "azurerm_lb_backend_address_pool" "backend_address_pool" { | ||
loadbalancer_id = azurerm_lb.lb.id | ||
name = "${var.vmss_name}-lb-backendaddresspool" | ||
|
||
} | ||
|
||
resource "azurerm_lb_rule" "lb_rule" { | ||
loadbalancer_id = azurerm_lb.lb.id | ||
name = "port-${var.frontend_port}" | ||
protocol = "Tcp" | ||
frontend_port = var.frontend_port | ||
backend_port = var.backend_port | ||
frontend_ip_configuration_name = "${var.vmss_name}-frontend-ip" | ||
backend_address_pool_ids = ["${azurerm_lb_backend_address_pool.backend_address_pool.id}"] | ||
} | ||
|
||
resource "azurerm_lb_probe" "health" { | ||
loadbalancer_id = azurerm_lb.lb.id | ||
name = "${var.vmss_name}-health-check" | ||
port = var.frontend_port | ||
protocol = var.protocol | ||
request_path = var.request_path | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
output "subnet_id" { | ||
value = data.azurerm_subnet.subnet.id | ||
description = "Azure Subnet id" | ||
} | ||
|
||
output "azure_vmss_name" { | ||
value = azurerm_linux_virtual_machine_scale_set.vmss.name | ||
description = "Azure VMSS name" | ||
} | ||
|
||
output "azure_vmss_rg" { | ||
value = azurerm_resource_group.rg.name | ||
description = "Azure VMSS Rg" | ||
} | ||
|
||
output "type_of_instances" { | ||
value = azurerm_linux_virtual_machine_scale_set.vmss.priority | ||
description = "Spot or Regular instances" | ||
} | ||
|
||
output "data_disks" { | ||
value = azurerm_linux_virtual_machine_scale_set.vmss.data_disk | ||
description = "VMSS data disks" | ||
} | ||
|
||
output "os_disk" { | ||
value = azurerm_linux_virtual_machine_scale_set.vmss.os_disk[0].disk_size_gb | ||
description = "VMSS os disk size" | ||
} | ||
|
||
output "admin_username" { | ||
value = var.admin_username | ||
description = "VMSS user name" | ||
} | ||
|
||
output "admin_password" { | ||
value = random_password.password.result | ||
sensitive = false | ||
description = "VMSS user password" | ||
} | ||
|
||
output "loadbalancer_id" { | ||
value = azurerm_lb.lb.id | ||
description = "AzureLoad balancer Id" | ||
} | ||
|
||
output "load_balancer_frontend_public_ip" { | ||
value = azurerm_public_ip.lb_pub_ip.ip_address | ||
description = "Azure load balancer frontend ip address" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
terraform { | ||
required_version = "~> 1.3" | ||
required_providers { | ||
azurerm = { | ||
source = "hashicorp/azurerm" | ||
version = "~> 3.0" | ||
} | ||
random = { | ||
source = "hashicorp/random" | ||
version = ">= 3.1" | ||
} | ||
} | ||
} | ||
provider "azurerm" { | ||
features {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
variable "resource_group_name" { | ||
default = "" | ||
description = "Azure VMSS resource group name" | ||
type = string | ||
} | ||
|
||
variable "vmss_name" { | ||
default = "" | ||
description = "Azure VMSS name" | ||
type = string | ||
} | ||
|
||
variable "location" { | ||
default = "" | ||
description = "Azure location" | ||
type = string | ||
} | ||
|
||
variable "sku_size" { | ||
default = "" | ||
description = "Azure VMSS sku" | ||
type = string | ||
} | ||
|
||
variable "default_instance_count" { | ||
default = 0 | ||
description = "Default instance count for the VMSS" | ||
type = number | ||
} | ||
|
||
variable "admin_username" { | ||
default = "admin_user" | ||
description = "VMSS default user name" | ||
type = string | ||
} | ||
|
||
|
||
variable "subnet_name" { | ||
default = "" | ||
description = "Azure subnet name to create vmss" | ||
type = string | ||
} | ||
|
||
variable "vnet_name" { | ||
default = "" | ||
description = "Azure Vnet Name" | ||
type = string | ||
} | ||
|
||
variable "vnet_resource_group" { | ||
default = "" | ||
description = "Azure Vnet resource group" | ||
type = string | ||
} | ||
|
||
|
||
variable "os_disk_storage_account_type" { | ||
default = "Standard_LRS" | ||
description = "OS disk storage account type" | ||
type = string | ||
validation { | ||
condition = contains(["Standard_LRS", "StandardSSD_LRS", "StandardSSD_ZRS", "Premium_LRS", "Premium_ZRS"], var.os_disk_storage_account_type) | ||
error_message = "OS disk storage account type must be one among Standard_LRS,StandardSSD_LRS,StandardSSD_ZRS,Premium_LRS,Premium_ZRS." | ||
} | ||
} | ||
|
||
variable "os_disk_size" { | ||
default = 30 | ||
description = "OS disk size in GB" | ||
type = number | ||
} | ||
|
||
|
||
variable "additional_data_disks" { | ||
description = "Adding additional disks capacity to add each instance in GB" | ||
type = list(number) | ||
default = [] | ||
} | ||
|
||
variable "additional_data_disks_storage_account_type" { | ||
description = "The Type of Storage Account which should back this Data Disk. Possible values include Standard_LRS, StandardSSD_LRS, Premium_LRS and UltraSSD_LRS." | ||
default = "Standard_LRS" | ||
type = string | ||
validation { | ||
condition = contains(["Standard_LRS", "StandardSSD_LRS", "StandardSSD_ZRS", "Premium_LRS", "Premium_ZRS"], var.additional_data_disks_storage_account_type) | ||
error_message = "Data disk storage account type must be one among Standard_LRS,StandardSSD_LRS,StandardSSD_ZRS,Premium_LRS,Premium_ZRS." | ||
} | ||
} | ||
|
||
variable "application_name" { | ||
default = "" | ||
description = "Azure application name tag" | ||
type = string | ||
} | ||
|
||
variable "environment" { | ||
default = "" | ||
description = "Environment tag value in Azure" | ||
type = string | ||
validation { | ||
condition = contains(["DEV", "QA", "UAT", "PROD"], var.environment) | ||
error_message = "Environment value should be one among DEV or QA or UAT or PROD." | ||
} | ||
} | ||
|
||
variable "priority" { | ||
default = "" | ||
description = "Type of vmss instances Spot or regular" | ||
type = string | ||
validation { | ||
condition = contains(["Spot", "Regular"], var.priority) | ||
error_message = "Priority Should be either Regular or Spot." | ||
} | ||
} | ||
|
||
variable "eviction_policy" { | ||
default = "Delete" | ||
description = "Azure Spot VM eviction policy Delete or Deallocate" | ||
type = string | ||
} | ||
|
||
variable "load_balancer_sku" { | ||
default = "Basic" | ||
description = "Azure Loadbalancer Skus" | ||
type = string | ||
validation { | ||
condition = contains(["Basic", "Standard", "Gateway"], var.load_balancer_sku) | ||
error_message = "Load balancer SKU must be one among Basic , Standard or Gateway type." | ||
} | ||
} | ||
|
||
variable "frontend_port" { | ||
default = 80 | ||
type = number | ||
description = "Port on which queries for status of application" | ||
} | ||
|
||
variable "backend_port" { | ||
default = 80 | ||
type = number | ||
description = "Port on which traffic is passed on to application backends" | ||
} | ||
variable "request_path" { | ||
default = "/" | ||
type = string | ||
description = "Health check path" | ||
} | ||
|
||
variable "protocol" { | ||
default = "Http" | ||
description = "Protocol for Load balancing" | ||
type = string | ||
validation { | ||
condition = contains(["Http", "Https", "Tcp"], var.protocol) | ||
error_message = "Protocol value should be one among Http, Https or Tcp." | ||
} | ||
} | ||
|
Oops, something went wrong.