-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
01dbb3f
commit 9a56b40
Showing
8 changed files
with
133 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
locals { | ||
network_interface_names = ["nic1", "nic2", "nic3"] | ||
security_rules = [ | ||
{ | ||
name = "allow-ssh" | ||
priority = 100 | ||
direction = "Inbound" | ||
access = "Allow" | ||
protocol = "Tcp" | ||
source_port_range = "*" | ||
destination_port_range = "22" | ||
}, | ||
{ | ||
name = "allow-http" | ||
priority = 200 | ||
direction = "Inbound" | ||
access = "Allow" | ||
protocol = "Tcp" | ||
source_port_range = "*" | ||
destination_port_range = "80" | ||
}, | ||
{ | ||
name = "allow-https" | ||
priority = 300 | ||
direction = "Inbound" | ||
access = "Allow" | ||
protocol = "Tcp" | ||
source_port_range = "*" | ||
destination_port_range = "443" | ||
} | ||
] | ||
} |
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,32 @@ | ||
locals { | ||
network_interface_names = ["nic1", "nic2", "nic3"] | ||
security_rules = [ | ||
{ | ||
name = "allow-ssh" | ||
priority = 100 | ||
direction = "Inbound" | ||
access = "Allow" | ||
protocol = "Tcp" | ||
source_port_range = "*" | ||
destination_port_range = "22" | ||
}, | ||
{ | ||
name = "allow-http" | ||
priority = 200 | ||
direction = "Inbound" | ||
access = "Allow" | ||
protocol = "Tcp" | ||
source_port_range = "*" | ||
destination_port_range = "80" | ||
}, | ||
{ | ||
name = "allow-https" | ||
priority = 300 | ||
direction = "Inbound" | ||
access = "Allow" | ||
protocol = "Tcp" | ||
source_port_range = "*" | ||
destination_port_range = "443" | ||
} | ||
] | ||
} |
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,11 @@ | ||
output "vm_names_uppercase" { | ||
value = [for vm in azurerm_virtual_machine.vm : upper(vm.name)] | ||
} | ||
|
||
output "joined_tags" { | ||
value = join(", ", [for vm in azurerm_virtual_machine.vm : join(", ", [for key, value in vm.tags : "${key}=${value}"])]) | ||
} | ||
|
||
output "vm_ids" { | ||
value = [for vm in azurerm_virtual_machine.vm : vm.id] | ||
} |
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,12 @@ | ||
terraform { | ||
required_providers { | ||
azurerm = { | ||
source = "hashicorp/azurerm" | ||
version = "3.105.0" | ||
} | ||
} | ||
} | ||
|
||
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,4 @@ | ||
resource "azurerm_resource_group" "example" { | ||
name = "${var.prefix}-resources" | ||
location = "West Europe" | ||
} |
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,7 @@ | ||
variable "prefix" { | ||
default = "tfvmex" | ||
} | ||
|
||
variable "vm_count" { | ||
default = 3 | ||
} |
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,35 @@ | ||
resource "azurerm_virtual_machine" "vm" { | ||
count = var.vm_count | ||
name = "${var.prefix}-vm-${count.index}" | ||
location = azurerm_resource_group.example.location | ||
resource_group_name = azurerm_resource_group.example.name | ||
network_interface_ids = [azurerm_network_interface.main["nic${count.index + 1}"].id] | ||
vm_size = "Standard_DS1_v2" | ||
|
||
storage_image_reference { | ||
publisher = "Canonical" | ||
offer = "0001-com-ubuntu-server-jammy" | ||
sku = "22_04-lts" | ||
version = "latest" | ||
} | ||
storage_os_disk { | ||
name = "myosdisk-${count.index}" | ||
caching = "ReadWrite" | ||
create_option = "FromImage" | ||
managed_disk_type = "Standard_LRS" | ||
} | ||
os_profile { | ||
computer_name = "hostname-${count.index}" | ||
admin_username = "testadmin" | ||
admin_password = "Password1234!" | ||
} | ||
os_profile_linux_config { | ||
disable_password_authentication = false | ||
} | ||
tags = { | ||
environment = "staging" | ||
} | ||
lifecycle { | ||
prevent_destroy = true | ||
} | ||
} |