Skip to content

Commit

Permalink
Merge pull request #8 from devwithkrishna/feature/vmss-linux
Browse files Browse the repository at this point in the history
Feature/vmss linux
  • Loading branch information
githubofkrishnadhas authored Sep 10, 2024
2 parents ce3823b + 764de7d commit 4fea17a
Show file tree
Hide file tree
Showing 9 changed files with 375 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/terraform-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
generate-terraform-docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/checkout@v4
- name: configure terraform-docs

run: |
curl -sSLo ./terraform-docs.tar.gz https://terraform-docs.io/dl/v0.18.0/terraform-docs-v0.18.0-$(uname)-amd64.tar.gz
tar -xzf terraform-docs.tar.gz
Expand Down
2 changes: 1 addition & 1 deletion storage-account/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ variable "resource_group_name" {
variable "location" {
type = string
description = "Azure storage account location"
default = "centralindia"
default = ""
}

variable "storage_account_name" {
Expand Down
20 changes: 20 additions & 0 deletions vmss-linux/cloudinit.conf
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
9 changes: 9 additions & 0 deletions vmss-linux/data.tf
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"
}
42 changes: 42 additions & 0 deletions vmss-linux/load_balancer.tf
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
}
50 changes: 50 additions & 0 deletions vmss-linux/outputs.tf
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"
}
16 changes: 16 additions & 0 deletions vmss-linux/providers.tf
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 {}
}
158 changes: 158 additions & 0 deletions vmss-linux/variables.tf
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."
}
}

Loading

0 comments on commit 4fea17a

Please sign in to comment.