Skip to content
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

Emma Lövgren #15

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
Expand Up @@ -6,3 +6,6 @@
/main.tfplan
/terraform.tfstate
/terraform.tfstate.backup

simple-api-0.0.1-SNAPSHOT.jar

21 changes: 21 additions & 0 deletions SUBMISSION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Submission

1. Generated ssh key.
2. Changed 'my' to 'emmaLovgren' in `main.tf`.
3. Changed Ubuntu version and added security rules to `main.tf`.
4. Run `terraform init -upgrade`
5. Validate terraform:
![](images/01_ValidateTerraform.png)
6. Generate main.tfplan and run apply command to create VM:
![](images/02_VM_created.png)
7. Run ./gradlew build in the IntelliJ project for the backend to update the jar file.
8. Install java on VM with `sudo apt install openjdk-21-jdk`
8. Copied the jar file to this repo and added the jar file to gitignore to avoid pushing it to GitHub `scp -i azure-tf-server simple-api-0.0.1-SNAPSHOT.jar [email protected]:/home/azureadmin
`:
![](images/03_jarFileInVM.png)
9. Run command `java -jar simple-api-0.0.1-SNAPSHOT.jar &` in VM:
![](images/04_startedSpringApp.png)
10. Opened in web browser `http://20.162.216.147:5000/regions`:
![](images/05_inBrowser.png)
11. Run `terraform destroy` to clean up and delete VM after this exercise:
![](images/06_terraformDestroy.png)
Binary file added images/01_ValidateTerraform.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/02_VM_created.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/03_jarFileInVM.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/04_startedSpringApp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/05_inBrowser.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/06_terraformDestroy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 46 additions & 10 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@ resource "azurerm_resource_group" "rg" {

# Create virtual network
resource "azurerm_virtual_network" "my_terraform_network" {
name = "myVnet"
name = "emmaLovgrenVnet"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
}

# Create subnet
resource "azurerm_subnet" "my_terraform_subnet" {
name = "mySubnet"
name = "emmaLovgrenSubnet"
resource_group_name = azurerm_resource_group.rg.name
virtual_network_name = azurerm_virtual_network.my_terraform_network.name
address_prefixes = ["10.0.1.0/24"]
}

# Create public IPs
resource "azurerm_public_ip" "my_terraform_public_ip" {
name = "myPublicIP"
name = "emmaLovgrenPublicIP"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
allocation_method = "Dynamic"
}

# Create Network Security Group and rule
resource "azurerm_network_security_group" "my_terraform_nsg" {
name = "myNetworkSecurityGroup"
name = "emmaLovgrenNetworkSecurityGroup"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name

Expand All @@ -48,11 +48,47 @@ resource "azurerm_network_security_group" "my_terraform_nsg" {
source_address_prefix = "*"
destination_address_prefix = "*"
}

security_rule {
name = "HTTP"
priority = 1011
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "80"
source_address_prefix = "*"
destination_address_prefix = "*"
}

security_rule {
name = "HTTPS"
priority = 1021
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "443"
source_address_prefix = "*"
destination_address_prefix = "*"
}

security_rule {
name = "AllowCustom5000"
priority = 1031
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "5000"
source_address_prefix = "*"
destination_address_prefix = "*"
}
}

# Create network interface
resource "azurerm_network_interface" "my_terraform_nic" {
name = "myNIC"
name = "emmaLovgrenNIC"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name

Expand Down Expand Up @@ -91,23 +127,23 @@ resource "azurerm_storage_account" "my_storage_account" {

# Create virtual machine
resource "azurerm_linux_virtual_machine" "my_terraform_vm" {
name = "myVM"
name = "emmaLovgrenVM"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
network_interface_ids = [azurerm_network_interface.my_terraform_nic.id]
size = "Standard_DS1_v2"

os_disk {
name = "myOsDisk"
name = "emmaLovgrenOsDisk"
caching = "ReadWrite"
storage_account_type = "Premium_LRS"
}

source_image_reference {
offer = "ubuntu-24_04-lts"
publisher = "Canonical"
offer = "0001-com-ubuntu-server-jammy"
sku = "22_04-lts-gen2"
version = "latest"
sku = "server"
version = "24.04.202410170"
}

computer_name = "hostname"
Expand Down