From 29e5ba28e9ff5683cc43270dd56490b94b585b56 Mon Sep 17 00:00:00 2001 From: Ric Harvey Date: Tue, 16 Apr 2024 16:16:03 +0100 Subject: [PATCH] finish lab 1 --- 1-getting-started/.DS_Store | Bin 6148 -> 6148 bytes 1-getting-started/README.md | 75 ++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/1-getting-started/.DS_Store b/1-getting-started/.DS_Store index 1cf8145b82da00cc1cea078c9b6e7ad15d6f9f25..df2948888b0abe03a26152073b622a45a1ca5688 100644 GIT binary patch delta 289 zcmZoMXfc=|#>B)qu~2NHo+2aX#DLw41(+BaIVbZlM${*j7Z)VuvOFzie!$jK}& zF)+Bs$i&RT%Er#Y&cV$Q8=R3}9$b=GQd;bkSQHK7h2-bwB*EB;Nnx3(!A4ToZP(pZlLRcfRPbGGw?!b7}Ya5im_OjnIV%Qmm$3@ uxF|0tKQA4mVe=`*2$s$49Q+)>0NBjP^qqM!zlbFV&>XN)n*&6)FarQA?n>VP delta 71 zcmZoMXfc=|#>B`mu~2NHo+2ar#DLw5?2~zzA|@L%XKvoa9Llo!1M^eH&Fmcf96)88 aA2NSup3E;|$-w{wj0_A+n*&6)FarR|U=nix diff --git a/1-getting-started/README.md b/1-getting-started/README.md index 3891fc7..5469d05 100644 --- a/1-getting-started/README.md +++ b/1-getting-started/README.md @@ -115,6 +115,8 @@ Now lets run some code. > [!Note] > You can replace the commands for ```terraform``` from ```tofu``` if you are running that version +#### init + First lets initialise our terraform/tofu environment: ```bash @@ -124,3 +126,76 @@ tofu init ![tofu init output on screen](./img/tofu-init.png) +This has installed all the providers and modules you need for running your code, basically it's downloaded any dependancies. + +#### plan + +Now we are going to run ```tofu plan```, this will test that your code will actually run and compare the code to any previous deployed resources saved in a state file (more on this later). + +```bash +tofu plan +``` + +This command will generate a lot of output, if you get any RED text you have an issue and you'll need to debug. The code in the repository should be fine however, if not please open an issue. + +![tofu plan output](./img/tofu-plan.png) + +#### apply + +Now lets apply this IaC and deploy the following: + +- A VPC +- 6 Subnets + - 3 Public + - 3 Private +- An EC2 instance with a Security Group + - Allows TCP ports 22,80 and 443 ingress + - Allows all egress + +Lets run the following code: + +```bash +tofu apply +``` + +![tofu apply output and prompt](./img/tofu-apply-1.png) + +At the prompt you need to type **yes** in order to actually deploy the infrastructure, anything else will result in the program terminating. Once complete you should see the following output: + +![tofu apply output after sucessfully deploying](./img/tofu-apply-2.png) + +The Outputs seen on the screen are controlled by the ```outputs.tf``` file in the repo. If you browse in the AWS console to **EC2 > Instances** you should see that there is indeed a new EC2 instance running in your account. + +![Running EC2 instance in the aws console](./img/deployed-ec2.png) + +#### destroy + +Right time is money as they say, lets shut this down and stop spending it. Luckily in tofu/terraform this is super easy to do and we can run the following command. Tofu will reference the ```.tfstate``` file and see what it needs to do to shut everything down. + +```bash +tofu destroy +``` + +This command can take a while to run, be patient and it'll do it's job. You'll get prompted along the way yo confirm you really want to delete everything, make sure to answer **yes** again. + +![tofu destroy prompt to continue](./img/tofu-destroy-1.png) + +Once complete, you'll get some confirmation like the picture below: + +![tofu destroy completed](./img/tofu-destroy-2.png) + +> [!Note] +> Don't worry about the warning you'll be ok with the acl not being deleted, it won't cost anything + +### Recap + +What we've learnt during this exercise: + +- How to install terraform/tofu in cloud shell +- terraform/tofu basic commands + - init + - plan + - apply + - destroy + +Now lets move onto the next lab to learn how to customise this and build upon it. \ No newline at end of file