# atmos terraform refresh

Use this command to refresh the Terraform state for an Atmos component in a stack, updating it to match the current remote infrastructure.

## Usage

Execute the `terraform refresh` command like this:

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

This command reads the current settings from all managed remote objects and updates the Terraform state to match. This won't modify your infrastructure but will update the state file.

:::info Atmos Enhancements
Atmos enhances the refresh command with:

- Automatic `terraform init` before refreshing
- Workspace selection and management
- **Automatic variable file generation and passing**
- Backend configuration
- Component validation
  :::

## Examples

### Basic Refresh

```shell
# Refresh the state for a component
atmos terraform refresh vpc -s dev
```

### Targeted Refresh

```shell
# Refresh specific resources only
atmos terraform refresh vpc -s dev -target=aws_instance.web
```

### Refresh with Variable Override

```shell
# Refresh with different variable values
atmos terraform refresh vpc -s dev -var="instance_type=t3.large"
```

## Arguments

- **`component` (required)**

  Atmos component name.

## Flags

- **`--stack` / `-s` (required)**

  Atmos stack name where the component is defined.
- **`--skip-init` (optional)**

  Skip running `terraform init` before executing the command.
  ```shell
  atmos terraform refresh vpc -s dev --skip-init
  ```
- **`--dry-run` (optional)**

  Show what would be executed without actually running the command.
  ```shell
  atmos terraform refresh vpc -s dev --dry-run
  ```

:::note
`--ui` (the [streaming UI](/cli/configuration/components/terraform#configuration-reference)
available for `plan`, `apply`, `deploy`, `init`, and `destroy`) is not supported for `refresh`,
since Terraform's `refresh` doesn't emit the structured `-json` output the streaming UI depends
on. Passing `--ui` prints a warning and falls back to standard output.
:::

## Native Terraform Flags

This command supports native `terraform refresh` flags such as `-target=RESOURCE` to refresh specific resources, `-var` to override variables, `-var-file` to specify variable files.

### Default Locking and Concurrency Flags

Instead of retyping flags like `-lock-timeout` on every invocation, declare a default
in [`components.terraform.flags`](/cli/configuration/components/terraform#flags) — globally
in `atmos.yaml`, per stack, or per component. `refresh` supports `lock_timeout`, `lock`,
`parallelism`, and `compact_warnings` (there is no `-refresh` flag on `terraform refresh`
itself — refresh is what the subcommand does). A native flag typed directly on the command
line always wins over a declared default.

## Related Commands

- [`atmos terraform plan`](/cli/commands/terraform/plan) - Generate execution plan
- [`atmos terraform apply`](/cli/commands/terraform/apply) - Apply changes
- [`atmos terraform init`](/cli/commands/terraform/init) - Initialize working directory
