Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.terraform/
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Location is 'Korea Central' but requirement specifies 'uksouth' (CHECKLIST ITEM #7).

*.tfstate
*.tfstate.*
5 changes: 5 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/devops_todolist_terraform_task.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/terraform.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions .terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
terraform {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checklist Item #7 Violation: Location must be uksouth as specified in requirements, but is set to Korea Central. This will deploy resources to the wrong region.

required_providers {
azurerm = {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Undefined variable: storage_account_name is declared but never assigned a value. This will cause a reference error when the module tries to use it.

source = "hashicorp/azurerm"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The storage_account_key variable is passed to the storage module but the storage module has its own mechanism to get the primary access key (it outputs primary_access_key). The passed value appears to be unused or incorrectly configured.

version = "3.105.0"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Undefined variable: storage_account_key is declared but never assigned a value. This will cause a reference error when the module tries to use it.

}
}

backend "azurerm" {
resource_group_name = "mate-azure-task-12"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checklist Item #10 Violation: vm_size must be Standard_B1s as specified in requirements, but is set to Standard_D2s_v3. This changes the VM specification.

storage_account_name = "storagejghae7"
container_name = "task-artifacts"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checklist Item #27 Violation: Backend container_name should be tfstate per requirements, but is set to task-artifacts. This mismatches the required remote state configuration.

key = "terraform.tfstate"
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checklist Item #19 Violation: Public IP allocation_method should be Dynamic per requirements, but is set to Static. The requirements explicitly state dynamic allocation method.

6 changes: 5 additions & 1 deletion install-app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ apt-get install python3-pip -yq
# Create a directory for the app and download the files.
mkdir /app
# 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/Xandane/devops_todolist_terraform_task.git
cd /app
pip3 install -r requirements.txt
sudo python3 manage.py migrate
python3 manage.py collectstatic --noinput
cp -r devops_todolist_terraform_task/app/* /app

# create a service for the app via systemctl and start the app
Expand Down
57 changes: 57 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
provider "azurerm" {
features {}
subscription_id = "6a8d93ad-791e-41b1-a745-b6c493b83991"
}



resource "azurerm_resource_group" "example" {
name = var.resource_group_name
location = var.location
}


module "compute" {
Comment on lines +13 to +14
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate output: network_interface_id (line 7) and nic_id (line 13) both output the exact same value. Remove one of them to avoid redundancy.

source = "./modules/compute"
network_security_group_id = module.network.network_security_group_id
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location

vm_name = var.vm_name
vm_size = var.vm_size
ssh_key_public = var.ssh_key_public

public_ip_address_name = var.public_ip_address_name
subnet_id = module.network.subnet_id
public_ip_id = module.network.public_ip_id

storage_account_name = module.storage.storage_account_name
storage_account_key = module.storage.primary_access_key
script_blob_url = module.storage.script_blob_url

depends_on = [module.storage]
}

module "network" {
source = "./modules/network"
Comment on lines +33 to +36
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checklist Item #9 Violation: The SKU should reference the proper Ubuntu 22.04 identifier. For the Ubuntu2204 marketplace image, the SKU typically follows a format like 2204-lts rather than 22_04-lts. Verify this matches the exact marketplace image plan.

resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
vnet_address_prefix = var.vnet_address_prefix
virtual_network_name = var.virtual_network_name
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
public_ip_allocation_method = "Dynamic"

}


module "storage" {
source = "./modules/storage"
resource_group_name = var.resource_group_name
location = var.location
storage_container_name = var.storage_container_name
storage_account_key = var.storage_account_key
storage_account_name = module.storage.storage_account_name
}
88 changes: 88 additions & 0 deletions modules/compute/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
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_virtual_machine" "main" {
name = var.vm_name
location = var.location
resource_group_name = var.resource_group_name
network_interface_ids = [
azurerm_network_interface.main.id
]
vm_size = var.vm_size





Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The storage module receives storage_account_name and storage_account_key as inputs, but the module's main.tf never uses these variables - it generates its own storage account name. These variables are unnecessary and should be removed from the module's variables.tf.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The storage_account_name variable is declared but never assigned a value. The storage module generates its own name. Remove this unused variable.

# Uncomment this line to delete the OS disk automatically when deleting the VM
# delete_os_disk_on_termination = true

# Uncomment this line to delete the data disks automatically when deleting the VM
# delete_data_disks_on_termination = true

storage_image_reference {
publisher = "Canonical"
offer = "0001-com-ubuntu-server-jammy"
Comment on lines +34 to +35
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The storage_account_key variable is declared but never assigned a value. The storage module generates its own key via primary_access_key output. Remove this unused variable.

sku = "22_04-lts"
version = "latest"
}

storage_os_disk {
name = "myosdisk1"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}

os_profile {
computer_name = "hostname"
admin_username = "testadmin"
}

os_profile_linux_config {
disable_password_authentication = true
ssh_keys {
key_data = var.ssh_key_public
Comment on lines +54 to +55
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Critical Error: var.storage_account_key is used here but never defined in terraform.tfvars. This will cause a reference error.

path = "/home/testadmin/.ssh/authorized_keys"
Comment on lines +50 to +56
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Critical Error: The storage module is passed module.storage.storage_account_name but the storage module declares this variable and never assigns it a value (it generates its own name internally via random_string). This creates a circular/unresolved reference that will cause Terraform to fail. The storage module doesn't need storage_account_name as input since it creates its own.

}
}

tags = {
environment = "staging"
}
}

resource "azurerm_virtual_machine_extension" "main" {
name = "install-app"
virtual_machine_id = azurerm_virtual_machine.main.id

publisher = "Microsoft.Azure.Extensions"
type = "CustomScript"
type_handler_version = "2.1"

settings = jsonencode({
fileUris = [
var.script_blob_url
]

commandToExecute = "sudo bash install-app.sh"
})
}



resource "azurerm_network_interface_security_group_association" "example" {
network_interface_id = azurerm_network_interface.main.id
network_security_group_id = var.network_security_group_id
}

17 changes: 17 additions & 0 deletions modules/compute/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
output "vm_name" {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The storage_account_name variable is passed to the storage module but the storage module generates its own name using random_string. This passed value is not used in modules/storage/main.tf, making the variable declaration misleading.

value = azurerm_virtual_machine.main.name
}
output "vm_id" {
value = azurerm_virtual_machine.main.id
}
output "network_interface_id" {
value = azurerm_network_interface.main.id
}
output "public_ip_address_name" {
value = var.public_ip_address_name
}
output "nic_id" {
value = azurerm_network_interface.main.id
}


46 changes: 46 additions & 0 deletions modules/compute/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
variable "subnet_id" {
type = string
}
variable "public_ip_id" {
type = string
}
variable "vm_name" {
type = string
}
variable "vm_size" {
type = string
}

variable "resource_group_name" {
type = string
}

variable "location" {
type = string
}


variable "ssh_key_public" {
type = string
}

variable "storage_account_name" {
type = string
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The storage_account_name variable is passed to the compute module (line 28) but is not used anywhere in the compute module's resources. This creates unnecessary coupling.

}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The storage_account_key variable passed to compute module (line 29) is not used in any compute module resources either.


variable "public_ip_address_name" {
type = string
}

variable "storage_account_key" {
type = string
}

variable "script_blob_url" {
type = string
}

variable "network_security_group_id" {
description = "Network Security Group ID"
type = string
}
Loading
Loading