Skip to content

Commit ef790e6

Browse files
authored
feat: improved filtering and support for moved blocks (#9)
1 parent c3a9113 commit ef790e6

File tree

3 files changed

+417
-185
lines changed

3 files changed

+417
-185
lines changed

README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
ℹ️ Currently only supports generating import IDs for AWS resources.
55

6-
`tfblocks` is a utility that generates `import` or `removed` blocks for Terraform resources by reading your Terraform state. These blocks can be especially useful when migrating a large number of resources between different Terraform states as you can define your migrations as code, and safely apply them as normal Terraform changes. They can, however, be a hassle to write by hand - enter `tfblocks`!
6+
`tfblocks` is a utility that generates `import`, `moved`, or `removed` blocks for Terraform resources by reading your Terraform state. These blocks can be especially useful when migrating a large number of resources between different Terraform states as you can define your migrations as code, and safely apply them as normal Terraform changes. They can, however, be a hassle to write by hand - enter `tfblocks`!
77

88
## Quick Start
99

@@ -43,12 +43,14 @@ tfblocks [command] [options] [addresses...]
4343
### Commands
4444
- `import` - Generate import blocks
4545
- `remove` - Generate removed blocks
46+
- `move` - Generate moved blocks
4647
- `list` - Output resource addresses only
4748

4849
### Options
4950
- `--files`, `-f` - Filter resources to those found in specified Terraform files
5051
- `--no-color` - Disable colored output
5152
- `--destroy` - Set destroy = true in removed blocks (only with `remove` command)
53+
- `--supported-providers-only` - Only generate import blocks for providers with import ID generators (currently only AWS)
5254

5355
## Examples
5456
### Generate import blocks for all resources
@@ -68,20 +70,31 @@ terraform show -json | tfblocks import "module.my_module"
6870

6971
### Generate import blocks for a specific resource type
7072
```
71-
terraform show -json | tfblocks import "aws_s3_bucket.*" "module.*.aws_s3_bucket.*" "module[*].aws_s3_bucket.*"
73+
terraform show -json | tfblocks import "*.aws_s3_bucket.*" "aws_s3_bucket.*"
7274
```
7375

7476
### Generate import blocks for resources in specific files
7577
```
7678
terraform show -json | tfblocks import -f "main.tf"
7779
```
7880

81+
### Group generated blocks by source files
82+
By including all Terraform files in a specific directory as context, tfblocks will group all the generated blocks by the source file of the associated resource (this works both for `import`, `move` and `removed`):
83+
```
84+
terraform show -json | tfblocks import -f "*.tf"
85+
```
86+
7987
### Generate removed blocks for all resources
8088
```
8189
terraform show -json | tfblocks remove
8290
```
8391

84-
### List all resource addresses
92+
### Generate moved blocks for all resources
93+
```
94+
terraform show -json | tfblocks move
95+
```
96+
97+
### Count resources in a given file
8598
```
86-
terraform show -json | tfblocks list
99+
terraform show -json | tfblocks list -f main.tf | wc -l
87100
```

0 commit comments

Comments
 (0)