From 82db27147e5de775f8265194c6054fdd3b746a5c Mon Sep 17 00:00:00 2001 From: Yona Date: Mon, 20 Apr 2026 14:14:56 +0200 Subject: [PATCH] first commit --- README.md | 7 ++++ ai.tf | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ main.tf | 12 ++++++ 3 files changed, 141 insertions(+) create mode 100644 README.md create mode 100644 ai.tf create mode 100644 main.tf diff --git a/README.md b/README.md new file mode 100644 index 0000000..97f4a57 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +1. Install Azure CLI https://learn.microsoft.com/en-us/cli/azure/install-azure-cli +2. Install Terraform https://developer.hashicorp.com/terraform +3. Make sure Azure CLI and Terraform can be accessed via PATH +4. Execute "az login" and login to your Azure account. +5. Adjust the files to your liking. +6. Try out the different commands: terraform init, plan, apply, destroy + diff --git a/ai.tf b/ai.tf new file mode 100644 index 0000000..b3999a8 --- /dev/null +++ b/ai.tf @@ -0,0 +1,122 @@ +resource "azurerm_resource_group" "res-0" { + location = "switzerlandnorth" + managed_by = "terraform-demo" + name = "rg-terraform-demo" + tags = { + Project = "b1clc-demo" + } +} + +resource "azurerm_virtual_network" "res-9" { + address_space = ["10.0.0.0/16"] + location = azurerm_resource_group.res-0.location + name = "vm-demo-linux1-vnet" + resource_group_name = azurerm_resource_group.res-0.name + tags = { + Project = "b1clc-demo" + } +} + + +resource "azurerm_subnet" "res-10" { + address_prefixes = ["10.0.0.0/24"] + name = "default" + resource_group_name = azurerm_resource_group.res-0.name + virtual_network_name = azurerm_virtual_network.res-9.name +} + + + +resource "azurerm_public_ip" "res-8" { + allocation_method = "Static" + ip_version = "IPv4" + location = azurerm_resource_group.res-0.location + name = "vm-demo-linux1-ip" + resource_group_name = azurerm_resource_group.res-0.name + sku = "Standard" + sku_tier = "Regional" + tags = { + Project = "b1clc-demo" + } + # Removed zones for Standard SKU compatibility +} + +resource "azurerm_network_security_group" "res-5" { + location = azurerm_resource_group.res-0.location + name = "vm-demo-linux1-nsg" + resource_group_name = azurerm_resource_group.res-0.name + security_rule { + access = "Allow" + destination_address_prefix = "*" + destination_port_range = "22" + direction = "Inbound" + name = "SSH" + priority = 300 + protocol = "Tcp" + source_address_prefix = "*" + source_port_range = "*" + } + security_rule { + access = "Allow" + destination_address_prefix = "*" + destination_port_range = "80" + direction = "Inbound" + name = "HTTP" + priority = 320 + protocol = "Tcp" + source_address_prefix = "*" + source_port_range = "*" + } + tags = { + Project = "b1clc-demo" + } +} + +resource "azurerm_network_interface" "res-3" { + location = azurerm_resource_group.res-0.location + name = "vm-demo-linux1823_z1" + resource_group_name = azurerm_resource_group.res-0.name + tags = { + Project = "b1clc-demo" + } + ip_configuration { + name = "ipconfig1" + primary = true + private_ip_address_version = "IPv4" + public_ip_address_id = azurerm_public_ip.res-8.id + subnet_id = azurerm_subnet.res-10.id + private_ip_address_allocation = "Dynamic" + } +} + +resource "azurerm_network_interface_security_group_association" "res-4" { + network_interface_id = azurerm_network_interface.res-3.id + network_security_group_id = azurerm_network_security_group.res-5.id +} + +resource "azurerm_linux_virtual_machine" "res-1" { + disable_password_authentication = false + admin_password = "test..123" + admin_username = "student" + computer_name = "vm-demo-linux1" + location = azurerm_resource_group.res-0.location + name = "vm-demo-linux1" + network_interface_ids = [azurerm_network_interface.res-3.id] + resource_group_name = azurerm_resource_group.res-0.name + size = "Standard_B2ats_v2" + zone = "1" + os_disk { + caching = "ReadWrite" + storage_account_type = "StandardSSD_LRS" + disk_size_gb = 30 + } + source_image_reference { + offer = "ubuntu-24_04-lts" + publisher = "canonical" + sku = "server" + version = "latest" + } + tags = { + Project = "b1clc-demo" + } +} diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..e7d6ecf --- /dev/null +++ b/main.tf @@ -0,0 +1,12 @@ +terraform { + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "4.64.0" + } + } +} +provider "azurerm" { + # Configuration options + features {} +} \ No newline at end of file