In this tutorial, you will set up an EC2 instance on Amazon Web Services (AWS). EC2 instances are virtual machines that run on AWS and are commonly used in infrastructure projects.
The requirements
To complete this tutorial, you'll need:
- The Terraform CLI (1.2.0+) is installed.
- The AWS CLI is installed.
- You will need an AWS account and the necessary credentials to build resources.
- Setting the AWS_ACCESS_KEY_ID environment variable will allow you to authenticate the Terraform AWS provider using your IAM credentials.
Log into your AWS portal
- Click on the top right-corner (Username)
- Select
Security credentials
- Click on
Create access key
- Check the "I Understand Box and Create."
Copy the Access Key and Secret key to your VScode Terminal
Press the enter button on every command you input.
- Input aws configure, then follow the instructions and paste your keys, respectively
- Create your own working directory and cd into the directory
Open main.tf in your text editor, paste in the configuration below, and save the file.
For more information on Terraform Block, Terraform Registry
To learn more, reference the provider source documentation.
Initialise the directory.
When you create a new configuration or check out an old configuration from version control, you must initialise the directory using terraform init
.
When a configuration directory is initialised, the providers defined in the configuration, in this example the aws
provider, are downloaded and installed.
Input terraform: fmt, Validate, & apply respectively
- Input yes to complete
Inspect the current state using terraform show
- AWS Active Access Key Confirmation
I hope this article is able to guide you in configuring your infrastructure.
You can follow me up on LinkedIn
Top comments (0)