0% found this document useful (0 votes)
25 views

Terraform With AWS-3

The document outlines steps to use Terraform to create an EC2 instance on AWS. It involves installing Terraform, configuring AWS access keys, creating a main.tf file with instance configuration, running Terraform init to download plugins, running Terraform plan to preview changes, running Terraform apply to create the instance, and verifying the instance was created in the AWS EC2 management console. Logs and configuration files are referenced for additional details.

Uploaded by

sopan sonar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Terraform With AWS-3

The document outlines steps to use Terraform to create an EC2 instance on AWS. It involves installing Terraform, configuring AWS access keys, creating a main.tf file with instance configuration, running Terraform init to download plugins, running Terraform plan to preview changes, running Terraform apply to create the instance, and verifying the instance was created in the AWS EC2 management console. Logs and configuration files are referenced for additional details.

Uploaded by

sopan sonar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Terraform with AWS

Before we see Terraform in action, first let’s check if we have EC2 instance using below steps,

Step 1: Login to AWS account

Step 2: Search and goto EC2 service.

https://www.linkedin.com/in/themr255/
Terraform with AWS
Step 3: Here you will see if you have any instances present in your account and which of them are
running and other info. And look for the region which is selected, you can change the region if it is
present in other region or you can check EC2 Global View.

And as of now, we don’t have instances in our account.

So now, we’ll create a EC2 instance using terraform and then we’ll see if gets created or not using above
steps.

https://www.linkedin.com/in/themr255/
Terraform with AWS
Terraform In Action
Step 1: Install terraform on your machine and complete the setup.

Step 2: In order to connect to AWS using Terraform, terraform has to successfully authenticate. It is
done with the help of Programmatic API Keys (Access Key and Secret). So we’ll need to create or use the
existing ones for authentication. To do that please check steps given in below doc.

aws_setup_progra
mmatic_access.txt

Step 3: Now we need to set these variables on our CLI, so we can use those for authentication.

If you are using Windows, then use below commands to set these variables -

set AWS_ACCESS_KEY_ID=JKAb************

set AWS_SECRET_ACCESS_KEY=Zasdak***************

If you are using Linux, then use below commands to set these variables -

export AWS_ACCESS_KEY_ID=JKAb************

export AWS_SECRET_ACCESS_KEY=Zasdak***************

Please check below logs for reference.

export_variables_cm
d_output.txt

Step 4: Now create a new file with tf extension, for e.g. main.tf. You can create this file in your current
directory or desired directory.

aws_ec2.tf

https://www.linkedin.com/in/themr255/
Terraform with AWS
Step 5: Now run terraform init command. It initializes a new or existing Terraform configuration. It
downloads the necessary provider plugins and sets up the backend configuration.

Please check below logs for reference.

terraform_init_cmd_
output.txt

Step 6: Now run terraform plan command. It will create an execution plan that shows the changes
Terraform will make to the infrastructure. It compares the desired state in the Terraform configuration
with the current state and displays a list of actions that will be taken.

Please check below logs for reference.

terraform_plan_cmd
_output.txt

Step 7: Now run terraform apply command. It will apply the changes described in the execution plan.
Creates, modifies, or destroys resources to match the desired state defined in the configuration.

Please check below logs for reference.

terraform_apply_cm
d_output.txt

Step 8: Again check the first steps mentioned in top section of document to verify if resource got
created or not.

Goto EC2 service window. And now you can see the EC2 instance got created, so click on it.

https://www.linkedin.com/in/themr255/
Terraform with AWS
And here you can see EC2 instance got created with name ec_instance which we gave in main.tf file

Don’t try to connect to this EC2 instance, as the SSH rule is not added in NSG.

https://www.linkedin.com/in/themr255/

You might also like