First of all head to [https://aws.amazon.com](https://aws.amazon.com) and sign into your console. The next thing to do is check that you are working inthe correct region. For this lab everything is coded for eu-west-1 (Ireland) so make sure you select the correct region at the top right hand of the page.
![eu-west-1 Ireland Region](./img/eu-west-1.png)
Once in this region we are setup for the following labs.
> [!NOTE]
> We'll be creating infrastructure throughout and AWS does charge for your actual usage
### Open CloudShell
For these labs we are going to use the AWS supplied CloudShell, now you can do this from your own machine, however, you'll need to setup the [AWS CLI tool](https://aws.amazon.com/cli/) and AWS credentials which is beyond the scope of these labs. The nice thing about CloudShell is that it's already configured with your credentials for accessing AWS resources. You also launch this by heading up to the main bar in the AWS console and clicking the icon highlighted below:
![Launch CloudShell](./img/cloudshell.png)
Once launched you can hit the arrow to break the shell out into it's own browser tab. I personally find it easier to work this way. It's also good to know there is no charge to run CloudShell. It'll look a little like this when opened:
![CloudShell in it's own browser window](./img/cloudshell2.png)
Right lets get you setup to run terraform or openTofu! You only need to do one of these so choose your tool of choice. I lean toward using tofu as it's fully open source, but if you want some of the newer features in terraform 1.8.0 and higher the guide is here for you also.
> [!Note]
> Periodically you CloudShell is rebuilt and anything thats not stored in your home directory will be deleted, for this reason the method's below store the tooling in your home directory.
#### Install Terraform
First we are going to install a tool that make's it easy to install the binaries for Terraform. Copy and Paste the below into your CloudShell:
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: