Skip to content

Commit 4fea17a

Browse files
Merge pull request #8 from devwithkrishna/feature/vmss-linux
Feature/vmss linux
2 parents ce3823b + 764de7d commit 4fea17a

File tree

9 files changed

+375
-3
lines changed

9 files changed

+375
-3
lines changed

.github/workflows/terraform-docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ jobs:
1414
generate-terraform-docs:
1515
runs-on: ubuntu-latest
1616
steps:
17-
- uses: actions/checkout@v4
18-
17+
- uses: actions/checkout@v4
1918
- name: configure terraform-docs
19+
2020
run: |
2121
curl -sSLo ./terraform-docs.tar.gz https://terraform-docs.io/dl/v0.18.0/terraform-docs-v0.18.0-$(uname)-amd64.tar.gz
2222
tar -xzf terraform-docs.tar.gz

storage-account/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ variable "resource_group_name" {
66
variable "location" {
77
type = string
88
description = "Azure storage account location"
9-
default = "centralindia"
9+
default = ""
1010
}
1111

1212
variable "storage_account_name" {

vmss-linux/cloudinit.conf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#cloud-config
2+
package_update: true
3+
packages:
4+
- unzip
5+
- git
6+
- wget
7+
- apt-transport-https
8+
- software-properties-common
9+
- azure-cli
10+
- terraform
11+
- ca-certificates
12+
- curl
13+
- gnupg
14+
- lsb-release
15+
runcmd:
16+
- sudo apt-get update
17+
- sudo apt install nginx -y
18+
- sudo curl -fsSL https://get.docker.com -o get-docker.sh
19+
- sudo sh ./get-docker.sh
20+
- docker --info

vmss-linux/data.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
data "azurerm_subnet" "subnet" {
2+
name = var.subnet_name
3+
resource_group_name = var.vnet_resource_group
4+
virtual_network_name = var.vnet_name
5+
}
6+
7+
data "local_file" "cloudinit" {
8+
filename = "${path.module}/cloudinit.conf"
9+
}

vmss-linux/load_balancer.tf

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
resource "azurerm_public_ip" "lb_pub_ip" {
2+
name = "${var.vmss_name}-publicip"
3+
location = azurerm_resource_group.rg.location
4+
resource_group_name = azurerm_resource_group.rg.name
5+
allocation_method = "Static"
6+
}
7+
8+
resource "azurerm_lb" "lb" {
9+
name = "${var.vmss_name}-lb"
10+
location = azurerm_resource_group.rg.location
11+
resource_group_name = azurerm_resource_group.rg.name
12+
sku = var.load_balancer_sku
13+
14+
frontend_ip_configuration {
15+
name = "${var.vmss_name}-frontend-ip"
16+
public_ip_address_id = azurerm_public_ip.lb_pub_ip.id
17+
}
18+
}
19+
20+
resource "azurerm_lb_backend_address_pool" "backend_address_pool" {
21+
loadbalancer_id = azurerm_lb.lb.id
22+
name = "${var.vmss_name}-lb-backendaddresspool"
23+
24+
}
25+
26+
resource "azurerm_lb_rule" "lb_rule" {
27+
loadbalancer_id = azurerm_lb.lb.id
28+
name = "port-${var.frontend_port}"
29+
protocol = "Tcp"
30+
frontend_port = var.frontend_port
31+
backend_port = var.backend_port
32+
frontend_ip_configuration_name = "${var.vmss_name}-frontend-ip"
33+
backend_address_pool_ids = ["${azurerm_lb_backend_address_pool.backend_address_pool.id}"]
34+
}
35+
36+
resource "azurerm_lb_probe" "health" {
37+
loadbalancer_id = azurerm_lb.lb.id
38+
name = "${var.vmss_name}-health-check"
39+
port = var.frontend_port
40+
protocol = var.protocol
41+
request_path = var.request_path
42+
}

vmss-linux/outputs.tf

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
output "subnet_id" {
2+
value = data.azurerm_subnet.subnet.id
3+
description = "Azure Subnet id"
4+
}
5+
6+
output "azure_vmss_name" {
7+
value = azurerm_linux_virtual_machine_scale_set.vmss.name
8+
description = "Azure VMSS name"
9+
}
10+
11+
output "azure_vmss_rg" {
12+
value = azurerm_resource_group.rg.name
13+
description = "Azure VMSS Rg"
14+
}
15+
16+
output "type_of_instances" {
17+
value = azurerm_linux_virtual_machine_scale_set.vmss.priority
18+
description = "Spot or Regular instances"
19+
}
20+
21+
output "data_disks" {
22+
value = azurerm_linux_virtual_machine_scale_set.vmss.data_disk
23+
description = "VMSS data disks"
24+
}
25+
26+
output "os_disk" {
27+
value = azurerm_linux_virtual_machine_scale_set.vmss.os_disk[0].disk_size_gb
28+
description = "VMSS os disk size"
29+
}
30+
31+
output "admin_username" {
32+
value = var.admin_username
33+
description = "VMSS user name"
34+
}
35+
36+
output "admin_password" {
37+
value = random_password.password.result
38+
sensitive = false
39+
description = "VMSS user password"
40+
}
41+
42+
output "loadbalancer_id" {
43+
value = azurerm_lb.lb.id
44+
description = "AzureLoad balancer Id"
45+
}
46+
47+
output "load_balancer_frontend_public_ip" {
48+
value = azurerm_public_ip.lb_pub_ip.ip_address
49+
description = "Azure load balancer frontend ip address"
50+
}

vmss-linux/providers.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
terraform {
2+
required_version = "~> 1.3"
3+
required_providers {
4+
azurerm = {
5+
source = "hashicorp/azurerm"
6+
version = "~> 3.0"
7+
}
8+
random = {
9+
source = "hashicorp/random"
10+
version = ">= 3.1"
11+
}
12+
}
13+
}
14+
provider "azurerm" {
15+
features {}
16+
}

vmss-linux/variables.tf

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
variable "resource_group_name" {
2+
default = ""
3+
description = "Azure VMSS resource group name"
4+
type = string
5+
}
6+
7+
variable "vmss_name" {
8+
default = ""
9+
description = "Azure VMSS name"
10+
type = string
11+
}
12+
13+
variable "location" {
14+
default = ""
15+
description = "Azure location"
16+
type = string
17+
}
18+
19+
variable "sku_size" {
20+
default = ""
21+
description = "Azure VMSS sku"
22+
type = string
23+
}
24+
25+
variable "default_instance_count" {
26+
default = 0
27+
description = "Default instance count for the VMSS"
28+
type = number
29+
}
30+
31+
variable "admin_username" {
32+
default = "admin_user"
33+
description = "VMSS default user name"
34+
type = string
35+
}
36+
37+
38+
variable "subnet_name" {
39+
default = ""
40+
description = "Azure subnet name to create vmss"
41+
type = string
42+
}
43+
44+
variable "vnet_name" {
45+
default = ""
46+
description = "Azure Vnet Name"
47+
type = string
48+
}
49+
50+
variable "vnet_resource_group" {
51+
default = ""
52+
description = "Azure Vnet resource group"
53+
type = string
54+
}
55+
56+
57+
variable "os_disk_storage_account_type" {
58+
default = "Standard_LRS"
59+
description = "OS disk storage account type"
60+
type = string
61+
validation {
62+
condition = contains(["Standard_LRS", "StandardSSD_LRS", "StandardSSD_ZRS", "Premium_LRS", "Premium_ZRS"], var.os_disk_storage_account_type)
63+
error_message = "OS disk storage account type must be one among Standard_LRS,StandardSSD_LRS,StandardSSD_ZRS,Premium_LRS,Premium_ZRS."
64+
}
65+
}
66+
67+
variable "os_disk_size" {
68+
default = 30
69+
description = "OS disk size in GB"
70+
type = number
71+
}
72+
73+
74+
variable "additional_data_disks" {
75+
description = "Adding additional disks capacity to add each instance in GB"
76+
type = list(number)
77+
default = []
78+
}
79+
80+
variable "additional_data_disks_storage_account_type" {
81+
description = "The Type of Storage Account which should back this Data Disk. Possible values include Standard_LRS, StandardSSD_LRS, Premium_LRS and UltraSSD_LRS."
82+
default = "Standard_LRS"
83+
type = string
84+
validation {
85+
condition = contains(["Standard_LRS", "StandardSSD_LRS", "StandardSSD_ZRS", "Premium_LRS", "Premium_ZRS"], var.additional_data_disks_storage_account_type)
86+
error_message = "Data disk storage account type must be one among Standard_LRS,StandardSSD_LRS,StandardSSD_ZRS,Premium_LRS,Premium_ZRS."
87+
}
88+
}
89+
90+
variable "application_name" {
91+
default = ""
92+
description = "Azure application name tag"
93+
type = string
94+
}
95+
96+
variable "environment" {
97+
default = ""
98+
description = "Environment tag value in Azure"
99+
type = string
100+
validation {
101+
condition = contains(["DEV", "QA", "UAT", "PROD"], var.environment)
102+
error_message = "Environment value should be one among DEV or QA or UAT or PROD."
103+
}
104+
}
105+
106+
variable "priority" {
107+
default = ""
108+
description = "Type of vmss instances Spot or regular"
109+
type = string
110+
validation {
111+
condition = contains(["Spot", "Regular"], var.priority)
112+
error_message = "Priority Should be either Regular or Spot."
113+
}
114+
}
115+
116+
variable "eviction_policy" {
117+
default = "Delete"
118+
description = "Azure Spot VM eviction policy Delete or Deallocate"
119+
type = string
120+
}
121+
122+
variable "load_balancer_sku" {
123+
default = "Basic"
124+
description = "Azure Loadbalancer Skus"
125+
type = string
126+
validation {
127+
condition = contains(["Basic", "Standard", "Gateway"], var.load_balancer_sku)
128+
error_message = "Load balancer SKU must be one among Basic , Standard or Gateway type."
129+
}
130+
}
131+
132+
variable "frontend_port" {
133+
default = 80
134+
type = number
135+
description = "Port on which queries for status of application"
136+
}
137+
138+
variable "backend_port" {
139+
default = 80
140+
type = number
141+
description = "Port on which traffic is passed on to application backends"
142+
}
143+
variable "request_path" {
144+
default = "/"
145+
type = string
146+
description = "Health check path"
147+
}
148+
149+
variable "protocol" {
150+
default = "Http"
151+
description = "Protocol for Load balancing"
152+
type = string
153+
validation {
154+
condition = contains(["Http", "Https", "Tcp"], var.protocol)
155+
error_message = "Protocol value should be one among Http, Https or Tcp."
156+
}
157+
}
158+

0 commit comments

Comments
 (0)