-
Notifications
You must be signed in to change notification settings - Fork 21
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
Solution #13
Open
Kagerou4649
wants to merge
3
commits into
mate-academy:main
Choose a base branch
from
Kagerou4649:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+375
−0
Open
Solution #13
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = "tfstate144" | ||
container_name = "tfstate" | ||
key = "terraform.tfstate" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
terraform { | ||
required_providers { | ||
azurerm = { | ||
source = "hashicorp/azurerm" | ||
version = "3.105.0" | ||
} | ||
} | ||
} | ||
|
||
provider "azurerm" { | ||
features {} | ||
} | ||
|
||
resource "azurerm_resource_group" "main" { | ||
name = "todolist-terraform-task" | ||
location = "West Europe" | ||
} | ||
|
||
module "network" { | ||
source = "./modules/network" | ||
resource_group_name = azurerm_resource_group.main.name | ||
location = azurerm_resource_group.main.location | ||
dns_label_prefix = var.dns_label | ||
virtual_network_name = var.virtual_network_name | ||
vnet_address_prefix = var.vnet_address_prefix | ||
} | ||
|
||
module "compute" { | ||
source = "./modules/compute" | ||
location = azurerm_resource_group.main.location | ||
resource_group_name = azurerm_resource_group.main.name | ||
vm_name = var.vm_name | ||
subnet_id = module.network.subnet_id | ||
public_ip_id = module.network.public_ip_address | ||
ssh_key = var.ssh_key | ||
virtual_network_name = var.virtual_network_name | ||
vnet_address_prefix = var.vnet_address_prefix | ||
} | ||
|
||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
resource "azurerm_public_ip" "linuxboxpip" { | ||
name = "linuxboxpip" | ||
location = var.location | ||
resource_group_name = var.resource_group_name | ||
allocation_method = "Static" | ||
} | ||
|
||
resource "azurerm_network_interface" "vm-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 = azurerm_public_ip.linuxboxpip.id | ||
} | ||
} | ||
|
||
resource "azurerm_linux_virtual_machine" "matebox" { | ||
name = "matebox" | ||
resource_group_name = var.resource_group_name | ||
location = var.location | ||
size = "Standard_B1s" | ||
admin_username = "adminuser" | ||
network_interface_ids = [ | ||
azurerm_network_interface.vm-nic.id, | ||
] | ||
|
||
admin_ssh_key { | ||
username = "adminuser" | ||
public_key = var.ssh_key | ||
} | ||
|
||
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" "CustomScript" { | ||
name = "CustomScript" | ||
virtual_machine_id = azurerm_linux_virtual_machine.matebox.id | ||
publisher = "Microsoft.Azure.Extensions" | ||
type = "CustomScript" | ||
type_handler_version = "2.0" | ||
|
||
settings = <<SETTINGS | ||
{ | ||
"fileUris": [ | ||
"https://lvkzxjncklvjn.blob.core.windows.net/task-artifacts/install-app.sh" | ||
], | ||
"script": "bash install-app.sh" | ||
} | ||
SETTINGS | ||
|
||
depends_on = [azurerm_linux_virtual_machine.matebox] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
output "network_interface_id" { | ||
description = "The ID of the network interface." | ||
value = azurerm_network_interface.vm-nic.id | ||
} | ||
|
||
output "virtual_machine_id" { | ||
description = "The ID of the virtual machine." | ||
value = azurerm_linux_virtual_machine.matebox.id | ||
} | ||
|
||
output "vm_extension_id" { | ||
description = "The ID of the VM extension." | ||
value = azurerm_virtual_machine_extension.CustomScript.id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
variable "location" { | ||
description = "The location where resources will be created." | ||
type = string | ||
} | ||
|
||
variable "resource_group_name" { | ||
description = "The name of the resource group." | ||
type = string | ||
} | ||
|
||
variable "vm_name" { | ||
description = "The name of the virtual machine." | ||
type = string | ||
} | ||
|
||
variable "subnet_id" { | ||
description = "The ID of the subnet." | ||
type = string | ||
} | ||
|
||
variable "public_ip_id" { | ||
description = "The ID of the public IP address." | ||
type = string | ||
} | ||
|
||
variable "ssh_key" { | ||
description = "The SSH public key for authentication." | ||
type = string | ||
} | ||
|
||
variable "virtual_network_name" { | ||
description = "The name of the virtual network" | ||
type = string | ||
} | ||
|
||
variable "vnet_address_prefix" { | ||
description = "The address prefix for the virtual network" | ||
type = string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
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" "default" { | ||
name = "default" | ||
resource_group_name = var.resource_group_name | ||
virtual_network_name = azurerm_virtual_network.vnet.name | ||
address_prefixes = ["10.0.0.0/24"] | ||
} | ||
|
||
resource "azurerm_network_security_group" "defaultnsg" { | ||
name = "defaultnsg" | ||
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 = "*" | ||
} | ||
} | ||
|
||
resource "azurerm_public_ip" "linuxboxpip" { | ||
name = "linuxboxpip" | ||
resource_group_name = var.resource_group_name | ||
location = var.location | ||
allocation_method = "Static" | ||
domain_name_label = "${var.dns_label_prefix}${random_integer.random.result}" | ||
} | ||
|
||
resource "random_integer" "random" { | ||
min = 1000 | ||
max = 9999 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
output "vnet_id" { | ||
description = "The ID of the virtual network." | ||
value = azurerm_virtual_network.vnet.id | ||
} | ||
|
||
output "network_security_group_id" { | ||
description = "The ID of the network security group." | ||
value = azurerm_network_security_group.defaultnsg.id | ||
} | ||
|
||
output "public_ip_id" { | ||
description = "The ID of the public IP address." | ||
value = azurerm_public_ip.linuxboxpip.id | ||
} | ||
|
||
output "public_ip_address" { | ||
description = "The public IP address value." | ||
value = azurerm_public_ip.linuxboxpip.ip_address | ||
} | ||
|
||
output "public_ip_fqdn" { | ||
description = "The fully qualified domain name (FQDN) of the public IP address." | ||
value = azurerm_public_ip.linuxboxpip.fqdn | ||
} | ||
|
||
output "subnet_id" { | ||
description = "The ID of the subnet." | ||
value = azurerm_subnet.default.id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
variable "location" { | ||
description = "The location where resources will be created." | ||
type = string | ||
} | ||
|
||
variable "resource_group_name" { | ||
description = "The name of the resource group." | ||
type = string | ||
} | ||
|
||
variable "dns_label_prefix" { | ||
description = "The prefix for the DNS label." | ||
type = string | ||
default = "matetask" | ||
} | ||
|
||
variable "virtual_network_name" { | ||
description = "The name of the virtual network" | ||
type = string | ||
} | ||
|
||
variable "vnet_address_prefix" { | ||
description = "The address prefix for the virtual network" | ||
type = string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
resource "azurerm_storage_account" "storage_account" { | ||
name = var.storage_account_name | ||
resource_group_name = var.resource_group_name | ||
location = var.location | ||
account_tier = "Standard" | ||
account_replication_type = "LRS" | ||
} | ||
|
||
resource "azurerm_storage_container" "task_artifacts" { | ||
name = "task-artifacts" | ||
storage_account_name = azurerm_storage_account.storage_account.name | ||
container_access_type = "private" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
output "storage_account_name" { | ||
value = azurerm_storage_account.storage_account.name | ||
description = "The name of the storage account." | ||
} | ||
|
||
output "storage_container_name" { | ||
value = azurerm_storage_container.task_artifacts.name | ||
description = "The name of the storage container." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
variable "location" { | ||
description = "The location where resources will be created." | ||
type = string | ||
} | ||
|
||
variable "resource_group_name" { | ||
description = "The name of the resource group." | ||
type = string | ||
} | ||
|
||
variable "storage_account_name" { | ||
description = "The name of the storage account." | ||
type = string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
output "virtual_network_id" { | ||
description = "The ID of the virtual network." | ||
value = module.network.vnet_id | ||
} | ||
|
||
output "subnet_id" { | ||
description = "The ID of the subnet." | ||
value = module.network.subnet_id | ||
} | ||
|
||
output "network_security_group_id" { | ||
description = "The ID of the network security group." | ||
value = module.network.network_security_group_id | ||
} | ||
|
||
output "public_ip_address" { | ||
description = "The public IP address." | ||
value = module.network.public_ip_address | ||
} | ||
|
||
output "virtual_machine_id" { | ||
description = "The ID of the virtual machine." | ||
value = module.compute.virtual_machine_id | ||
} | ||
|
||
output "vm_extension_id" { | ||
description = "The ID of the VM extension." | ||
value = module.compute.vm_extension_id | ||
} | ||
|
||
output "network_interface_id" { | ||
description = "The ID of the network interface." | ||
value = module.compute.network_interface_id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ssh_key = <<EOF | ||
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCjSa8xOgez5hycgVIbUnCA4Sf+pYofWWSc0H5fGM8ahdhzQ+RxvncmkMhda14lRU5tjTjVtbNKiw+9sZsUpkMcGKH+UEUGIOwXN9NKnZPMGvzByWQragaqAj5vanlDaTdiUYgqD/Ydvhy3zI5ax+PuNr1MQBOZ5bgwlR6fWT71NvY/XQt4cEDE/03ypjwAg57scK6hUsWfYk9iIF9V78d09PyOjIiTi5sVqUFkOtvy02Okqpuvjhtsr7W4gySu46ftKosXJTkYqCkxP7PmWuiOsBWrRAx6ZOvv/IY+CofrMOUUiRMKH9tXD/4mTjlkMwYtVQ4WEZkXLZOo2aVNri0usERnPjEkDmRxEV3YqHxTDhPWZBFnK59QLyPoEpy3HXS1H3Fe3xBVPSMJTzzPwrFo090Lovm8QYveBScLARh1WNGY4PiZFX/tOuadamb7LXNKeSA1MCVKK64D6H9MQ6CK9/NpQYeGXtGfl7TtJkqoIVg+1tgMwqx7JK27KaQG7nu3zY22oFgpqeBxady95JuGWm7mtrEQKv6kJhtByVTZ7xdcqJ62/sn1hcSfGpGsIcLn8tjdr6Ry0o6xSfvRC6iIEzubmCHiUyf/BIH9c1Ab1PgfLA4A8ecPUtAx9rvwvOyM3x2iKsTcmahV/gE6wt8wl0+n4BY9epwNdlUADmvNQQ== hyakunosuke7@gmail.com | ||
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
variable "vm_name" { | ||
description = "The name of the virtual machine." | ||
type = string | ||
default = "matebox" | ||
} | ||
|
||
variable "dns_label" { | ||
description = "The prefix for the DNS label." | ||
type = string | ||
default = "todolist-terraform-task" | ||
} | ||
|
||
variable "ssh_key" { | ||
description = "The SSH public key for the VM." | ||
type = string | ||
} | ||
|
||
variable "storage_account_name" { | ||
description = "The name of the storage account." | ||
type = string | ||
default = "tfstatekagerou4649" | ||
} | ||
|
||
variable "virtual_network_name" { | ||
description = "The name of the virtual network" | ||
type = string | ||
} | ||
|
||
variable "vnet_address_prefix" { | ||
description = "The address prefix for the virtual network" | ||
type = string | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 same here