-
Notifications
You must be signed in to change notification settings - Fork 70
Develop #55
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?
Develop #55
Changes from all commits
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,17 @@ | ||
| .terraform/ | ||
|
|
||
| *.tfstate | ||
| *.tfstate.* | ||
|
|
||
| *.tfvars | ||
| *.tfvars.json | ||
|
|
||
| .terraformrc | ||
| terraform.rc | ||
|
|
||
| *.tfplan | ||
| *.log | ||
|
|
||
| .DS_Store | ||
|
|
||
| id_rsa* | ||
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,9 @@ | ||
| terraform { | ||
| backend "azurerm" { | ||
| resource_group_name = "mate-azure-task-12" | ||
| storage_account_name = "yourstorageaccount" | ||
|
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.
|
||
| container_name = "tfstate" | ||
| key = "terraform.tfstate" | ||
|
salabam marked this conversation as resolved.
|
||
| use_oidc = true | ||
|
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 |
|---|---|---|
|
|
@@ -9,11 +9,12 @@ | |
| # when running the script as VM extention. | ||
| apt-get update -yq | ||
| apt-get install python3-pip -yq | ||
| apt-get install -yq git | ||
|
salabam marked this conversation as resolved.
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 installs git but has no error handling here. Prefer combining package installs (e.g. |
||
|
|
||
| # Create a directory for the app and download the files. | ||
| mkdir /app | ||
| # Create a directory for the app and download the files. | ||
|
salabam marked this conversation as resolved.
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. Creating /app is fine, but the script does not check for errors. Add |
||
| mkdir -p /app | ||
|
salabam marked this conversation as resolved.
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.
|
||
| # make sure to uncomment the line bellow and update the link with your GitHub username | ||
| # git clone https://github.com/<your-gh-username>/azure_task_12_deploy_app_with_vm_extention.git | ||
| git clone https://github.com/salabam/devops_todolist_terraform_task.git | ||
|
salabam marked this conversation as resolved.
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 hard-coded git clone will break when the VM extension is expected to download a raw |
||
| cp -r devops_todolist_terraform_task/app/* /app | ||
|
|
||
| # create a service for the app via systemctl and start the app | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| terraform { | ||
| required_providers { | ||
| random = { | ||
| source = "hashicorp/random" | ||
| version = "~> 3.0" | ||
| } | ||
| azurerm = { | ||
| source = "hashicorp/azurerm" | ||
| version = "3.105.0" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| provider "azurerm" { | ||
| features {} | ||
| use_oidc = true | ||
| } | ||
|
|
||
| resource "azurerm_resource_group" "rg" { | ||
| name = var.resource_group_name | ||
|
salabam marked this conversation as resolved.
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.
|
||
| location = var.location | ||
|
salabam marked this conversation as resolved.
|
||
| } | ||
|
|
||
| module "storage_module" { | ||
| source = "./modules/storage" | ||
| storage_account_name = var.storage_account_name | ||
| storage_container_name = var.storage_container_name | ||
|
salabam marked this conversation as resolved.
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 storage module is being passed |
||
| resource_group_name = azurerm_resource_group.rg.name | ||
| location = var.location | ||
| } | ||
|
|
||
| module "network_module" { | ||
| source = "./modules/network" | ||
| resource_group_name = azurerm_resource_group.rg.name | ||
| location = azurerm_resource_group.rg.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 | ||
| net_security_group_name = var.net_security_group_name | ||
| public_ip_name = var.public_ip_name | ||
| dns_prefix = var.dns_prefix | ||
|
salabam marked this conversation as resolved.
Comment on lines
+36
to
+42
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. You pass many network-related inputs here. The task requires specific names: virtual network |
||
| } | ||
|
|
||
| module "compute_module" { | ||
| source = "./modules/compute" | ||
| resource_group_name = azurerm_resource_group.rg.name | ||
| location = azurerm_resource_group.rg.location | ||
| subnet_id = module.network_module.subnet_id | ||
| public_ip_id = module.network_module.public_ip_id | ||
| network_interface_name_sufix = var.network_interface_name_sufix | ||
|
salabam marked this conversation as resolved.
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 compute module receives |
||
| vm_name = var.vm_name | ||
| vm_size = var.vm_size | ||
|
salabam marked this conversation as resolved.
|
||
| admin_username = var.admin_username | ||
| ssh_public_key = var.ssh_public_key | ||
|
salabam marked this conversation as resolved.
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.
|
||
| install_app_sh_git_path = var.install_app_sh_git_path | ||
|
salabam marked this conversation as resolved.
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.
|
||
| depends_on = [module.network_module] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| resource "azurerm_network_interface" "ni" { | ||
| name = "${var.vm_name}${var.network_interface_name_sufix}" | ||
|
salabam marked this conversation as resolved.
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 name is constructed as |
||
| resource_group_name = var.resource_group_name | ||
| location = var.location | ||
|
|
||
| ip_configuration { | ||
| name = "ip-cfg" | ||
| private_ip_address_allocation = "Dynamic" | ||
| subnet_id = var.subnet_id | ||
| public_ip_address_id = var.public_ip_id | ||
| } | ||
| } | ||
|
|
||
| resource "azurerm_linux_virtual_machine" "vm" { | ||
| name = var.vm_name | ||
| location = var.location | ||
| resource_group_name = var.resource_group_name | ||
| network_interface_ids = [azurerm_network_interface.ni.id] | ||
| size = var.vm_size | ||
| admin_username = var.admin_username | ||
| disable_password_authentication = true | ||
|
|
||
| admin_ssh_key { | ||
| username = var.admin_username | ||
| public_key = var.ssh_public_key | ||
|
salabam marked this conversation as resolved.
Comment on lines
+23
to
+25
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. You use |
||
| } | ||
|
|
||
| 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
+33
to
+37
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 and SKU here use Ubuntu 22.04 (Canonical jammy, sku |
||
| } | ||
|
|
||
| } | ||
|
|
||
| resource "azurerm_virtual_machine_extension" "install_script" { | ||
| name = "install-app-extension" | ||
| 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_app_sh_git_path | ||
|
salabam marked this conversation as resolved.
Comment on lines
+50
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. The VM extension's |
||
| ], | ||
| commandToExecute = "bash install-app.sh" | ||
|
salabam marked this conversation as resolved.
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,3 @@ | ||
| output "vm_id" { | ||
| value = azurerm_linux_virtual_machine.vm.id | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| ### I made sure that all variables are in terraform.tfvars | ||
| ### I don't need you to write "check it!" to every variable. | ||
|
|
||
| variable "resource_group_name" { | ||
| description = "The name of the resource group" | ||
| type = string | ||
|
Comment on lines
+4
to
+6
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 the resource group to be |
||
| } | ||
|
|
||
| variable "location" { | ||
| description = "The location for all resources." | ||
| type = string | ||
|
Comment on lines
+9
to
+11
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 |
||
| } | ||
|
|
||
| variable "vm_name" { | ||
| description = "The name of the virtual machine" | ||
| type = string | ||
|
Comment on lines
+14
to
+16
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 must be named
Comment on lines
+14
to
+16
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 module does not expose or default the VM image. The task requires the VM image be |
||
| } | ||
|
salabam marked this conversation as resolved.
|
||
|
|
||
| variable "vm_size" { | ||
| description = "The size of the virtual machine" | ||
| type = string | ||
|
Comment on lines
+19
to
+21
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 size must be |
||
| } | ||
|
salabam marked this conversation as resolved.
|
||
|
|
||
| variable "network_interface_name_sufix" { | ||
| description = "The sufix of the network interface, will be concatenated with vm_name" | ||
| type = string | ||
|
Comment on lines
+24
to
+26
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.
|
||
| } | ||
|
salabam marked this conversation as resolved.
|
||
|
|
||
| variable "subnet_id" { | ||
| description = "The id of the sub network" | ||
| type = string | ||
| } | ||
|
|
||
| variable "public_ip_id" { | ||
| description = "The id of the public ip address" | ||
| type = string | ||
| } | ||
|
|
||
| variable "admin_username" { | ||
| description = "The user that will be created when the virtual machine is created" | ||
| type = string | ||
| } | ||
|
|
||
| variable "ssh_public_key" { | ||
| description = "The path to the ssh key for sign in to system" | ||
| type = string | ||
|
Comment on lines
+44
to
+46
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 variable |
||
| } | ||
|
salabam marked this conversation as resolved.
|
||
|
|
||
| variable "install_app_sh_git_path" { | ||
| description = "The path to the git repo with install script" | ||
| type = string | ||
|
Comment on lines
+49
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.
|
||
| } | ||
|
salabam marked this conversation as resolved.
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| locals { | ||
| security_rules = [ | ||
|
salabam marked this conversation as resolved.
|
||
| { | ||
| name = "AllowSSH" | ||
| priority = 100 | ||
| direction = "Inbound" | ||
| access = "Allow" | ||
| protocol = "Tcp" | ||
| source_port_range = "*" | ||
| destination_port_range = "22" | ||
| source_address_prefix = "*" | ||
| destination_address_prefix = "*" | ||
|
salabam marked this conversation as resolved.
|
||
| }, | ||
| { | ||
| name = "AllowHTTP" | ||
| priority = 110 | ||
| direction = "Inbound" | ||
| access = "Allow" | ||
| protocol = "Tcp" | ||
| source_port_range = "*" | ||
| destination_port_range = "80" | ||
| source_address_prefix = "*" | ||
| destination_address_prefix = "*" | ||
|
salabam marked this conversation as resolved.
|
||
| }, | ||
| { | ||
| name = "AllowHTTP8080" | ||
| priority = 120 | ||
| direction = "Inbound" | ||
| access = "Allow" | ||
| protocol = "Tcp" | ||
| source_port_range = "*" | ||
| destination_port_range = "8080" | ||
| source_address_prefix = "*" | ||
| destination_address_prefix = "*" | ||
|
salabam marked this conversation as resolved.
|
||
| } | ||
| ] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| resource "random_integer" "suffix" { | ||
| min = 1000 | ||
| max = 9999 | ||
| } | ||
|
|
||
| resource "azurerm_virtual_network" "vnet" { | ||
| name = var.virtual_network_name | ||
| address_space = var.vnet_address_prefix | ||
| resource_group_name = var.resource_group_name | ||
| location = var.location | ||
|
Comment on lines
+6
to
+10
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.
|
||
| } | ||
|
|
||
| resource "azurerm_subnet" "subnet" { | ||
| name = var.subnet_name | ||
| address_prefixes = var.subnet_address_prefix | ||
| resource_group_name = var.resource_group_name | ||
| virtual_network_name = azurerm_virtual_network.vnet.name | ||
|
Comment on lines
+13
to
+17
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.
|
||
| } | ||
|
|
||
| resource "azurerm_public_ip" "pip" { | ||
| name = var.public_ip_name | ||
| location = var.location | ||
| resource_group_name = var.resource_group_name | ||
| allocation_method = "Dynamic" | ||
| sku = "Standard" | ||
|
Comment on lines
+24
to
+25
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. You set |
||
| domain_name_label = "${var.dns_prefix}${random_integer.suffix.result}" | ||
|
salabam marked this conversation as resolved.
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 domain name label is constructed with |
||
| } | ||
|
|
||
| resource "azurerm_network_security_group" "nsg" { | ||
| name = var.net_security_group_name | ||
|
salabam marked this conversation as resolved.
|
||
| location = var.location | ||
| resource_group_name = var.resource_group_name | ||
|
Comment on lines
+29
to
+32
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.
|
||
|
|
||
| dynamic "security_rule" { | ||
| for_each = local.security_rules | ||
|
salabam marked this conversation as resolved.
Comment on lines
+34
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 dynamic block uses |
||
| content { | ||
| name = security_rule.value.name | ||
| priority = security_rule.value.priority | ||
| direction = security_rule.value.direction | ||
| access = security_rule.value.access | ||
| protocol = security_rule.value.protocol | ||
| source_port_range = security_rule.value.source_port_range | ||
| destination_port_range = security_rule.value.destination_port_range | ||
| source_address_prefix = security_rule.value.source_address_prefix | ||
| destination_address_prefix = security_rule.value.destination_address_prefix | ||
| } | ||
| } | ||
| } | ||
|
|
||
| resource "azurerm_subnet_network_security_group_association" "assoc" { | ||
| subnet_id = azurerm_subnet.subnet.id | ||
| network_security_group_id = azurerm_network_security_group.nsg.id | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| output "public_ip_fqdn" { | ||
| value = azurerm_public_ip.pip.fqdn | ||
|
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. This output uses |
||
| } | ||
|
|
||
| output "subnet_id" { | ||
| value = azurerm_subnet.subnet.id | ||
|
Comment on lines
+5
to
+6
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 output references |
||
| } | ||
|
|
||
| output "public_ip_id" { | ||
| value = azurerm_public_ip.pip.id | ||
|
Comment on lines
+9
to
+10
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 references |
||
| } | ||
|
|
||
| output "public_ip_address" { | ||
| value = azurerm_public_ip.pip.ip_address | ||
|
Comment on lines
+13
to
+14
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.
|
||
| } | ||
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.
*.tfvarswill ignore the requiredterraform.tfvarsfile which the task requires in the repository (Main Configuration and Variables). This will prevent graders / CI from seeing the enforced variable values. Remove this line or add an explicit allow rule such as!terraform.tfvarsso the rootterraform.tfvarscan be committed.