Package: tf-cop
Terraform automatic reviewerterraform scripts checker.This package helps you to review your tf script.(ex: confirm add logging rule to all s3 bucket)1 Installation$pipinstalltf_cop2 Usage2.1 cli useat your console$tfcopTERRAFORM_ROOT_PATHREVIEW_BOOK_ROOT_PATH(optional)sample output☁tf_cop[master]⚡tfcoptest[INFO]tf_root_path:test[INFO]rbook_root_path:==========================================================RESOURCEAWS_S3_BUCKET.TEST_TF_REVIEW_BUCKET==========================================================[WARN]desc_checker:descriptionnotuse[ALERT]tag_checker:tagsnotuse==========================================================RESOURCEAWS_S3_BUCKET.TEST_TF_REVIEW_BUCKET2==========================================================[WARN]desc_checker:descriptionnotuse[PASS]tag_checker:passed[PASS]name_checker:passed[PASS]env_checker:passed==========================================================DATAAWS_S3_BUCKET.TEST_DATA_TF_REVIEW_BUCKET==========================================================[PASS]bucket_checker:passed=======================|RESOURCENUM:3||warnNUM:2||alertNUM:1||passNUM:4|=======================2.2 module use2.2.1 do reviewpassterraform root path&review_book root pathimporttf_copif__name__=='__main__':test=tf_cop.TfCop()test.tf_review("./test","./review_book_default")2.2.2 get outputoutput=test.output(color_flg=True)print(output)3 Review_book yaml rule3.1 file name rulereview_book_yaml=resource_name.split("_")[1]+'.yaml'(ex. aws_s3_bucket => s3.yaml)folder structure${REVIEW_BOOK_ROOT_PATH}
├── data
│   ├──s3.yaml
│   └──...
└── resource
    ├── acm.yaml
    ├── api.yaml
    └── ...3.2 key rulekeydescriptionrequiredtitletest titlerequireddescdescription for testoptionmodetest mode (existance|value|nested)requiredkeytest target key (ex. tags)requiredvaluecorrect value regexoptionnestfor nested testoptiontypetest type (ex. alert, warn)required3.2.1 existance testcheck if target key is exist.(ex. description)3.2.2 value testcheck if target value is correct.(ex. name = "(prd|stg|dev)-s3-.*-terraform")3.2.3 nested testtest to nested key_valuetags{Name="${terraform.env}-tf-review-bucket"Env="dev"}3.3 sampleaws_s3_bucket:-title:description_checkerdescription:simple existance checkermode:existancewarn:Truekey:description-title:private_checkerdescription:simple value checkermode:valuekey:aclvalue:private-title:bucket_checkerdescription:simple value regex checkermode:valuekey:bucketvalue:.*-tf-review-bucket.*-title:tag_checkerdescription:nested value checkermode:nestedkey:tagsnest:-title:name_checkerdescription:nested value checkermode:valuekey:Namevalue:.*-tf-review-bucket.*-title:env_checkerdescription:nested value checkermode:valuewarn:Truekey:Envvalue:(dev|stg|prd)-title:if_checkermode:ifkey:loggingnest:title:name_checkermode:existancekey:lifecycle_rule4 Testingpython test.py5 Sample usagetest terraform files using docker.├── Dockerfile
├── main.py
└── requirements.txtFROMpython:3.6RUNapt-getupdateENVLANGja_JP.UTF-8ENVLANGUAGEja_JP:jaENVLC_ALLja_JP.UTF-8ENVTZJST-9RUNpipinstall--upgradepipRUNpipinstall--upgradesetuptoolsWORKDIR/tmpCOPYrequirements.txt./RUNpipinstall-rrequirements.txtCOPY..CMD["python","main.py"]importtf_copif__name__=='__main__':test=tf_cop.TfCop()test.tf_review("./terraform","./review_book")output=test.output(color_flg=True)print(output)setTF_ROOT_PATH&REVIEW_BOOK_PATHdockerbuild-ttf_cop.
dockerrun\-v`pwd`/${TF_ROOT_PATH}:/tmp/terraform\-v`pwd`/${REVIEW_BOOK_PATH}:/tmp/review_book\tf_cop6 Authorys-tydy