Skip to content

Commit

Permalink
docs: update README
Browse files Browse the repository at this point in the history
  • Loading branch information
suzuki-shunsuke committed Dec 21, 2024
1 parent 80479af commit 0f84320
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,11 @@ tfmv -r -j tfmv.jsonnet
tfmv uses [Jsonnet](https://jsonnet.org) to enable you to define a custom rename logic.
You need to define Jsonnet whose input is each resource and output is a new resource name.
tfmv passes an input via External Variables.
The Jsonnet must returns a new resource name.
If the returned value is an empty string or not changed, the resource isn't renamed.
You can access an input by `std.extVar('input')`.

```jsonnet
local input = std.extVar('input');
```

The type of an external variable `input` is as following:

Expand All @@ -112,6 +115,20 @@ The type of an external variable `input` is as following:
}
```

e.g.

```json
{
"file": "foo/main.tf",
"block_type": "resource",
"resource_type": "null_resource",
"name": "foo"
}
```

The Jsonnet must returns a new resource name.
If the returned value is an empty string or not changed, the resource isn't renamed.

### Native Functions

tfmv supports the following [native functions](https://pkg.go.dev/github.com/google/go-jsonnet#NativeFunction).
Expand All @@ -121,7 +138,7 @@ You can executed these functions by `std.native("{native function name}")`.
e.g.

```jsonnet
local contained = std.native("strings.Contains")("hello", "ll"); // true
std.native("strings.Replace")(input.name, "-", "_", -1)[0]
```

For details, please see [Native functions](docs/native-function.md).
Expand Down

0 comments on commit 0f84320

Please sign in to comment.