-
Notifications
You must be signed in to change notification settings - Fork 70
add solutuon #64
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?
add solutuon #64
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,15 @@ | ||
| .terraform/ | ||
| *.tfstate | ||
| *.tfstate.* | ||
| *.tfvars | ||
| *.tfvars.json | ||
| *.tfvars.* | ||
| override.tf | ||
| override.tf.json | ||
|
taniakolesnik marked this conversation as resolved.
|
||
| *_override.tf | ||
| *_override.tf.json | ||
| crash.log | ||
| crash.log.* | ||
| .terraform.lock.hcl | ||
| terraform.tfplan | ||
| terraform.tfplan.* | ||
| 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 = "storageacctk19052026" | ||
| container_name = "tfstate" | ||
| key = "terraform.tfstate" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| terraform { | ||
| required_providers { | ||
| azurerm = { | ||
| source = "hashicorp/azurerm" | ||
| version = "~> 3.0" | ||
| } | ||
| } | ||
| } | ||
|
taniakolesnik marked this conversation as resolved.
|
||
|
|
||
| provider "azurerm" { | ||
| features {} | ||
| } | ||
|
|
||
| resource "azurerm_resource_group" "name" { | ||
| name = var.azurerm_resource_group_name | ||
| location = var.location | ||
| } | ||
|
|
||
| module "network" { | ||
| source = "./modules/network" | ||
| location = var.location | ||
| azurerm_resource_group_name = var.azurerm_resource_group_name | ||
| azurerm_network_security_group_name = var.azurerm_network_security_group_name | ||
| azurerm_virtual_network_name = var.azurerm_virtual_network_name | ||
| azurerm_virtual_network_address_space = var.azurerm_virtual_network_address_space | ||
| subnet_name = var.subnet_name | ||
| subnet_prefix = var.subnet_prefix | ||
| azurerm_public_ip_name = var.azurerm_public_ip_name | ||
| dns_label = var.dns_label | ||
| } | ||
|
|
||
| module "compute" { | ||
| source = "./modules/compute" | ||
| location = var.location | ||
| subnet_id = module.network.subnet_id | ||
| vm_name = var.vm_name | ||
| vm_size = var.vm_size | ||
| public_ssh_key = var.public_ssh_key | ||
| } | ||
|
|
||
| module "storage" { | ||
| source = "./modules/storage" | ||
| azurerm_resource_group_name = var.azurerm_resource_group_name | ||
| location = var.location | ||
| } | ||
|
taniakolesnik marked this conversation as resolved.
taniakolesnik marked this conversation as resolved.
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| resource "azurerm_network_interface" "example" { | ||
| name = "${var.vm_name}-nic" | ||
| location = var.location | ||
|
taniakolesnik marked this conversation as resolved.
|
||
| resource_group_name = var.azurerm_resource_group_name | ||
|
|
||
| ip_configuration { | ||
| name = "internal" | ||
| subnet_id = var.subnet_id | ||
| private_ip_address_allocation = "Dynamic" | ||
| } | ||
| } | ||
|
|
||
| resource "azurerm_linux_virtual_machine" "example" { | ||
| name = var.vm_name | ||
| resource_group_name = var.azurerm_resource_group_name | ||
| location = var.location | ||
| size = var.vm_size | ||
| admin_username = "adminuser" | ||
| network_interface_ids = [ | ||
| azurerm_network_interface.example.id, | ||
| ] | ||
|
|
||
| admin_ssh_key { | ||
| username = "adminuser" | ||
| public_key = var.public_ssh_key | ||
| } | ||
|
|
||
| os_disk { | ||
| caching = "ReadWrite" | ||
| storage_account_type = "Standard_LRS" | ||
| } | ||
|
|
||
| source_image_reference { | ||
|
taniakolesnik marked this conversation as resolved.
|
||
| publisher = "Canonical" | ||
| offer = "0001-com-ubuntu-server-jammy" | ||
| sku = "22_04-lts" | ||
| version = "latest" | ||
| } | ||
| } | ||
|
|
||
| resource "azurerm_virtual_machine_extension" "example" { | ||
| name = "hostname" | ||
| virtual_machine_id = azurerm_linux_virtual_machine.example.id | ||
| publisher = "Microsoft.Azure.Extensions" | ||
| type = "CustomScript" | ||
| type_handler_version = "2.0" | ||
|
|
||
| settings = jsonencode({ | ||
| commandToExecute = <<-EOT | ||
| apt-get update -yq | ||
| apt-get install python3-pip git -yq | ||
|
|
||
| mkdir -p /app | ||
| git clone https://github.com/taniakolesnik/azure_task_12_deploy_app_with_vm_extention.git /tmp/apprepo | ||
| cp -r /tmp/apprepo/devops_todolist_terraform_task/app/* /app | ||
|
|
||
| mv /app/todoapp.service /etc/systemd/system/ | ||
| systemctl daemon-reload | ||
| systemctl start todoapp | ||
| systemctl enable todoapp | ||
| EOT | ||
|
taniakolesnik marked this conversation as resolved.
|
||
| }) | ||
|
Comment on lines
+40
to
+62
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 requirement explicitly states: 'VM Extension: use the CustomScript extension to execute install-app.sh script.' Currently, the extension has inline commands that duplicate the script content. Instead, use |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| variable "azurerm_resource_group_name" { | ||
| description = "The name of the resource group" | ||
| default = "mate-azure-task-12" | ||
|
taniakolesnik marked this conversation as resolved.
|
||
| type = string | ||
| } | ||
|
|
||
| variable "location" { | ||
| description = "Resource location" | ||
| default = "uksouth" | ||
| type = string | ||
| } | ||
|
|
||
| variable "subnet_id" { | ||
| description = "subnet id" | ||
| type = string | ||
| } | ||
|
|
||
| variable "vm_name" { | ||
| description = "The name of the virtual machine" | ||
| default = "matebox" | ||
| type = string | ||
| } | ||
|
|
||
| variable "vm_size" { | ||
| description = "The size of the virtual machine" | ||
| default = "Standard_B1s" | ||
| type = string | ||
| } | ||
|
|
||
| variable "public_ssh_key" { | ||
| default = "linuxboxsshkey" | ||
| type = string | ||
| description = "SSH key" | ||
|
taniakolesnik marked this conversation as resolved.
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
|
|
||
| # network security group | ||
| resource "azurerm_network_security_group" "example" { | ||
|
taniakolesnik marked this conversation as resolved.
|
||
| name = var.azurerm_network_security_group_name | ||
| location = var.location | ||
| resource_group_name = var.azurerm_resource_group_name | ||
| } | ||
|
|
||
| # virtual network | ||
| resource "azurerm_virtual_network" "example" { | ||
| name = var.azurerm_virtual_network_name | ||
| location = var.location | ||
| resource_group_name = var.azurerm_resource_group_name | ||
| address_space = var.azurerm_virtual_network_address_space | ||
| } | ||
|
|
||
| # subnet | ||
| resource "azurerm_subnet" "default" { | ||
| name = var.subnet_name | ||
| resource_group_name = var.azurerm_resource_group_name | ||
| virtual_network_name = azurerm_virtual_network.example.name | ||
| address_prefixes = var.subnet_prefix | ||
| } | ||
|
|
||
| # assosiate subnet to network security group | ||
| resource "azurerm_subnet_network_security_group_association" "default" { | ||
| subnet_id = azurerm_subnet.default.id | ||
| network_security_group_id = azurerm_network_security_group.example.id | ||
| } | ||
|
|
||
| resource "random_integer" "dns" { | ||
| min = 1000 | ||
| max = 9999 | ||
| } | ||
|
|
||
| # public IP address | ||
| resource "azurerm_public_ip" "example" { | ||
| name = var.azurerm_public_ip_name | ||
| resource_group_name = var.azurerm_resource_group_name | ||
| location = var.location | ||
| 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,11 @@ | ||
| output "subnet_id" { | ||
| value = azurerm_subnet.default.id | ||
| } | ||
|
|
||
| output "public_ip_address" { | ||
| value = azurerm_public_ip.example.ip_address | ||
| } | ||
|
|
||
| output "public_ip_fqdn" { | ||
| value = azurerm_public_ip.example.fqdn | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| variable "azurerm_resource_group_name" { | ||
| default = "mate-azure-task-12" | ||
|
taniakolesnik marked this conversation as resolved.
|
||
| type = string | ||
| } | ||
|
|
||
| variable "location" { | ||
| default = "uksouth" | ||
| type = string | ||
| } | ||
|
taniakolesnik marked this conversation as resolved.
|
||
|
|
||
| variable "azurerm_network_security_group_name" { | ||
| default = "defaultnsg" | ||
| type = string | ||
| } | ||
|
|
||
| variable "azurerm_virtual_network_name" { | ||
| default = "vnet" | ||
| type = string | ||
| } | ||
|
|
||
| variable "azurerm_virtual_network_address_space" { | ||
| default = ["10.0.0.0/16"] | ||
| type = list(string) | ||
| } | ||
| variable "subnet_name" { | ||
| default = "default" | ||
| type = string | ||
| } | ||
|
|
||
| variable "subnet_prefix" { | ||
| default = ["10.0.0.0/24"] | ||
| type = list(string) | ||
| } | ||
|
|
||
| variable "azurerm_public_ip_name" { | ||
| default = "linuxboxpip" | ||
| type = string | ||
| } | ||
|
|
||
| variable "dns_label" { | ||
| default = "matetask" | ||
| type = string | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| resource "azurerm_storage_account" "example" { | ||
| name = "storageacctk19052026" | ||
|
taniakolesnik marked this conversation as resolved.
|
||
| resource_group_name = var.azurerm_resource_group_name | ||
| location = var.location | ||
| account_tier = "Standard" | ||
| account_replication_type = "LRS" | ||
| } | ||
|
|
||
| resource "azurerm_storage_container" "example" { | ||
|
taniakolesnik marked this conversation as resolved.
|
||
| name = var.azurerm_storage_container_name | ||
| storage_account_name = azurerm_storage_account.example.name | ||
| container_access_type = "private" | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| variable "azurerm_resource_group_name" { | ||
| default = "mate-azure-task-12" | ||
|
taniakolesnik marked this conversation as resolved.
|
||
| type = string | ||
| } | ||
|
|
||
| variable "location" { | ||
| default = "uksouth" | ||
| type = string | ||
| } | ||
|
taniakolesnik marked this conversation as resolved.
|
||
|
|
||
| variable "azurerm_storage_container_name" { | ||
| default = "task-artifacts" | ||
| type = string | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| output "public_ip_address_name" { | ||
| value = module.network.public_ip_address | ||
| } | ||
|
|
||
| output "public_ip_fqdn" { | ||
| value = module.network.public_ip_fqdn | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.