diff --git a/.gitignore b/.gitignore index a590c3d..d803525 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,6 @@ /main.tfplan /terraform.tfstate /terraform.tfstate.backup + +simple-api-0.0.1-SNAPSHOT.jar + diff --git a/SUBMISSION.md b/SUBMISSION.md new file mode 100644 index 0000000..212879c --- /dev/null +++ b/SUBMISSION.md @@ -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 azureadmin@20.162.216.147:/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) \ No newline at end of file diff --git a/images/01_ValidateTerraform.png b/images/01_ValidateTerraform.png new file mode 100644 index 0000000..a143a55 Binary files /dev/null and b/images/01_ValidateTerraform.png differ diff --git a/images/02_VM_created.png b/images/02_VM_created.png new file mode 100644 index 0000000..53f2713 Binary files /dev/null and b/images/02_VM_created.png differ diff --git a/images/03_jarFileInVM.png b/images/03_jarFileInVM.png new file mode 100644 index 0000000..746be72 Binary files /dev/null and b/images/03_jarFileInVM.png differ diff --git a/images/04_startedSpringApp.png b/images/04_startedSpringApp.png new file mode 100644 index 0000000..663279a Binary files /dev/null and b/images/04_startedSpringApp.png differ diff --git a/images/05_inBrowser.png b/images/05_inBrowser.png new file mode 100644 index 0000000..87f4df5 Binary files /dev/null and b/images/05_inBrowser.png differ diff --git a/images/06_terraformDestroy.png b/images/06_terraformDestroy.png new file mode 100644 index 0000000..06b2694 Binary files /dev/null and b/images/06_terraformDestroy.png differ diff --git a/main.tf b/main.tf index 221e5f9..9d0892c 100644 --- a/main.tf +++ b/main.tf @@ -9,7 +9,7 @@ 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 @@ -17,7 +17,7 @@ resource "azurerm_virtual_network" "my_terraform_network" { # 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"] @@ -25,7 +25,7 @@ resource "azurerm_subnet" "my_terraform_subnet" { # 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" @@ -33,7 +33,7 @@ resource "azurerm_public_ip" "my_terraform_public_ip" { # 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 @@ -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 @@ -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"