เลนส์ Terraform เป็นเครื่องมือ CLI ที่ช่วยให้นักพัฒนามีมุมมองสรุปของทรัพยากร TFSTate
มันจะผลิตตารางที่มีทรัพยากรใน tfstate terraform ที่กำหนดด้วยคอลัมน์ต่อไปนี้:
ตัวอย่าง:
| provider | type | mode | name | module |
| --------------|---------------------|---------|-------------------------------|-------- |
| provider.aws | aws_caller_identity | data | current_user | test |
| provider.aws | aws_dynamodb_table | managed | dynamodb-terraform-state-lock | - |ขณะนี้เครื่องมือรองรับการอ่านไฟล์ tfState จาก ไฟล์ท้องถิ่น หรือ สถานะระยะไกลที่เก็บไว้ใน S3
เกี่ยวกับผลผลิตที่ผลิตมีความเป็นไปได้สามประการ:
.tflens/terraform.tfstate.json.md ในไดเรกทอรีปัจจุบันด้วยตาราง.tflens/terraform.tfstate.json.html ในไดเรกทอรีปัจจุบันด้วยตารางเครื่องมือได้รับการทดสอบด้วยไฟล์ tfState สำหรับเวอร์ชัน Terraform ต่อไปนี้:
เนื่องจากเนื้อหาของ repo นี้เป็นแพ็คเกจ PYPI คุณสามารถติดตั้งได้อย่างง่ายดายโดยใช้ PIP:
pip install tflens➜ tflens --help
usage: tflens [-h] [-f FILE_LOCATION] [-o OUTPUT] [-r REMOTE] [-m FILTER_MODULE] [-n FILTER_NAME] [-t FILTER_TYPE] [-p FILTER_PROVIDER] [-d FILTER_MODE] [-u HTTP_USER] [-w HTTP_PASSWORD] [-v]
Terraform lens is a CLI tool that enables developers have a summarized view of tfstate resources.
optional arguments:
-h, --help show this help message and exit
-f FILE_LOCATION, --file-location FILE_LOCATION
Defines the location (remote or local) of the tfstate file.
Mandatory if remote tfstate is selected.
If empty then use the current_folder/terraform.tfstate
-o OUTPUT, --output OUTPUT
Defines output type (markdown | html).
If empty outputs in terminal
-r REMOTE, --remote REMOTE
Defines if remote (s3 | http) or local tfstate file.
If empty local is used.
When remote is defined, you also need to specify --file-location with the tfstate location
according to the following pattern: bucket-name/tfstate-key
-s SHOW_COLUMNS, --show-columns SHOW_COLUMNS
Comma separated string list with columns to show in output. Default list is: ' provider,type,mode,name,module '
-m FILTER_MODULE, --filter-module FILTER_MODULE
Applies a regular expression to the module field in order to filter the resources list to output
-n FILTER_NAME, --filter-name FILTER_NAME
Applies a regular expression to the name field in order to filter the resources list to output
-t FILTER_TYPE, --filter-type FILTER_TYPE
Applies a regular expression to the type field in order to filter the resources list to output
-p FILTER_PROVIDER, --filter-provider FILTER_PROVIDER
Applies a regular expression to the provider field in order to filter the resources list to output
-d FILTER_MODE, --filter-mode FILTER_MODE
Applies a regular expression to the mode field in order to filter the resources list to output
-u HTTP_USER, --http-user HTTP_USER
User for http remote backend basic auth
-w HTTP_PASSWORD, --http-password HTTP_PASSWORD
Password for http remote backend basic auth
-v, --version
Show program versionดูตารางทรัพยากรสำหรับ tfState ที่อยู่ในระบบไฟล์ในไดเรกทอรี:
➜ tflens
| provider | type | mode | name | module |
| -------------- | --------------------- | --------- | ------------------------------- | -------- |
| provider.aws | aws_caller_identity | data | current_user | test |
| provider.aws | aws_dynamodb_table | managed | dynamodb-terraform-state-lock | - |ดูตารางทรัพยากรสำหรับ tfState ที่อยู่ในระบบไฟล์ในคอลัมน์การลบไดเรกทอรี:
➜ tflens --show-columns " type,mode,name,module "
| type | mode | name | module |
| --------------------- | --------- | ------------------------------- | -------- |
| aws_caller_identity | data | current_user | test |
| aws_dynamodb_table | managed | dynamodb-terraform-state-lock | - |คุณลักษณะนี้สามารถใช้ในการเปลี่ยนลำดับคอลัมน์:
➜ tflens --show-columns " module,name,type "
| module | name | type |
| -------- | ------------------------------- | --------------------- |
| test | current_user | aws_caller_identity |
| - | dynamodb-terraform-state-lock | aws_dynamodb_table |ดูตารางทรัพยากรที่ผ่านการกรองสำหรับ tfState ที่อยู่ในระบบไฟล์ในไดเรกทอรี:
➜ tflens --filter-name " current "
| provider | type | mode | name | module |
| -------------- | --------------------- | --------- | ------------------------------- | -------- |
| provider.aws | aws_caller_identity | data | current_user | test |หรือ:
➜ tflens --filter-module " test "
| provider | type | mode | name | module |
| -------------- | --------------------- | --------- | ------------------------------- | -------- |
| provider.aws | aws_caller_identity | data | current_user | test |หรือ:
➜ tflens --filter-name " current " --filter-module " test "
| provider | type | mode | name | module |
| -------------- | --------------------- | --------- | ------------------------------- | -------- |
| provider.aws | aws_caller_identity | data | current_user | test | ดูตารางทรัพยากรสำหรับ tfState ที่อยู่ในระบบไฟล์ในเส้นทาง dev/terraform.tfstate.json :
➜ tflens --file-location dev/terraform.tfstate.json
| provider | type | mode | name | module |
| -------------- | --------------------- | --------- | ------------------------------- | -------- |
| provider.aws | aws_caller_identity | data | current_user | test |
| provider.aws | aws_dynamodb_table | managed | dynamodb-terraform-state-lock | - |สร้างไฟล์ Markdown พร้อมตารางทรัพยากรสำหรับ tfState ที่อยู่ในระบบไฟล์ในไดเรกทอรี:
➜ tflens --output markdown ดูตารางทรัพยากรสำหรับ tfState ที่อยู่ในถัง S3 ที่เรียกว่า tflens-test-tfstate-bucket :
➜ tflens --file-location tflens-test-tfstate-bucket/common/terraform.tfstate --remote s3