atmos terraform migrate apply
Use atmos terraform migrate apply to apply a user-authored tfmigrate migration for an Atmos Terraform component.
Usage
atmos terraform migrate apply [component] -s <stack> [options]
Atmos runs the same component preparation as plan: auth, source provisioning, workdir provisioning, generated files, Terraform init, and workspace selection.
Arguments
component- Atmos Terraform component to migrate. Omit when selecting multiple components with
--all,--components,--query, or--affected.
Flags
--stack/-s- Atmos stack where the component is defined.
--identity/-i- Identity to authenticate before resolving the component and running
tfmigrate apply. Environment variable:ATMOS_IDENTITY. --migration- Path to a single
tfmigratemigration file, relative tomigration_dir. Do not include themigration_dirprefix.migration_dirdefaults to./migrationswhen that directory exists in the component, otherwise it defaults to the component root. Omit this flag to lettfmigraterun history mode. Single-file reruns are not inherently idempotent. --tfmigrate-config- Override the
tfmigrateconfig path. Atmos checks, in order: this flag orATMOS_TFMIGRATE_CONFIG, thenTFMIGRATE_CONFIG, then a.tfmigrate.hclfile in the component. When none of these are set, Atmos generates a config that reuses the component's Terraform backend as history storage. --backend-config- Backend config entry passed to
tfmigrate --backend-config. Repeat the flag for multiple entries. --all- Apply the migration for all selected component instances.
--components- Apply the migration for the listed component names.
--query- Apply the migration for component instances matching a YQ expression.
--affected- Apply the migration for affected Terraform components.
--include-dependentsis not supported for migrate yet. --skip-init- Skip the normal Terraform init path before
tfmigrateruns.
Examples
Apply history-mode migrations:
atmos terraform migrate apply s3-bucket -s plat-ue2-dev
Apply with an explicit identity:
atmos terraform migrate apply s3-bucket -s plat-ue2-dev --identity aws-prod
Apply a single-file migration:
atmos terraform migrate apply s3-bucket -s plat-ue2-dev --migration 001_remove_template_provider.hcl
tfmigrate resolves the value relative to the migration_dir in its config. Pass just the filename when migration_dir already points at your migrations directory.
Override the default tfmigrate config path:
atmos terraform migrate apply s3-bucket -s plat-ue2-dev --tfmigrate-config migrations/.tfmigrate.hcl
Components with an S3 or GCS backend get durable history automatically. When none of --tfmigrate-config / ATMOS_TFMIGRATE_CONFIG, TFMIGRATE_CONFIG, or a component .tfmigrate.hcl file is set, Atmos generates a config that stores history in the same bucket as the state. Provide your own config only to customize this behavior, for example:
tfmigrate {
migration_dir = "./tfmigrate"
history {
storage "s3" {
bucket = env.ATMOS_TFMIGRATE_HISTORY_BUCKET
key = env.ATMOS_TFMIGRATE_HISTORY_KEY
region = env.ATMOS_TFMIGRATE_HISTORY_REGION
role_arn = env.ATMOS_TFMIGRATE_HISTORY_ROLE_ARN
}
}
}
Atmos authenticates the component identity before tfmigrate runs. The history storage client then inherits the same environment as the Terraform backend.
Rerun Safety
Use history mode for automation. Single-file tfmigrate apply path.hcl can fail on rerun if state addresses already moved or were removed.