# Pulumi Related Scripts

## How to split resources of monolith pulumi stack to micro ones

1. cd the pulumi project directory.

2. Dump the exporting file using `pulumi export` command:
```shell
$ pulumi stack export --file ${filename} -s ${stack_name}
# demo: pulumi export --file export.manager_prod.json -s prod
```

3. Split the exported file by eks list.
```shell
$ python ./split_by_eks.py ${path_to_exported_file}
```
The splitted files will be located in `./output` directory,
with every splitted file containing shared resources and naming splitted.${eks_name}.json

4. Mutate the stack of splitted files to target eks.
```shell
$ FOLDER=./output PULUMI_PROJECT=${pulumi_project} SOURCE_STACK=${prod} sh mute_by_eks.sh 
# demo: FOLDER=./output PULUMI_PROJECT=manager SOURCE_STACK=prod sh mute_by_eks.sh 
```

5. Import the mutated file into target stack.
```shell
$ pulumi stack import --file ${mutated_file_path} -s ${stack_name}
# demo:  pulumi stack import --file splitted.ap-northeast-1-f01.json -s prod-ap-northeast-1-f01

$ pulumi stack change-secrets-provider default
```

6. Pulumi refresh & check the resource urn list
```shell
$ pulumi refresh
$ pulumi stack --show-urns -s ${stack_name}
```
