# Your First Terraform Project: Hello World

Now that you've installed and configured Terraform for your environment, it's time to dive into the exciting world of Infrastructure as Code (IaC). In this guide, we'll create a simple yet illustrative Terraform project, echoing the classic programming tradition with a "Hello World" example.

## **Step 1: Setting Up Your Project**

1. **Create a Directory:**
    
    Begin by creating a new directory for your Terraform project. Open your terminal and run:
    
    ```xml
    mkdir terraform_hello_world
    cd terraform_hello_world
    ```
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1700724358551/ae9c57b0-e156-4bd6-9f74-2446a42e96a3.png align="center")
    
2. **Initialize Terraform:**
    
    In your project directory, run the following command to initialize Terraform:
    
    ```xml
    terraform init
    ```
    
    This command sets up the necessary files and downloads any required provider plugins.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1700725325873/a19bae8d-65b7-40a2-85f7-e30240b5144f.png align="center")

## **Step 2: Writing Your First Terraform Configuration**

Create a file named [`main. tf`](http://main.tf) in your project directory. This file will contain the Terraform configuration code.

```xml
main.tf

provider "null" {
  version = "3.1.0"
}

resource "null_resource" "hello_world" {
  provisioner "local-exec" {
    command = "echo 'Hello, Terraform!'"
  }
}
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1700725406644/8da57f27-9e2f-43f6-9320-bcbc145dc6e5.png align="center")

Let's break down what's happening in this simple configuration:

* We're using the `null` provider, a built-in provider that represents no real infrastructure. It's perfect for our "Hello World" example.
    
* The `null_resource` block creates a null resource, again, for demonstration purposes.
    
* Within the `provisioner` block, we use the `local-exec` provisioner to execute a local command. In this case, we're echoing "Hello, Terraform!" to the terminal.
    

## **Step 3: Applying Your Terraform Configuration**

Now that your Terraform configuration is ready, let's apply it:

```xml
terraform apply
```

Terraform will provide an execution plan, outlining the actions it will take. Confirm the plan by typing `yes`. Terraform will then execute the plan, and you should see the "Hello, Terraform!" message in your terminal.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1700725519914/de597e6a-8032-4aa3-b620-8ec207145353.png align="center")

## **Step 4: Destroying Resources**

Once you've had your "Hello, Terraform!" moment, it's essential to clean up resources to avoid unnecessary costs. Run the following command to destroy the resources:

```xml
terraform destroy
```

Confirm the destruction by typing `yes` when prompted.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1700725580176/25a3477d-326f-4ef9-a320-376c67ebe444.png align="center")

## **Conclusion:**

Congratulations! You've just created and applied your first Terraform configuration. While the "Hello World" example may seem trivial, it lays the foundation for more complex infrastructure definitions.

In future blog posts, we'll explore advanced Terraform features, work with real cloud providers, and tackle real-world use cases. Stay tuned for an exciting journey into the depths of Infrastructure as Code with Terraform!
