> For the complete documentation index, see [llms.txt](https://docs.projectreclass.org/infrastructure/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.projectreclass.org/infrastructure/terraform-basics.md).

# Terraform Basics

This will be a brief overview on how to create resources in AWS with Terraform

## Set Access Credentials for AWS

Configure your `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` with the following

```
aws configure
```

{% hint style="info" %}
&#x20;Refer to how to access AWS on notes for getting an Access Key and Secret
{% endhint %}

This example terraform code should give you an idea of how to create resources in this case we'll be making an EC2 Instance

{% code title="main.tf" %}

```bash
# Set your provider and region in this case AWS and Ohio 
provider "aws" {
    region = "us-east-2"
}

resource "aws_instance" "my-first-instance" { # resource first then custom name
    ami           = "123gd4df5678a" # image ID is necessary to tell AWS what to build
    instance_type = "t2.nano" # this is the size of the VM. This size is free tier
    key_name      = "My-first-key" # this will tell AWS which key to use, it must already exist
}
    
    # It's important for readability to have equal signs in a resource align
    # Not doing so may cause issues in running this code
    
    # Save and exit this file and run `terraform init` followed by `terraform apply main.tf`
    
```

{% endcode %}

{% hint style="info" %}
`main.tf` is the main file terraform runs by default. Create the `main.tf` file fill it with your Terraform code. Afterwards run: `terraform init` followed by `terraform apply` to create your resources.
{% endhint %}
