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

# Terraform

> YAML reference for Terraform services that provision cloud infrastructure from modules in GitHub repos or the Terraform public registry.

Terraform services provision and manage cloud infrastructure using Terraform
modules. Use them to create resources like S3 buckets, databases, and
other cloud infrastructure.

## Build from source

Package Terraform modules from your GitHub repository. Ryvn will package the
Terraform files from your repository and create versioned releases that can be
deployed across environments.

```yaml theme={null}
# yaml-language-server: $schema=https://api.ryvn.app/v1/schemas/resources.json
kind: Service
metadata:
  name: s3-buckets
spec:
  type: terraform
  repo: acme/infra
  build:
    path: modules/s3
```

For Terraform files at the repository root, omit the `path` field or use `.`.

```yaml theme={null}
kind: Service
metadata:
  name: storage
spec:
  type: terraform
  repo: acme/infra
```

## Use public modules

From Terraform Registry:

```yaml theme={null}
kind: Service
metadata:
  name: s3-bucket
spec:
  type: terraform
  source: terraform-aws-modules/s3-bucket/aws
```

> [!WARNING]
>
> Omit `repo` when referencing a module from a Terraform Registry

From Public GitHub repo:

```yaml theme={null}
kind: Service
metadata:
  name: rds
spec:
  type: terraform
  source: github.com/terraform-aws-modules/terraform-aws-rds
```

## Properties

### `name`

`string` — required

Service identifier. Must be lowercase, alphanumeric with hyphens only.

```yaml theme={null}
name: s3-buckets
```

### `labels`

`object` — optional

Key-value labels for grouping and filtering services. Use labels to organize services by team, tier, or any other dimension.

Constraints:

* Maximum 50 labels per service
* Keys must start with an alphanumeric character and contain only alphanumerics, dots, hyphens, and underscores
* Keys and values are each limited to 63 characters

```yaml theme={null}
metadata:
  name: s3-buckets
  labels:
    team: infrastructure
    tier: storage
```

### `type`

`string` — required

Must be `terraform`.

```yaml theme={null}
type: terraform
```

### `repo`

`string` — conditional

GitHub repository in `owner/repo` format. Required when building from source.

```yaml theme={null}
repo: acme/infra
```

### `source`

`string` — conditional

Terraform module source reference. Required when using public modules.
Supports Terraform Registry modules, GitHub, Git repositories, etc. Do not
include version/ref—Ryvn manages versioning.

```yaml theme={null}
# Terraform Registry
source: hashicorp/vpc/aws

# GitHub
source: github.com/org/repo//modules/vpc
```

### `autoApprove`

`boolean` — optional

Auto-approve Terraform plans during deployments. Use with caution in
production environments.

```yaml theme={null}
autoApprove: true
```

### `promotionPipeline`

`string` — optional

Name of promotion pipeline to follow for automated release promotion.

```yaml theme={null}
promotionPipeline: main-pipeline
```

### `maintenanceWindow`

`string` — optional

[Maintenance window](https://ryvn.ai/docs/iac/maintenance-window.md) for this service. Automated deployments will only occur during specified intervals.

```yaml theme={null}
maintenanceWindow: overnight
```

### `build.path`

`string` — optional

Directory containing .tf files, relative to repository root. Defaults to
repository root if not specified. Required when building from source.

```yaml theme={null}
build:
  path: modules/vpc
```

### `build.tagPrefix`

`string` — optional

Git tag prefix for versioning. The version number will be appended to this
prefix. For example, `infra@` creates tags like `infra@0.1.0`.

```yaml theme={null}
build:
  tagPrefix: infra@
```

### `build.branches`

`array` — optional

List of branches that trigger Terraform plans and applies on push. Each entry
has a `name`. When configured, pushing to any listed branch produces a
versioned release on the `branch:{name}` channel. Installations can then
track a specific branch using the `branch` field. Only applies when building
from a GitHub repository (`repo` + `build`), not when using `source`.

Compatible with `promotionPipeline`, but a branch release channel can only
appear once in a pipeline.

```yaml theme={null}
build:
  path: modules/s3
  branches:
    - name: main
    - name: staging
```

## Examples

```yaml theme={null}
# storage.service.yaml
# yaml-language-server: $schema=https://api.ryvn.app/v1/schemas/resources.json
kind: Service
metadata:
  name: storage
spec:
  type: terraform
  repo: acme/infra
  build:
    path: modules/s3
    tagPrefix: storage@

# database.service.yaml
# yaml-language-server: $schema=https://api.ryvn.app/v1/schemas/resources.json
kind: Service
metadata:
  name: database
spec:
  type: terraform
  repo: acme/infra
  build:
    path: modules/rds
    tagPrefix: db@
```

Using public modules:

```yaml theme={null}
# rds.service.yaml
# yaml-language-server: $schema=https://api.ryvn.app/v1/schemas/resources.json
kind: Service
metadata:
  name: rds
spec:
  type: terraform
  source: terraform-aws-modules/rds/aws

# s3-bucket.service.yaml
# yaml-language-server: $schema=https://api.ryvn.app/v1/schemas/resources.json
kind: Service
metadata:
  name: s3-bucket
spec:
  type: terraform
  source: terraform-aws-modules/s3-bucket/aws
```
