Skip to content

Infer terraform resource move and generate "terraform state mv ..." command

Notifications You must be signed in to change notification settings

bigwheel/tfinfermv

Repository files navigation

Terraform infer move tool

CI

What's this ?

An script that infers terraform resource move and generates 'terraform state mv ...' commands.

Installation

Put generate_state_mv.sh and infermv files into your $PATH directory.

 curl https://raw.githubusercontent.com/bigwheel/tfinfermv/master/infermv -o ~/bin/infermv
 curl https://raw.githubusercontent.com/bigwheel/tfinfermv/master/generate_state_mv.sh -o ~/bin/generate_state_mv.sh
 chmod +x ~/bin/infermv ~/bin/generate_state_mv.sh

How to use

  1. Go your Terraform root module
  2. Change your terraform configuration files
  3. Run generate_state_mv.sh {{similarity_threshold - default 1.0}}

For more details, see this test case.

Similarity Threshold

How many property values are needed for same resource determination.

If you change only one name of single resource, property values does not changed. Then you don't have to change Similarity Threshold from 1.0. However, if you change both resource property values and name, resource Similarity must go down under 1.0.

For example, a resource has 8 properties and 2 properties changed, Similarity is (8 - 2) / 8 = 0.75. Therefore no outputs for the resource when similarity_threshould is greater than 0.75.

You can specify any value as similarity_threshold, but I suggest use 0.7 ~ 1.0 value. If you need the value lower than 0.7, you should separate resource move commit and resource property change commit.

How to run test

cd $GIT_ROOT/test
find .. -not -path '*/tmp*' -a -not -path '*/\.*' | entr ./test.bats

About

Infer terraform resource move and generate "terraform state mv ..." command

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published