{"id":29416378,"url":"https://github.com/gurpreet2828/terraform-aws-ec2","last_synced_at":"2025-07-11T19:03:06.312Z","repository":{"id":285659352,"uuid":"958909251","full_name":"gurpreet2828/terraform-aws-ec2","owner":"gurpreet2828","description":"This repository contains Terraform configurations to automate the provisioning of AWS infrastructure, specifically the deployment of EC2 instances. It includes step-by-step setup instructions for installing Terraform and AWS CLI on both Linux and Windows, configuring AWS credentials, and deploying infrastructure directly from your local machine","archived":false,"fork":false,"pushed_at":"2025-05-21T00:55:44.000Z","size":1868,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-21T01:52:56.840Z","etag":null,"topics":["automation","aws","aws-cli","aws-ec2","devops","iac","linux","terraform","terraform-aws","terraform-module","vscode"],"latest_commit_sha":null,"homepage":"","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gurpreet2828.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-02T00:51:39.000Z","updated_at":"2025-05-21T00:55:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"f2cf1eea-b6f1-45fa-b098-fae2bd84abbc","html_url":"https://github.com/gurpreet2828/terraform-aws-ec2","commit_stats":null,"previous_names":["gurpreet2828/terraform","gurpreet2828/terraform-aws-ec2"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gurpreet2828/terraform-aws-ec2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gurpreet2828%2Fterraform-aws-ec2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gurpreet2828%2Fterraform-aws-ec2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gurpreet2828%2Fterraform-aws-ec2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gurpreet2828%2Fterraform-aws-ec2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gurpreet2828","download_url":"https://codeload.github.com/gurpreet2828/terraform-aws-ec2/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gurpreet2828%2Fterraform-aws-ec2/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264878580,"owners_count":23677451,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","aws","aws-cli","aws-ec2","devops","iac","linux","terraform","terraform-aws","terraform-module","vscode"],"created_at":"2025-07-11T19:03:04.664Z","updated_at":"2025-07-11T19:03:06.248Z","avatar_url":"https://github.com/gurpreet2828.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Manage AWS Infrastructure with Terraform\n\n## Step 1: Installation of terraform\n\n### **Install Terraform (Linux -Ubuntu)**\n\nRun the following commands\n\n```shell\nwget -O - https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg\necho \"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main\" | sudo tee /etc/apt/sources.list.d/hashicorp.list\n```\n\n```shell\nsudo apt update \u0026\u0026 sudo apt install terraform\n```\n\n### **Install Terraform on Windows**\n\nDownload from the following link\n\nhttps://developer.hashicorp.com/terraform/install\n\ncreate folder named Terraform in C:\\ and extract to C:\\terraform\n\nsearch View Advanced System Setting\n\ngo to Advanced - Environment Variables – System Variables – New\n\nadd c:\\terraform\n\n![Picture14](https://github.com/gurpreet2828/terraform/blob/main/Images/Picture14.png)\n\nGo to cmd and type `terraform –version`\n\nYou will see the following screen and verify the terraform installation\n\n![Picture15](https://github.com/gurpreet2828/terraform/blob/main/Images/Picture15.png)\n\n## Step2: Install AWS CLI\n\n**On windows**\n\nOpen CMD or Power Shell run the following command\n\n```shell\nmsiexec.exe /i https://awscli.amazonaws.com/AWSCLIV2.msi\n```\n\nNote: for silent install use /qn flag\n\n**On Linux**\n\nTo install the AWS CLI, run the following command\n\n```bash\ncurl \"https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip\" -o \"awscliv2.zip\"\nunzip awscliv2.zip\nsudo ./aws/install\n```\n\nRun the following command to check if AWS CLI is installed correctly:\n\n```bash\naws –version\n```\n\nYou see the following output\n\n![Picture16](https://github.com/gurpreet2828/terraform/blob/f4ef582a732d2dc6b5b9e054f7956ffd7ba9f462/Images/Picture16.png)\n\n## Step3: Create AWS account\n\nAfter Creating\n\nClick on account name - Select Security Credentials\n\n![Picture17](https://github.com/gurpreet2828/terraform/blob/f4ef582a732d2dc6b5b9e054f7956ffd7ba9f462/Images/Picture17.png)\n\nClick Create access key.\n\n![Picture18](https://github.com/gurpreet2828/terraform/blob/f4ef582a732d2dc6b5b9e054f7956ffd7ba9f462/Images/Picture18.png)\n\nNote: Download the key file or copy the Access Key ID \u0026 Secret Access Key (Secret Key is shown only once!).\n\n## Step 4: Configure AWS CLI with the New Access Key\n\n```shell\naws configure\n```\n\nIt will prompt you for:\n\n**1. AWS Access Key ID:** Your access key from AWS IAM.\n\n**2. AWS Secret Access Key:** Your secret key from AWS IAM.\n\n**3. Default region name:** (e.g., us-east-1, us-west-2).\n\n**4. Default output format:** (json, table, text — default is json).\n\nAs shown bellow\n\n![Picture1](https://github.com/gurpreet2828/terraform/blob/f4ef582a732d2dc6b5b9e054f7956ffd7ba9f462/Images/Picture1.png)\n\nCheck credentials added to aws configure correctly\n\n```shell\naws sts get-caller-identity\n```\n\nIf your AWS CLI is properly configured, you'll see a response like this:\n\n![Picture2](https://github.com/gurpreet2828/terraform/blob/f4ef582a732d2dc6b5b9e054f7956ffd7ba9f462/Images/Picture2.png)\n\n## Step 5: Install vs code\n\n### Step 6: Install Terraform Extension in VS Code\n\n1. Open VS Code.\n\n2. Go to Extensions (Ctrl+Shift+X).\n\n3. Search for \"HashiCorp Terraform\" and click Install.\n\n4. Once installed, restart VS Code.\n\n![Picture3](https://github.com/gurpreet2828/terraform/blob/f4ef582a732d2dc6b5b9e054f7956ffd7ba9f462/Images/Picture3.png)\n\nNow Open Lab3-Terraform in Visual Studio Code\n\nLaunch VS Code.\n\nClick File → Open Folder → locate the terraform code from your local machine.\n\nSelect your Terraform project directory and open it\n\nYou will see the following screen in vscode\n\n![Picture4](https://github.com/gurpreet2828/terraform/blob/f4ef582a732d2dc6b5b9e054f7956ffd7ba9f462/Images/Picture4.png)\n\n## Step7: Deploy EC2 instance on AWS through Terraform\n\nRun the following commands\n\n### 1. `Terraform init`\n\n- terraform init is a command used in Terraform to initialize a working directory containing Terraform configuration files\n\n- It sets up your environment by configuring the backend, downloading necessary provider plugins, and installing modules, allowing\nyou to then plan, apply, and manage your infrastructure\n\nYou will see the following screen after running Terraform init\n\n![Picture6](https://github.com/gurpreet2828/terraform/blob/f4ef582a732d2dc6b5b9e054f7956ffd7ba9f462/Images/Picture6.png) \n\n### 2. `Terraform validate`\n\n- The terraform validate command checks whether your Terraform configuration is syntactically valid and internally consistent\n\n- Ensures your .tf files are written correctly (Syntax Checking) (valid HCL syntax)\n\n- Verifies references between resources are valid.\n\n- Does not check whether your AWS credentials or resources exist — that happens during plan and apply.\n\n![Picture7](https://github.com/gurpreet2828/terraform/blob/f4ef582a732d2dc6b5b9e054f7956ffd7ba9f462/Images/Picture7.png)\n\n### 3. `Terraform fmt`\n\n- The terraform fmt command automatically formats your Terraform code to follow canonical style conventions.\n\n- Fixes indentation\n\n- Orders attributes consistently\n\n- Makes your .tf files cleaner and easier to read\n\n- Applies to files in the current directory by default\n\n### 4. `Terraform plan`\n\n- terraform plan is a crucial command in Terraform that allows you to preview the changes that Terraform intends to make to your infrastructure based on your current configuration and state\n\n**Generates an Execution Plan:** Terraform produces a detailed plan outlining the proposed actions. This plan shows:\n\n- Which resources will be created (+ symbol).\n\n- Which resources will be modified (~ symbol, showing the before and after values of changed attributes).\n\n- Which resources will be replaced (-/+ symbol, indicating destruction and creation).\n\n- Which resources will be destroyed (- symbol).\n\n![Picture8](https://github.com/gurpreet2828/terraform/blob/f4ef582a732d2dc6b5b9e054f7956ffd7ba9f462/Images/Picture7.png)\n\n### 5. `Terraform plan -out=ec2plan`     -- ec2plan is filename you can rename according to your need\n\nThe terraform plan -out command is used to save the execution plan generated by terraform plan to a file. This is a crucial step for ensuring consistency and automation in your Terraform workflow.\n\n![Picture9](https://github.com/gurpreet2828/terraform/blob/f4ef582a732d2dc6b5b9e054f7956ffd7ba9f462/Images/Picture9.png)\n\n### 6. `Terraform apply`\n\n- terraform apply is the command in Terraform that executes the actions proposed in the execution plan to create, modify, or destroy infrastructure resources. It's the command that actually makes changes to your real-world infrastructure\n\n![Picture10](https://github.com/gurpreet2828/terraform/blob/f4ef582a732d2dc6b5b9e054f7956ffd7ba9f462/Images/Picture10.png)\n\nNow you can access the website from browser using the URL provided in the output\n\n![Picture11](https://github.com/gurpreet2828/terraform/blob/f4ef582a732d2dc6b5b9e054f7956ffd7ba9f462/Images/Picture11.png)\n\n## Step 8: Verifying ec2 instance running on AWS\n\n- Login to aws Account\n\n- Go to EC2 – Instances\n\n![Picture12](https://github.com/gurpreet2828/terraform/blob/f4ef582a732d2dc6b5b9e054f7956ffd7ba9f462/Images/Picture12.png)\n\n## Step 9: Delete all resources\n\n```shell\nTerraform destroy\n```\n\nThe terraform destroy command removes all resources that were created by your Terraform configuration.\n\n```shell\nterraform plan -destroy #for Double-checking what you're destroying\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgurpreet2828%2Fterraform-aws-ec2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgurpreet2828%2Fterraform-aws-ec2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgurpreet2828%2Fterraform-aws-ec2/lists"}