# atmos validate component

Use this command to validate an Atmos component in a stack using JSON Schema and OPA policies.

**Configure Schema Validation**

Learn how to configure JSON Schema and OPA policy paths for validating components.

Configuration Reference[Read more](/cli/configuration/schemas)

## Usage

Execute the `validate component` command like this:

```shell
atmos validate component <component> -s <stack> [options]
```

This command validates an Atmos component in a stack using JSON Schema and OPA policies.

### Path-Based Component Resolution

Atmos supports using filesystem paths instead of component names for convenience:

```shell
# Navigate to component directory
cd components/terraform/vpc

# Use . to reference current directory
atmos validate component . --stack dev
```

This automatically resolves the path to the component name configured in your stack.

**Supported path formats:**

- `.` - Current directory
- `./component` - Relative path from current directory
- `../other-component` - Relative path to sibling directory
- `/absolute/path/to/component` - Absolute path

**Requirements:**

- Must be inside a component directory under the configured base path
- Must specify `--stack` flag
- Component must exist in the specified stack configuration
- **The component path must resolve to a unique component name** - If multiple components in the stack reference the same component path, you must use the unique component name instead of the path

:::warning Path Resolution Limitation
Path-based resolution only works when the component path resolves to a **single unique component** in the stack.

For example, if both `station/1` and `station/2` reference `components/terraform/weather`:

```bash
cd components/terraform/weather
atmos validate component . --stack dev  # ❌ Error: ambiguous - which component?
```

Instead, you must use the unique component names:

```bash
atmos validate component station/1 --stack dev  # ✓ Explicit and unambiguous
atmos validate component station/2 --stack dev  # ✓ Explicit and unambiguous
```

:::

:::tip
Run `atmos validate component --help` to see all the available options
:::

## Schema directory overrides

Use `--schemas-jsonschema-dir` and `--schemas-opa-dir` to select schema base directories for this invocation. These flags override `schemas.jsonschema.base_path` / `schemas.opa.base_path` and their environment variables. Relative directories resolve from the Atmos base path; absolute directories are preserved.

```shell
atmos validate component infra/vpc -s tenant1-ue2-dev \
  --schemas-jsonschema-dir stacks/schemas/jsonschema \
  --schemas-opa-dir stacks/schemas/opa
```

## Examples

### Component Name Examples

```shell
atmos validate component infra/vpc -s tenant1-ue2-dev
atmos validate component infra/vpc -s tenant1-ue2-dev --schema-path vpc/validate-infra-vpc-component.json --schema-type jsonschema
atmos validate component infra/vpc -s tenant1-ue2-dev --schema-path vpc/validate-infra-vpc-component.rego --schema-type opa
atmos validate component infra/vpc -s tenant1-ue2-dev --schema-path vpc/validate-infra-vpc-component.rego --schema-type opa --module-paths catalog/constants
atmos validate component infra/vpc -s tenant1-ue2-dev --schema-path vpc/validate-infra-vpc-component.rego --schema-type opa --module-paths catalog
atmos validate component infra/vpc -s tenant1-ue2-dev --timeout 15
```

### Path-Based Examples

```shell
# Navigate to component directory and use current directory
cd components/terraform/vpc
atmos validate component . --stack dev

# Use relative path
cd components/terraform
atmos validate component ./vpc --stack dev

# Use from project root with relative path
atmos validate component components/terraform/vpc --stack dev

# Combine with validation options
cd components/terraform/vpc
atmos validate component . --stack dev --schema-path vpc-schema.json --schema-type jsonschema
atmos validate component . --stack dev --schema-path vpc-policy.rego --schema-type opa
atmos validate component . --stack dev --timeout 15
```

## Arguments

- **`component` (required)** — Atmos component name or filesystem path.
  Supports both:

  Component names: vpc, infra/vpc, test/test-component
  Filesystem paths: . (current directory), ./vpc, components/terraform/vpc

  When using paths, Atmos automatically resolves the path to the component name based on your stack configuration.

## Flags

- **`--stack` / `-s` (required)** — Atmos stack.
- **`--schema-path` (optional)** — Path to the schema file.Can be an absolute path or a path relative to `schemas.jsonschema.base_path`and `schemas.opa.base_path` defined in `atmos.yaml`.
- **`--schemas-jsonschema-dir` (optional)** — Base directory for JSON Schema files. Overrides `schemas.jsonschema.base_path` and its environment variable. Relative paths resolve from the Atmos base path.
- **`--schemas-opa-dir` (optional)** — Base directory for OPA policies. Overrides `schemas.opa.base_path` and its environment variable. Relative paths resolve from the Atmos base path.
- **`--schema-type` (optional)** — Schema type: `jsonschema` or `opa`.
- **`--module-paths` (optional)** — Comma-separated string of filesystem paths (folders or individual files) to the additional modulesfor schema validation. Each path can be an absolute path or a path relative to`schemas.opa.base_path` defined in `atmos.yaml`.
- **`--timeout` (optional)** — Validation timeout in seconds. Can also be specified in `settings.validation` component config. If not provided, timeout of 20 seconds is used by default.

## Try it out

### demo-opa

Copy the example into a new directory and make it your own:

```shell
atmos init examples/demo-opa
cd demo-opa
```

Evaluate the included OPA policy against dev. This intentionally fails: dev violates the availability-zone and VPC-name rules. No infrastructure is deployed.

```shell
atmos validate component vpc -s dev
```

- [Installation guide](/install)
- [Explore the example](/examples/demo-opa)
- [Initialization and repository settings](/cli/commands/init#examples-and-source-directories)
