# Terraform

To support modern GitOps practices Hava has built a provider for Terraform. This will allow teams that utilize Terraform to deploy and manage their cloud environments to use the same tools to manage their integration with Hava. Making it simple to automatically add new cloud environments to Hava as new environments are deployed.

Hava's Terraform provider can be found in the official [HashiCorp Terraform registry](https://registry.terraform.io/providers/teamhava/hava/latest).

## Example Usage

The below example shows how the Terraform provider can be used to configure an AWS account source using a cross account role.

```hcl
terraform {
  required_providers {
    hava = {
      source = "teamhava/hava"
      version = "~> 0.1"
    }

    aws = {
      source = "hashicorp/aws"
      version = "~> 4.39"
    }
  }
}

// Get the ARN for the AWS Read Only Managed Policy
data "aws_iam_policy" "example" {
  name = "ReadOnlyAccess"
}

// Create the role that will be used for cross account role accesss
resource "aws_iam_role" "hava_ro" {
  name                = "hava-read-only-role"
  assume_role_policy  = jsonencode({
      "Version": "2012-10-17",
      "Statement": [
          {
              "Effect": "Allow",
              "Principal": {
                  // Hava CAR account
                  "AWS": "arn:aws:iam::281013829959:root"
              },
              "Action": "sts:AssumeRole",
              "Condition": {
                  "StringEquals": {
                      // unique id for your Hava account, 
                      "sts:ExternalId": var.external_id
                  }
              }
          }
      ]
    })
  
  managed_policy_arns = [data.aws_iam_policy.example.arn]
}

// 
resource "hava_source_aws_car_resource" "example" {
  name        = "Example Source"
  role_arn    = aws_iam_role.hava_ro.arn 
  external_id = var.external_id
}
```

More details on the available providers can be found in the documentation for the Terraform provider on the [HashiCorp Terraform registry](https://registry.terraform.io/providers/teamhava/hava/latest/docs).

## Authentication

The provider relies on the Hava API and requires any requests to be authenticated using an API token.&#x20;

The recommended approach to providing an API token to the terraform provider is by setting the `HAVA_TOKEN` environment variable in the shell you are executing Terraform commands from.

See our [API documentation](https://developer.hava.io/api/authentication) for details on how to generate an API token for your account.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hava.io/integrations/terraform.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
