# Tutorial: Deploy an AWS S3 bucket using Terraform

IntelliJ IDEA offers support for managing infrastructure as code with [Terraform](terraform.html), allowing you to define, review, and update cloud resources without leaving the IDE. Tasks such as creating storage for a feature, setting up environments, or keeping configurations consistent across machines and CI pipelines can be handled directly in code instead of through the cloud console.

This tutorial explains how to create an [AWS S3 bucket](https://aws.amazon.com/s3/) using Terraform in IntelliJ IDEA. You will use the IDE features to write and review the configuration, apply it to provision the resource, and then destroy this resource.

## Before you start

Before starting the tutorial, make sure that the following prerequisites are met:

* AWS account. Create and activate an AWS account. For this tutorial, the AWS Free Tier is enough, but a valid payment method is required during the account setup. For more details, refer to the [official documentation](https://docs.aws.amazon.com/accounts/latest/reference/manage-acct-creating.html).

* IAM user with programmatic access. For security reasons, do not use the root account for this tutorial. Instead, in the [AWS Management Console](https://aws.amazon.com/console/), create a new user with programmatic access and attach the `AmazonS3FullAccess` permission policy. > **Note:** > Make sure to save the access key ID and secret access key after user creation. You will need these values for configuring AWS credentials locally.

* AWS CLI. [Install AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) on your machine. You will use it to configure AWS credentials locally and verify access to your account.

## Set up the environment

After creating an IAM user and installing AWS CLI, configure your credentials locally:

Procedure: Configure AWS credentials

1. In the system terminal, run the following command to configure a named profile:

```BASH
aws configure --profile terraform-user
```

By using a named profile, you can manage multiple AWS accounts and configurations on the same machine. The profile name you specify here will be used later in the Terraform configuration.

2. When prompted, enter the following details:

* AWS Access key ID: from the IAM user you created.

* AWS Secret Access Key: from the IAM user you created.

* Default region name: the region where your resources will be created. For example, `us-east-1` or `eu-central-1`. For more details about supported regions, refer to the [official documentation](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.RegionsAndAvailabilityZones.html).

* Default output format: press `Enter` to use the default format (JSON).

3. Verify that the credentials are configured correctly by running:

```BASH
aws sts get-caller-identity --profile terraform-user
```

If the configuration is successful, the command returns details about your IAM user.

> **Tip:**
> AWS CLI stores your credentials locally in the `~/.aws/credentials` file. Terraform will use the specified profile to interact with AWS.

Now that your AWS credentials are configured and verified, launch IntelliJ IDEA and set up your development environment.

Procedure: Install the Terraform and HCL plugin

This functionality relies on the [Terraform and HCL](https://plugins.jetbrains.com/plugin/7808-terraform-and-hcl)  plugin, which   you need to install and enable.

1. Press `Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS)) to open settings and then select `Plugins`.

2. Open the Marketplace tab, find the Terraform and HCL plugin, and click Install (restart the IDE if prompted).

Procedure: Specify the Terraform executable path

To run Terraform commands from the IDE using run configurations, you need to have Terraform installed on your machine.

1. Press `Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS)) to open settings and then select `Tools | Terraform Tools`.

2. In most cases, IntelliJ IDEA detects the path to the Terraform executable automatically. If the IDE does not detect the version and path to the executable, click Detect and Test.

If Terraform is not installed on your machine, click Install.

![Terraform Tools settings](https://resources.jetbrains.com.cn/help/img/idea/2026.2/terraform_tools_settings.png)

3. If necessary, you can specify the path to Terraform manually in the Terraform executable path field.

## Create a new project

Let's create a new empty project to store our Terraform configuration.

This is a basic project that allows you to work with different languages, Java or Kotlin classes without a predefined SDK, which could be useful for adhoc developing, creating mockups, and testing.

Procedure:

1. Launch IntelliJ IDEA.

To start a new project, do one of the following:

* Click New Project on the Welcome screen.

* Select `File | New | Project` from the main menu.

* Click the Project widget in the main window header and select New Project. ![Create a new project using the Project widget](https://resources.jetbrains.com.cn/help/img/idea/2026.2/ij_new_project_from_widget.png)

2. From the list on the left, select Empty Project.

3. In the Name field, type a name of a project.

4. In the Location field, type or select a path to the project location.

5. Select the Create Git repository option to place the new project under version control.

You will be able to do it later at any time.

> **Note:**
> The `.gitignore` file is generated in any case.

6. Click Create.

![Creating a new empty project](https://resources.jetbrains.com.cn/help/img/idea/2026.2/new-empty-project-npw.png)

## Create a Terraform configuration

With your project ready, you can start defining your infrastructure. In Terraform, infrastructure is described using configuration files written in HashiCorp Configuration Language (HCL). Let's create a simple Terraform configuration that defines an AWS S3 bucket.

Procedure: Create a new Terraform file

1. In the   Project tool window  (`Alt+1` (Windows), `⌘ 1` (macOS), `⌘ 1` (IntelliJ IDEA Classic (macOS)), `⌘ 1` (macOS System Shortcuts), `Alt+1` (XWin), `Alt+1` (GNOME), `Alt+1` (KDE), `Alt+1` (Emacs), `Alt+1` (Sublime Text), `⌘ 1` (Sublime Text (macOS)), `Ctrl+1` (NetBeans), `Ctrl+Alt+L` (Visual Studio), `⌘ ⌥ L` (Visual Studio (macOS)), `Alt+1` (Eclipse), `Alt+1` (Eclipse (macOS))) , right-click the project root and select `New | Terraform File`.

2. In the New File dialog, name the new file `main` and select the Configuration file template from the list. Press `Enter`.

![New Terraform Config](https://resources.jetbrains.com.cn/help/img/idea/2026.2/new-terraform-config.png)

IntelliJ IDEA creates the `main.tf` file in the project root and opens it in the editor.

IntelliJ IDEA helps you build a valid Terraform configuration using the smart assistance features. Start building the configuration by defining a provider.

Procedure: Add the AWS provider

1. In the `main.tf` file, start typing the `provider` block:

```HCL
provider ""
```

2. Invoke code completion (`Ctrl+Space` (Windows), `⌃ Space` (macOS), `⌃ Space` (IntelliJ IDEA Classic (macOS)), `⌃ Space` (macOS System Shortcuts), `Ctrl+Space` (XWin), `Ctrl+Space` (GNOME), `Ctrl+Space` (KDE), `Alt+/` (Emacs), `Ctrl+Space` (Sublime Text), `⌃ Space` (Sublime Text (macOS)), `Ctrl+Space` (NetBeans), `Ctrl+Space` (Visual Studio), `⌃ Space` (Visual Studio (macOS)), `Ctrl+Space` (Eclipse), `⌃ Space` (Eclipse (macOS))) and select `aws` from the list of [completion suggestions](terraform.html#completion):

```HCL
provider "aws" {
}
```

As you do this, IntelliJ IDEA also inserts a `terraform` block at the top of the file. This block defines the [required providers](https://developer.hashicorp.com/terraform/language/block/stack/tfcomponent/required_providers) and their versions for the configuration.

After these steps, your configuration should look similar to the following:

```HCL
terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "6.36.0"
    }
  }
}
provider "aws" {
}
```

3. Inside the `provider` block, use code completion to add the `region` and `profile` arguments.

4. Set the argument values, for example:

```HCL
provider "aws" {
  region  = "eu-west-1"
  profile = "terraform-user"
}
```

The `region` determines where Terraform will create your resources, and the `profile` specifies the AWS credentials to use.

> **Tip:**
> IntelliJ IDEA provides [quick documentation](terraform.html#quick-documentation) for available arguments, helping you discover how to configure the provider.

Now that the AWS provider is configured, let's define an S3 bucket resource.

Procedure: Add an S3 bucket resource

1. In the `main.tf` file, start typing `resource`. Then use code completion (`Ctrl+Space` (Windows), `⌃ Space` (macOS), `⌃ Space` (IntelliJ IDEA Classic (macOS)), `⌃ Space` (macOS System Shortcuts), `Ctrl+Space` (XWin), `Ctrl+Space` (GNOME), `Ctrl+Space` (KDE), `Alt+/` (Emacs), `Ctrl+Space` (Sublime Text), `⌃ Space` (Sublime Text (macOS)), `Ctrl+Space` (NetBeans), `Ctrl+Space` (Visual Studio), `⌃ Space` (Visual Studio (macOS)), `Ctrl+Space` (Eclipse), `⌃ Space` (Eclipse (macOS))) to select the `aws_s3_bucket` resource type. Name the resource `tutorial_bucket`. Your configuration should look like this:

```HCL
resource "aws_s3_bucket" "tutorial_bucket" {}
```

2. Inside the `resource` block, start typing `bucket` and use code completion to add the argument. Specify a unique bucket name, for example:

```HCL
resource "aws_s3_bucket" "tutorial_bucket" {
  bucket = "ij-idea-terraform-tutorial-bucket-123"
}
```

> **Warning:**
> The value of the `bucket` argument must be globally unique across all AWS accounts and use lowercase letters, numbers, and hyphens.
>
>
>
> If the name is already in use, Terraform will return an error, so you may need to choose a different name or add a unique suffix. Your bucket name will differ from the example used in the tutorial.

Now that your configuration is ready, you can run Terraform commands to create the S3 bucket.

## Run Terraform

You can run Terraform commands directly from IntelliJ IDEA using gutter icons in the editor or run/debug configurations.

In this section, you will initialize the project, preview the planned changes, apply the configuration to create the S3 bucket, and then remove it to avoid unnecessary costs.

Procedure: Initialize the project

The `terraform init` command initializes the Terraform project, downloads the required providers, and prepares the working directory. It also creates a `.terraform.lock.hcl` file, which records the exact provider versions used in the project and ensures consistent behavior across runs and environments.

1. In the `main.tf` file, click ![Run](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app-client.expui.gutter.run.svg) Run Terraform in the gutter.

2. Select the Init command from the dropdown.

After initializing the project, preview the execution plan Terraform will generate before applying the changes.

In IntelliJ IDEA, you can run Terraform commands using [run/debug configurations](run-debug-configuration.html), which allow you to customize the execution by adding arguments or setting environment variables. In this tutorial, you will add the `-out` argument, which saves the execution plan to a file. This allows you to review the plan and apply the same changes later.

Procedure: Preview the execution plan

1. Go to `Run | Edit Configurations`. Alternatively, press `Alt+Shift+F10` (Windows), `⌃ ⌥ R` (macOS), `⌥ ⇧ F10` (IntelliJ IDEA Classic (macOS)), `⌃ ⌥ R` (macOS System Shortcuts), `Alt+Shift+F10` (XWin), `Alt+Shift+F10` (GNOME), `Alt+Shift+F10` (KDE), `Alt+Shift+F10` (Emacs), `Alt+Shift+F10` (Sublime Text), `⌃ ⌥ R` (Sublime Text (macOS)), `Alt+Shift+F10` (NetBeans), `Ctrl+Alt+Shift+R` (Visual Studio), `⌘ ⌥ ⇧ R` (Visual Studio (macOS)), `Alt+Shift+F10` (Eclipse), `⌃ ⌥ R` (Eclipse (macOS)), then `0` (Windows), `0` (macOS), `0` (IntelliJ IDEA Classic (macOS)), `0` (macOS System Shortcuts), `0` (XWin), `0` (GNOME), `0` (KDE), `0` (Emacs), `0` (Sublime Text), `0` (Sublime Text (macOS)), `0` (NetBeans), `0` (Visual Studio), `0` (Visual Studio (macOS)), `0` (Eclipse), `0` (Eclipse (macOS)).

2. Click (![Add a run/debug configuration](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.general.add.svg)) Add New Configuration and start typing Terraform.

![Terraform run configuration](https://resources.jetbrains.com.cn/help/img/idea/2026.2/terraform_run_configuration.png)

3. Select the Terraform Plan configuration type from the list.

4. Name the run/debug configuration, for example, `Plan S3 Bucket`.

5. In the Program arguments field, specify the `-out=tfplan` argument.

6. Click Run.

The execution plan details are displayed in the Run tool window. At the same time, because we specified the `-out=tfplan` argument, Terraform saved the plan to the `tfplan` file in the project root. After reviewing the plan, you can apply the configuration using this file to create an S3 bucket resource in your AWS account.

Procedure: Apply the configuration

1. Similarly to the [previous procedure](#preview-execution-plan), create a new run/debug configuration. Select the Terraform Apply configuration type from the list.

2. Name the run/debug configuration, for example, `Apply S3 Bucket`.

3. In the Program arguments field, specify the `tfplan` argument.

Terraform will use the execution plan stored in the `tfplan` file when creating the resource.

4. Click Run.

5. After applying the configuration, verify that the S3 bucket was created successfully in the AWS Management Console.

## Clean up

> **Warning:**
> After completing the tutorial, destroy the S3 bucket to avoid unnecessary charges and keep your AWS environment clean. Although we used Free Tier–eligible resources, unused infrastructure can still lead to unexpected costs over time.

Procedure: Destroy the S3 bucket

1. In the `main.tf` file, click ![Run](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app-client.expui.gutter.run.svg) Run Terraform in the gutter.

2. Select the Destroy command from the dropdown.

3. After the process is finished, verify that the S3 bucket has been removed in the AWS Management Console.

## Summary

In this tutorial, you have learned how to:

* Configure the Terraform executable path and set up your AWS environment

* Create a Terraform configuration in IntelliJ IDEA

* Configure the AWS provider and define an S3 bucket resource

* Run Terraform commands using gutter icons and run/debug configurations to initialize, plan, apply, and destroy infrastructure

