-
Notifications
You must be signed in to change notification settings - Fork 70
Solution #72
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 #72
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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" { | ||
| storage_account_name = "yourstorageaccount" | ||
| container_name = "tfstate" | ||
| key = "terraform.tfstate" | ||
| resource_group_name = "mate-azure-task-12" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| terraform { | ||
| required_providers { | ||
| azurerm = { | ||
| source = "hashicorp/azurerm" | ||
| version = "4.79.0" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| provider "azurerm" { | ||
| features {} | ||
| } | ||
|
|
||
| resource "azurerm_resource_group" "main" { | ||
| name = var.resource_group_name | ||
| location = var.location | ||
| } | ||
|
|
||
| module "network" { | ||
| source = "./modules/network" | ||
|
|
||
| location = var.location | ||
| resource_group_name = azurerm_resource_group.main.name | ||
| 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 | ||
| } | ||
|
|
||
| module "storage" { | ||
| source = "./modules/storage" | ||
|
|
||
| location = var.location | ||
| resource_group_name = azurerm_resource_group.main.name | ||
| } | ||
|
|
||
| module "compute" { | ||
| source = "./modules/compute" | ||
|
|
||
| location = var.location | ||
| resource_group_name = azurerm_resource_group.main.name | ||
| vm_name = var.vm_name | ||
| vm_size = var.vm_size | ||
| subnet_id = module.network.subnet_id | ||
| public_ip_id = module.network.public_address_ip_id | ||
| ssh_key_public = var.ssh_key_public | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| resource "azurerm_network_interface" "main" { | ||
| 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" "main" { | ||
| name = var.vm_name | ||
| resource_group_name = var.resource_group_name | ||
| location = var.location | ||
| size = var.vm_size | ||
| admin_username = "adminuser" | ||
| network_interface_ids = [ | ||
| azurerm_network_interface.main.id, | ||
| ] | ||
|
|
||
| admin_ssh_key { | ||
| username = "adminuser" | ||
| public_key = var.ssh_key_public | ||
| } | ||
|
|
||
| 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" | ||
|
Comment on lines
+34
to
+38
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. This VM configuration correctly uses |
||
| } | ||
| } | ||
|
|
||
| resource "azurerm_virtual_machine_extension" "main" { | ||
| name = "install-extension" | ||
| virtual_machine_id = azurerm_linux_virtual_machine.main.id | ||
| publisher = "Microsoft.Azure.Extensions" | ||
| type = "CustomScript" | ||
| type_handler_version = "2.0" | ||
|
|
||
| protected_settings = jsonencode({ | ||
| "script" = base64encode(file("${path.root}/install-app.sh")) | ||
| }) | ||
|
Comment on lines
+42
to
+51
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. Using the |
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| output "network_interface_id" { | ||
| value = azurerm_network_interface.main.id | ||
| } | ||
|
|
||
| output "virtual_machine_id" { | ||
| value = azurerm_linux_virtual_machine.main.id | ||
| } | ||
|
|
||
| output "virtual_machine_extension_id" { | ||
| value = azurerm_virtual_machine_extension.main.id | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| variable "location" { | ||
| type = string | ||
| description = "The location of VM" | ||
| } | ||
|
|
||
| variable "resource_group_name" { | ||
| type = string | ||
| description = "The name of the resource group" | ||
| } | ||
|
|
||
| variable "vm_name" { | ||
| type = string | ||
| description = "The name of the VM" | ||
| } | ||
|
|
||
| variable "vm_size" { | ||
| type = string | ||
| description = "The size of the VM" | ||
| } | ||
|
|
||
| variable "ssh_key_public" { | ||
| type = string | ||
| description = "The content of the public ssh key" | ||
| } | ||
|
|
||
| variable "subnet_id" { | ||
| type = string | ||
| description = "The id of the subnet" | ||
| } | ||
|
|
||
| variable "public_ip_id" { | ||
| type = string | ||
| description = "The id of the public ip" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| resource "azurerm_network_security_group" "main" { | ||
| name = var.network_security_group_name | ||
| location = var.location | ||
| resource_group_name = var.resource_group_name | ||
|
|
||
| security_rule { | ||
| name = "AllowSSH" | ||
| priority = 100 | ||
| direction = "Inbound" | ||
| access = "Allow" | ||
| protocol = "Tcp" | ||
| source_port_range = "*" | ||
| destination_port_range = "22" | ||
| source_address_prefix = "*" | ||
| destination_address_prefix = "*" | ||
| } | ||
|
|
||
| security_rule { | ||
| name = "AllowHTTP" | ||
| priority = 110 | ||
| direction = "Inbound" | ||
| access = "Allow" | ||
| protocol = "Tcp" | ||
| source_port_range = "*" | ||
| destination_port_range = "80" | ||
| source_address_prefix = "*" | ||
| destination_address_prefix = "*" | ||
| } | ||
|
|
||
| security_rule { | ||
| name = "AllowApp8080" | ||
| priority = 120 | ||
| direction = "Inbound" | ||
| access = "Allow" | ||
| protocol = "Tcp" | ||
| source_port_range = "*" | ||
| destination_port_range = "8080" | ||
| source_address_prefix = "*" | ||
| destination_address_prefix = "*" | ||
| } | ||
| } | ||
|
|
||
| resource "azurerm_virtual_network" "main" { | ||
| name = var.virtual_network_name | ||
| location = var.location | ||
| resource_group_name = var.resource_group_name | ||
| address_space = [var.vnet_address_prefix] | ||
| } | ||
|
|
||
| resource "azurerm_subnet" "main" { | ||
| name = var.subnet_name | ||
| resource_group_name = var.resource_group_name | ||
| address_prefixes = [var.subnet_address_prefix] | ||
| virtual_network_name = azurerm_virtual_network.main.name | ||
| } | ||
|
|
||
| resource "random_integer" "dns-suffix" { | ||
| min = 1 | ||
| max = 100 | ||
| } | ||
|
|
||
| resource "azurerm_public_ip" "main" { | ||
| name = var.public_ip_address_name | ||
| resource_group_name = var.resource_group_name | ||
| location = var.location | ||
| allocation_method = "Dynamic" | ||
| domain_name_label = "${var.dns_label}-${random_integer.dns-suffix.result}" | ||
| } | ||
|
|
||
| resource "azurerm_subnet_network_security_group_association" "main" { | ||
| subnet_id = azurerm_subnet.main.id | ||
| network_security_group_id = azurerm_network_security_group.main.id | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| output "virtual_network_id" { | ||
| value = azurerm_virtual_network.main.id | ||
| } | ||
|
|
||
| output "virtual_network_security_id" { | ||
| value = azurerm_network_security_group.main.id | ||
| } | ||
|
|
||
| output "public_address_ip_id" { | ||
| value = azurerm_public_ip.main.id | ||
| } | ||
|
|
||
| output "subnet_id" { | ||
| value = azurerm_subnet.main.id | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| variable "location" { | ||
| type = string | ||
| description = "The location of VM" | ||
| } | ||
|
|
||
| variable "resource_group_name" { | ||
| type = string | ||
| description = "The name of the resource group" | ||
| } | ||
|
|
||
| variable "virtual_network_name" { | ||
| type = string | ||
| description = "The name of the virtual network" | ||
| } | ||
|
|
||
| variable "vnet_address_prefix" { | ||
| type = string | ||
| description = "The vnet address prefix" | ||
| } | ||
|
|
||
| variable "subnet_name" { | ||
| type = string | ||
| description = "The name of the subnet" | ||
| } | ||
|
|
||
| variable "subnet_address_prefix" { | ||
| type = string | ||
| description = "The subnet address prefix" | ||
| } | ||
|
|
||
| variable "network_security_group_name" { | ||
| type = string | ||
| description = "The name of the network security group" | ||
| } | ||
|
|
||
| variable "public_ip_address_name" { | ||
| type = string | ||
| description = "The name of the public ip address" | ||
| } | ||
|
|
||
| variable "dns_label" { | ||
| type = string | ||
| description = "The dns label" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| resource "azurerm_storage_account" "main" { | ||
| name = "nichelangeloost" | ||
| resource_group_name = var.resource_group_name | ||
| location = var.location | ||
| account_tier = "Standard" | ||
| account_replication_type = "LRS" | ||
| } | ||
|
|
||
| resource "azurerm_storage_container" "main" { | ||
| name = "task-artifacts" | ||
| storage_account_id = azurerm_storage_account.main.id | ||
| container_access_type = "private" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| output "storage_account_id" { | ||
| value = azurerm_storage_account.main.id | ||
| } | ||
|
|
||
| output "storage_container_id" { | ||
| value = azurerm_storage_container.main.id | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| variable "location" { | ||
| type = string | ||
| description = "The location of VM" | ||
|
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. This backend block is functionally valid, but checklist item #36 requires |
||
| } | ||
|
|
||
| variable "resource_group_name" { | ||
| type = string | ||
| description = "The name of the resource group" | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| output "resource_group_id" { | ||
| value = azurerm_resource_group.main.id | ||
| } | ||
|
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. This backend block works technically, but checklist item #36 requires |
||
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.
The backend configuration must match checklist item #36:
storage_account_nameis required to be"yourstorageaccount", but here it is set to a different value. Update this to the specified name and ensure the corresponding storage account exists.