Skip to content

Commit

Permalink
solved
Browse files Browse the repository at this point in the history
  • Loading branch information
NikitaLafinskiy committed Dec 24, 2024
1 parent 01dbb3f commit 9a56b40
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 0 deletions.
32 changes: 32 additions & 0 deletions locals.tf
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"
}
]
}
32 changes: 32 additions & 0 deletions network.tf
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"
}
]
}
11 changes: 11 additions & 0 deletions outputs.tf
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]
}
12 changes: 12 additions & 0 deletions provider.tf
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 {}
}
4 changes: 4 additions & 0 deletions resource_group.tf
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"
}
Binary file added tfplan
Binary file not shown.
7 changes: 7 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
variable "prefix" {
default = "tfvmex"
}

variable "vm_count" {
default = 3
}
35 changes: 35 additions & 0 deletions vm.tf
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
}
}

0 comments on commit 9a56b40

Please sign in to comment.