<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/first-terraform-script-for-aws-ec2-instance-on-windows-and-linux-kusa87xrx" -->

---
title: First Terraform Script for AWS EC2 Instance on Windows...
description: A beginner-friendly guide covering Terraform installation and setup on both Windows and Linux systems. Walks through creating AWS EC2 instances using Terraform...
canonical: https://daily.dev/posts/first-terraform-script-for-aws-ec2-instance-on-windows-and-linux-kusa87xrx
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: First Terraform Script for AWS EC2 Instance on Windows and Linux | daily.dev
og:description: A beginner-friendly guide covering Terraform installation and setup on both Windows and Linux systems. Walks through creating AWS EC2 instances using Terraform...
og:url: https://daily.dev/posts/first-terraform-script-for-aws-ec2-instance-on-windows-and-linux-kusa87xrx
og:image: https://api.daily.dev/og/posts/Kusa87xRX.png
og:image:alt: First Terraform Script for AWS EC2 Instance on Windows and Linux
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# First Terraform Script for AWS EC2 Instance on Windows and Linux

**[Collections](https://daily.dev/sources/collections)** · 3 min read · 1 upvotes · 0 comments

## Summary

A beginner-friendly guide covering Terraform installation and setup on both Windows and Linux systems. Walks through creating AWS EC2 instances using Terraform configuration files, including environment setup, credential management, and executing core Terraform commands like init, plan, and apply. Covers troubleshooting common issues and demonstrates the complete workflow from installation to resource provisioning.

## Content

# Introduction
This tutorial provides a comprehensive guide on setting up and executing your first Terraform script on both Windows and Linux environments. We will walk through provisioning AWS EC2 instances using Terraform, demonstrating the process with Visual Studio Code on Windows and directly on a Linux virtual machine hosted on AWS.

## Setting Up Your Environment
### Windows
1. **Install Terraform**: Before getting started, ensure that Terraform is installed on your Windows machine. You can download it from HashiCorp's official website and follow the installation instructions.

2. **Create an EC2 Instance**: Begin by setting up an EC2 instance on AWS to test your Terraform scripts. Configure your AWS credentials, which can be handled via environment variables.

3. **Visual Studio Code Setup**: Use Visual Studio Code as your IDE. Install any necessary extensions to support Terraform syntax and improve productivity.

### Linux
1. **Create and Access Linux VM**: Start by launching an EC2 instance running a Linux distribution. Use SSH to connect to this VM via tools like Git Bash.

2. **Install Terraform**: Use official HashiCorp commands to install Terraform on your Linux VM.

## Writing Your First Terraform Script
Create a new directory for your project, then proceed with the following steps:

1. **Define Providers and Resources**: Write Terraform configuration files (`*.tf`) that define the required providers (such as AWS) and desired resources (like EC2 instances).

2. **Set Up AWS Credentials**: Manage AWS credentials via environment variables for authenticating your requests. This step is crucial for both Windows and Linux environments.

## Executing Terraform Commands
### Common Workflow
1. **Initialize Project**: Use `terraform init` to initialize your project directory and download necessary provider plugins.

2. **Format and Validate**: Ensure your configuration files are correctly formatted with `terraform fmt`, and validate them using `terraform validate`.

3. **Plan and Apply**: Utilize `terraform plan` to preview the actions Terraform will perform, and `terraform apply` to execute the provisioning tasks.

4. **State Management**: After successfully applying, Terraform creates a state file maintaining the resource configurations.

### Additional Linux Steps
1. **Managing Instance Lifecycle**: Easily manage the lifecycle of your Linux VM by stopping and starting it as needed. This helps preserve installed software and minimizes operational costs.

## Troubleshooting
During execution, you may encounter credential issues. Ensure environment variables are set correctly, and check for any typos in your configuration files.

## Conclusion
By following these steps, you can effectively manage AWS infrastructure using Terraform scripts across different platforms. This approach not only automates resource provisioning but also ensures consistency and scalability in your cloud operations.

Deploy your first EC2 instance today and experience the power of Terraform in action!

---

Tags: [#cloud](https://daily.dev/tags/cloud), [#aws](https://daily.dev/tags/aws), [#terraform](https://daily.dev/tags/terraform), [#iac](https://daily.dev/tags/iac), [#aws-ec2](https://daily.dev/tags/aws-ec2)

[View this post on daily.dev](https://daily.dev/posts/first-terraform-script-for-aws-ec2-instance-on-windows-and-linux-kusa87xrx)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"First Terraform Script for AWS EC2 Instance on Windows and Linux","url":"https://daily.dev/posts/first-terraform-script-for-aws-ec2-instance-on-windows-and-linux-kusa87xrx","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/first-terraform-script-for-aws-ec2-instance-on-windows-and-linux-kusa87xrx"},"datePublished":"2025-08-01T10:59:31.282Z","dateModified":"2025-08-01T11:10:23.308Z","description":"A beginner-friendly guide covering Terraform installation and setup on both Windows and Linux systems. Walks through creating AWS EC2 instances using Terraform...","image":"https://i.ytimg.com/vi/1q1DK-jfHjk/sddefault.jpg","thumbnailUrl":"https://i.ytimg.com/vi/1q1DK-jfHjk/sddefault.jpg","isAccessibleForFree":true,"articleSection":"Collections","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Collections","logo":"https://media.daily.dev/image/upload/s--fk_6ycEi--/f_auto,q_auto/v1780996001/logos/collections?_a=BAMAMiWQ0","url":"https://daily.dev/sources/collections"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/first-terraform-script-for-aws-ec2-instance-on-windows-and-linux-kusa87xrx","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"cloud,aws,terraform,iac,aws-ec2","timeRequired":"PT3M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Collections","item":"https://daily.dev/sources/collections"},{"@type":"ListItem","position":3,"name":"First Terraform Script for AWS EC2 Instance on Windows and Linux"}]}
```

