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

# Amazon Web Services - Terraform Setup

> Connect your AWS payer account to nOps with Terraform instead of CloudFormation. Add the module to your own Terraform code and paste the role ARN back into the wizard, or download a full setup where Terraform connects the account for you.

The AWS connect wizard offers two Terraform options next to **CloudFormation** and **Manual IAM**. Both create the same resources in your payer account as the CloudFormation stack: the S3 bucket for your Cost and Usage Report, the Legacy CUR export, an optional CUR 2.0 export, the IAM policies for your permission level, and the cross-account IAM role.

| | **Terraform module** | **Terraform, full setup** |
| - | - | - |
| You do | Add the module to your Terraform, apply it, paste the role ARN into the wizard | Create an onboarding key in the wizard, download a ready configuration, apply it |
| Registers the account in nOps | The wizard, after you paste the role ARN | Terraform, when the apply finishes |
| Wizard steps | Account, CUR Export, IAM Setup, Verify Access | Account, CUR Export, API key, Files, Apply |
| Use it when | You want to add the resources to an existing Terraform project | You want a standalone configuration with no copying back and forth |

> [!NOTE]
>
> **Who can do this:** Only **Admin** users in your nOps organization can connect AWS or create an onboarding key. See [Users and roles](https://help.nops.io/platform/users.md).

This page covers Savings Analysis and Full Platform access. Commitment Management is set up separately. See [AWS Commitment Management setup](https://help.nops.io/aws/commitment-management-setup.md).

***

## Prerequisites

* Terraform 1.6 or later, with credentials for your AWS **payer (management) account**. Child and member accounts are not supported.
* Permission to create IAM policies and roles, S3 buckets, and Cost and Usage Report exports in that account.
* **Cost Explorer** turned on in the payer account. See [Turn on Cost Explorer in your payer account](https://help.nops.io/aws/integration-setup.md#turn-on-cost-explorer-in-your-payer-account).
* Optional: an existing S3 bucket in `us-east-1` for the CUR. AWS only offers CUR exports in `us-east-1`. An existing bucket is never changed, so its bucket policy must already allow `billingreports.amazonaws.com` and `bcm-data-exports.amazonaws.com` to write to it.

***

## Terraform module

**1. Choose the setup method**

Open **Connect Amazon Web Services** from [**Settings > Cloud Provider Integrations**](https://clara.nops.io/settings) and choose **Terraform module**.

**2. Enter your account**

Enter the 12-digit **Payer AWS Account ID** and an **Integration name**, then click **Next**.

**3. Name the CUR bucket and exports**

Enter the S3 bucket name and export names, or select **Use a bucket I already have in us-east-1**. Choose **Savings Analysis** or **Full Platform** as the permission level. The wizard shows a Terraform configuration with your values and the ExternalId filled in.

**4. Apply the configuration**

Copy the configuration into your Terraform project and run:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
terraform init
terraform apply
```

**5. Paste the role ARN**

Run `terraform output -raw role_arn`, paste the value into **Role ARN** in the wizard, then run verification.

***

## Terraform, full setup

In this option, Terraform registers the account with nOps itself. It uses an onboarding key you create in the wizard. The key can only register new AWS accounts. It cannot read, change, or delete anything in nOps.

**1. Choose the setup method**

Open **Connect Amazon Web Services** from [**Settings > Cloud Provider Integrations**](https://clara.nops.io/settings) and choose **Terraform, full setup**.

**2. Enter your account**

Enter the 12-digit **Payer AWS Account ID** and an **Integration name**, then click **Next**.

**3. Name the CUR bucket and exports**

Enter the S3 bucket name and export names, or select **Use a bucket I already have in us-east-1**. Choose **Savings Analysis** or **Full Platform** as the permission level.

**4. Create the onboarding key**

Click **Create API key**. The key is shown **once**. Copy the export command and run it in the shell where you will run Terraform:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
export CLARA_API_KEY=<your key>
```

The key is never written to the generated files. If you lose it, revoke it in the wizard and create another.

**5. Download the files**

Save each file into a new, empty directory:

| File | Contains |
| - | - |
| `main.tf` | The providers, the nOps module, and the registration |
| `variables.tf` | The inputs the configuration takes |
| `terraform.tfvars` | Your values. Nothing secret |
| `secrets.auto.tfvars` | The ExternalId for the IAM role trust policy. Keep it out of version control |
| `.gitignore` | Keeps `secrets.auto.tfvars` and Terraform state out of git |

**6. Apply**

In that directory, with `CLARA_API_KEY` exported, run:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
terraform init
terraform apply
```

Keep the wizard open. The **Apply** step updates when nOps receives the registration and shows the result. Click **Done** once it shows **Connected**.

### What the result means

| The wizard shows | What to do |
| - | - |
| **Connected** | Nothing. nOps registered the account and confirmed access. |
| **Registered, but access could not be confirmed** | Open the integration in **Settings**, see which checks failed, fix them, and verify again. The apply still succeeds, because the integration exists. |
| **Registration failed** | Open the integration in **Settings** to see what went wrong. |
| **This account is already connected** | nOps allows one integration per payer account. Manage the existing one in **Settings**, or disconnect it there first. |
| **Nothing arrived in 15 minutes** | Check the `terraform apply` output and that `CLARA_API_KEY` was exported. You can close the wizard; the integration appears in **Settings** when it is registered. |

### After onboarding

* **Revoke the key** when you are done. You can revoke it in the wizard, and it is no longer needed once the account is registered.
* **Re-running the same configuration** is safe. Terraform already has the resources in its state, so `terraform apply` changes nothing.
* **Registration is create-only.** To change the integration later, or to disconnect it, use **Settings** in nOps. `terraform destroy` removes the AWS resources but leaves the integration in nOps.

***

## Troubleshooting

> [accordion] The apply fails with EntityAlreadyExists
>
> The account already has resources with the same names, for example from the CloudFormation stack or from another Terraform state. The module does not adopt or overwrite them, and nothing is registered with nOps. Remove the existing stack, or import the resources into your state, then apply again.

> [accordion] Verification reports Cost Explorer actions as failing
>
> Cost Explorer has not been turned on in the payer account. See [Turn on Cost Explorer in your payer account](https://help.nops.io/aws/integration-setup.md#turn-on-cost-explorer-in-your-payer-account), then verify again from **Settings**.

> [accordion] The plan fails when I use an existing bucket
>
> The bucket must be in `us-east-1`. Use a bucket in that region, or let the module create one.

For the policies and role the configuration creates, see [Permissions & Resources](https://help.nops.io/aws/permissions-and-resources.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.