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

# Terraform Provider

> Use the TwexAPI Terraform provider to manage follow, tweet, like, retweet, bookmark, and DM resources as infrastructure.

Use the Terraform provider when you want declarative infrastructure for TwexAPI write actions such as follow, tweet, like, retweet, bookmark, and DM resources. Search, timelines, communities, and other reads stay on the REST API or language SDKs.

| Terraform task | Resource / data source          | REST route                         |
| -------------- | ------------------------------- | ---------------------------------- |
| Read profile   | `data.x-api-scraper_user_about` | `GET /twitter/{screen_name}/about` |
| Read tweet     | `data.x-api-scraper_tweet`      | `POST /twitter/tweets/lookup`      |
| Follow account | `x-api-scraper_follow`          | `POST /twitter/user/follow`        |
| Post tweet     | `x-api-scraper_tweet`           | `POST /twitter/tweets/create`      |
| Send DM        | `x-api-scraper_dm`              | `POST /v3/twitter/send-dm`         |

<Note>
  The Terraform Registry listing is not published yet. Build locally and use a `dev_overrides` block until the provider is published.
</Note>

## Install

Terraform CLI 1.0 or newer.

```hcl theme={null}
terraform {
  required_providers {
    x-api-scraper = {
      source  = "twexapi-dev/x-api-scraper"
      version = "~> 0.1"
    }
  }
}

provider "x-api-scraper" {}
```

Local development override in `~/.terraformrc`:

```hcl theme={null}
provider_installation {
  dev_overrides {
    "twexapi-dev/x-api-scraper" = "/absolute/path/to/terraform-provider-x-api-scraper"
  }
  direct {}
}
```

Then:

```bash theme={null}
go build -o terraform-provider-x-api-scraper
export X_API_SCRAPER_KEY="YOUR_API_KEY"
terraform plan
```

Source: [twexapi-dev/terraform-provider-x-api-scraper](https://github.com/twexapi-dev/terraform-provider-x-api-scraper)

## Authenticate

Prefer environment variables:

```bash theme={null}
export X_API_SCRAPER_KEY="YOUR_API_KEY"
```

Or set `bearer_auth` on the provider. Write resources also need a Twitter cookie or `auth_token`.

Never commit credentials or Terraform state.

## Read a profile

```hcl theme={null}
data "x-api-scraper_user_about" "elon" {
  screen_name = "elonmusk"
}

output "user_id" {
  value = data.x-api-scraper_user_about.elon.user_id
}
```

## Follow an account

```hcl theme={null}
resource "x-api-scraper_follow" "example" {
  username = "elonmusk"
  cookie   = var.twitter_cookie
}
```

## Post a tweet

```hcl theme={null}
resource "x-api-scraper_tweet" "announcement" {
  username      = "example"
  cookie        = var.twitter_cookie
  tweet_content = "Published through the TwexAPI Terraform provider."
}
```

Changing `tweet_content` replaces the resource. Destroy deletes the tweet.

## Like, retweet, or bookmark

```hcl theme={null}
resource "x-api-scraper_like" "example" {
  tweet_id = data.x-api-scraper_tweet.example.tweet_id
  cookie   = var.twitter_cookie
}
```

Destroy reverses the action.

## Send a DM

```hcl theme={null}
resource "x-api-scraper_dm" "hello" {
  recipient = "elonmusk"
  text      = "hello from Terraform"
  cookie    = var.twitter_cookie
}
```

Destroy removes Terraform state only. The API cannot unsend a DM.

## Search and pagination

For tweet search, follower exports, and other paginated reads, use the [Go SDK](/sdks/go), [TypeScript SDK](/sdks/typescript), or [CLI](/sdks/cli) instead of Terraform.

## References

* [SDKs overview](/sdks)
* [Go SDK](/sdks/go) (underlying client)
* [Authentication](/authentication)
* [Source Repository](https://github.com/twexapi-dev/terraform-provider-x-api-scraper)
