-
Notifications
You must be signed in to change notification settings - Fork 70
Solution #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Solution #73
Changes from all commits
584b15c
e9aff0f
b056945
e8ad2ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| .terraform/ | ||
| *.tfstate | ||
| *.tfstate.* | ||
| .terraform.tfstate.lock.info | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The task requires |
||
| crash.log | ||
| crash.*.log | ||
| *.tfplan | ||
| override.tf | ||
| override.tf.json | ||
| *_override.tf | ||
| *_override.tf.json | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| terraform { | ||
| backend "azurerm" { | ||
| resource_group_name = "mate-azure-task-12" | ||
| storage_account_name = "yourstorageaccount" | ||
| container_name = "tfstate" | ||
| key = "terraform.tfstate" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| terraform { | ||
| required_providers { | ||
|
Comment on lines
+1
to
+2
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIC naming via |
||
| azurerm = { | ||
| source = "hashicorp/azurerm" | ||
| version = "~> 4.0" | ||
| } | ||
| random = { | ||
| source = "hashicorp/random" | ||
| version = "~> 3.0" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| provider "azurerm" { | ||
| features {} | ||
| } | ||
|
|
||
| resource "azurerm_resource_group" "main" { | ||
| name = var.resource_group_name | ||
| location = var.location | ||
| } | ||
|
|
||
| module "network" { | ||
| source = "./modules/network" | ||
|
|
||
| resource_group_name = azurerm_resource_group.main.name | ||
| location = azurerm_resource_group.main.location | ||
| virtual_network_name = var.virtual_network_name | ||
| vnet_address_prefix = var.vnet_address_prefix | ||
| subnet_name = var.subnet_name | ||
| subnet_address_prefix = var.subnet_address_prefix | ||
| network_security_group_name = var.network_security_group_name | ||
| public_ip_address_name = var.public_ip_address_name | ||
| dns_label = var.dns_label | ||
| } | ||
|
Comment on lines
+32
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The VM is using Ubuntu 22.04 via Jammy LTS image, which is correct in practice, but the checklist calls for image |
||
|
|
||
| module "storage" { | ||
| source = "./modules/storage" | ||
|
|
||
| resource_group_name = azurerm_resource_group.main.name | ||
| location = azurerm_resource_group.main.location | ||
| storage_account_name = var.storage_account_name | ||
| } | ||
|
|
||
| module "compute" { | ||
| source = "./modules/compute" | ||
|
|
||
| resource_group_name = azurerm_resource_group.main.name | ||
| location = azurerm_resource_group.main.location | ||
|
Comment on lines
+40
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| vm_name = var.vm_name | ||
| vm_size = var.vm_size | ||
| admin_username = var.admin_username | ||
| ssh_key_public = var.ssh_key_public | ||
| install_script_url = var.install_script_url | ||
|
|
||
| subnet_id = module.network.subnet_id | ||
| public_ip_id = module.network.public_ip_id | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| resource "azurerm_network_interface" "nic" { | ||
| name = "${var.vm_name}-nic" | ||
| location = var.location | ||
| resource_group_name = var.resource_group_name | ||
|
|
||
| ip_configuration { | ||
| name = "internal" | ||
| subnet_id = var.subnet_id | ||
| private_ip_address_allocation = "Dynamic" | ||
| public_ip_address_id = var.public_ip_id | ||
| } | ||
| } | ||
|
|
||
| resource "azurerm_linux_virtual_machine" "vm" { | ||
| name = var.vm_name | ||
| resource_group_name = var.resource_group_name | ||
| location = var.location | ||
| size = var.vm_size | ||
| admin_username = var.admin_username | ||
| network_interface_ids = [azurerm_network_interface.nic.id] | ||
|
|
||
| admin_ssh_key { | ||
| username = var.admin_username | ||
| public_key = var.ssh_key_public | ||
| } | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The task description and checklist refer to a variable |
||
| os_disk { | ||
| caching = "ReadWrite" | ||
| storage_account_type = "Standard_LRS" | ||
| } | ||
|
|
||
| source_image_reference { | ||
| publisher = "Canonical" | ||
| offer = "0001-com-ubuntu-server-jammy" | ||
| sku = "22_04-lts" | ||
| version = "latest" | ||
| } | ||
| } | ||
|
|
||
| resource "azurerm_virtual_machine_extension" "app" { | ||
| name = "install-app" | ||
| virtual_machine_id = azurerm_linux_virtual_machine.vm.id | ||
| publisher = "Microsoft.Azure.Extensions" | ||
| type = "CustomScript" | ||
| type_handler_version = "2.1" | ||
|
|
||
| settings = jsonencode({ | ||
| fileUris = [var.install_script_url] | ||
| commandToExecute = "bash install-app.sh" | ||
|
Comment on lines
+40
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| }) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| output "vm_name" { | ||
| description = "Name of the virtual machine" | ||
| value = azurerm_linux_virtual_machine.vm.name | ||
| } | ||
|
|
||
| output "vm_id" { | ||
| description = "Resource ID of the virtual machine" | ||
| value = azurerm_linux_virtual_machine.vm.id | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| variable "resource_group_name" { | ||
| description = "Name of the resource group for the compute resources" | ||
| type = string | ||
| } | ||
|
|
||
| variable "location" { | ||
| description = "Azure region" | ||
| type = string | ||
| } | ||
|
|
||
| variable "vm_name" { | ||
| description = "Name of the virtual machine" | ||
| type = string | ||
| } | ||
|
|
||
| variable "vm_size" { | ||
| description = "Size of the virtual machine" | ||
| type = string | ||
| } | ||
|
|
||
| variable "admin_username" { | ||
| description = "Admin username for the virtual machine" | ||
| type = string | ||
| } | ||
|
|
||
| variable "ssh_key_public" { | ||
| description = "SSH public key used for VM authentication" | ||
| type = string | ||
| } | ||
|
|
||
| variable "subnet_id" { | ||
| description = "ID of the subnet the network interface attaches to" | ||
| type = string | ||
| } | ||
|
|
||
|
Comment on lines
+32
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The VM image is clearly Ubuntu 22.04 (Jammy), but the checklist specifies |
||
| variable "public_ip_id" { | ||
| description = "ID of the public IP attached to the network interface" | ||
| type = string | ||
| } | ||
|
|
||
| variable "install_script_url" { | ||
| description = "Raw GitHub URL of install-app.sh for the VM extension" | ||
| type = string | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| resource "azurerm_virtual_network" "vnet" { | ||
| name = var.virtual_network_name | ||
| address_space = [var.vnet_address_prefix] | ||
| location = var.location | ||
| resource_group_name = var.resource_group_name | ||
| } | ||
|
|
||
| resource "azurerm_subnet" "subnet" { | ||
| name = var.subnet_name | ||
| resource_group_name = var.resource_group_name | ||
| virtual_network_name = azurerm_virtual_network.vnet.name | ||
| address_prefixes = [var.subnet_address_prefix] | ||
| } | ||
|
|
||
| resource "azurerm_network_security_group" "nsg" { | ||
| name = var.network_security_group_name | ||
| location = var.location | ||
| resource_group_name = var.resource_group_name | ||
|
|
||
| security_rule { | ||
| name = "AllowSSH" | ||
| priority = 1001 | ||
| direction = "Inbound" | ||
| access = "Allow" | ||
| protocol = "Tcp" | ||
| source_port_range = "*" | ||
| destination_port_range = "22" | ||
| source_address_prefix = "*" | ||
| destination_address_prefix = "*" | ||
| } | ||
|
|
||
| security_rule { | ||
| name = "AllowAppHttp" | ||
| priority = 1002 | ||
| direction = "Inbound" | ||
| access = "Allow" | ||
| protocol = "Tcp" | ||
| source_port_range = "*" | ||
| destination_port_range = "8080" | ||
| source_address_prefix = "*" | ||
| destination_address_prefix = "*" | ||
| } | ||
| } | ||
|
|
||
| resource "azurerm_subnet_network_security_group_association" "subnet_nsg" { | ||
| subnet_id = azurerm_subnet.subnet.id | ||
| network_security_group_id = azurerm_network_security_group.nsg.id | ||
| } | ||
|
|
||
| resource "random_integer" "dns" { | ||
| min = 1000 | ||
| max = 9999 | ||
| } | ||
|
|
||
| resource "azurerm_public_ip" "pip" { | ||
| name = var.public_ip_address_name | ||
| location = var.location | ||
| resource_group_name = var.resource_group_name | ||
| allocation_method = "Dynamic" | ||
| domain_name_label = "${var.dns_label}${random_integer.dns.result}" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| output "subnet_id" { | ||
| description = "ID of the subnet (used by the network interface in the compute module)" | ||
| value = azurerm_subnet.subnet.id | ||
| } | ||
|
|
||
| output "public_ip_id" { | ||
| description = "ID of the public IP (attached to the network interface in the compute module)" | ||
| value = azurerm_public_ip.pip.id | ||
| } | ||
|
|
||
| output "public_ip_fqdn" { | ||
| description = "Full DNS name of the public IP (used to open the app in a browser)" | ||
| value = azurerm_public_ip.pip.fqdn | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| variable "resource_group_name" { | ||
| description = "Name of the resource group for the network resources" | ||
| type = string | ||
| } | ||
|
|
||
| variable "location" { | ||
| description = "Azure region (e.g. westeurope)" | ||
| type = string | ||
| } | ||
|
|
||
| variable "virtual_network_name" { | ||
| description = "Name of the virtual network" | ||
| type = string | ||
| } | ||
|
|
||
| variable "vnet_address_prefix" { | ||
| description = "Address space of the virtual network in CIDR format (e.g. 10.0.0.0/16)" | ||
| type = string | ||
| } | ||
|
|
||
| variable "subnet_name" { | ||
| description = "Name of the subnet" | ||
| type = string | ||
| } | ||
|
|
||
| variable "subnet_address_prefix" { | ||
| description = "Address range of the subnet in CIDR format (e.g. 10.0.0.0/24)" | ||
| type = string | ||
| } | ||
|
|
||
| variable "network_security_group_name" { | ||
| description = "Name of the network security group (NSG)" | ||
| type = string | ||
| } | ||
|
|
||
| variable "public_ip_address_name" { | ||
| description = "Name of the public IP resource" | ||
| type = string | ||
| } | ||
|
|
||
| variable "dns_label" { | ||
| description = "DNS label prefix for the public IP (a random number is appended)" | ||
| type = string | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| resource "random_string" "storage" { | ||
| length = 6 | ||
| upper = false | ||
| special = false | ||
| } | ||
|
|
||
| resource "azurerm_storage_account" "storage" { | ||
| name = "${var.storage_account_name}${random_string.storage.result}" | ||
| resource_group_name = var.resource_group_name | ||
| location = var.location | ||
| account_tier = "Standard" | ||
| account_replication_type = "LRS" | ||
| } | ||
|
|
||
| resource "azurerm_storage_container" "container" { | ||
| name = "task-artifacts" | ||
| storage_account_id = azurerm_storage_account.storage.id | ||
| container_access_type = "private" | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Backend config must match checklist item #9: use
mate-azure-task-12asresource_group_nameandyourstorageaccountasstorage_account_name, with containertfstateand keyterraform.tfstate. The current values (tfstate-rg,tfstate2426127369) do not comply.