atmos icon indicating copy to clipboard operation
atmos copied to clipboard

Allow terraform state migration blocks per stack/workspace

Open nitrocode opened this issue 1 year ago • 0 comments

Describe the Feature

I'd like to migrate existing terraform into atmos, without having to run terraform commands, by taking advantage of import blocks.

Usually this can be done easily without workspaces by adding a migrations.tf file in a terraform directory and applying.

This is impossible to do with atmos without manually copying and pasting a file into the directory, then apply, and then remove the migrations file. This works but prevents us from keeping the migration file in git and gives more incentive to running the import commands instead of using import blocks.

Expected Behavior

A method to allow a migrations file per stack.

Perhaps an optional migrations directory within each component terraform with the following convention.

<base component>/migrations/<stage>/<region>/<component>/*.tf

or

<base component>/migrations/<stage>-<region>-<component>.tf

or

<base component>/migraions/<workspace>.tf


Could be a directory of migration files.

Use Case

I recall having issues once with the eks component if there was a partial apply failure which resulted in 8 resources created without it stored in state. These had to be reimported manually. I used a script at the time. Using a method like this would also ease developer frustration.

Describe Ideal Solution

A migrations directory would need to pull a file or directory of files into the base component directory before the terraform workflow began.

At this point, you could also rename this to be a mixin directory which would allow users to change the terraform code per workspace if needed. The migrations would be one use case of that.

Alternatives Considered

No response

Additional Context

No response

nitrocode avatar Aug 16 '24 04:08 nitrocode