.gitlab-ci(blocking_mode).yml 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. stages:
  2. - checkov-test-files
  3. - tfplan
  4. - checkov-test-tfplan
  5. - tf-apply
  6. #Checkov test terrafrom files
  7. checkov-test-files:
  8. stage: checkov-test-files
  9. allow_failure: false # True for AutoDevOps compatibility
  10. image:
  11. name: bridgecrew/checkov:latest
  12. entrypoint:
  13. - '/usr/bin/env'
  14. - 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
  15. rules:
  16. - if: $SAST_DISABLED
  17. when: never
  18. - if: $CI_COMMIT_BRANCH
  19. exists:
  20. - '**/*.yml'
  21. - '**/*.yaml'
  22. - '**/*.json'
  23. - '**/*.template'
  24. - '**/*.tf'
  25. - '**/serverless.yml'
  26. - '**/serverless.yaml'
  27. script:
  28. # Use `script` to emulate `tty` for colored output.
  29. - script -q -c 'checkov -d . ; echo $? > CKVEXIT'
  30. - exit $(cat CKVEXIT)
  31. #Terraform generate plan
  32. tfplan:
  33. stage: tfplan
  34. allow_failure: false # True for AutoDevOps compatibility
  35. image:
  36. name: hashicorp/terraform:light
  37. entrypoint:
  38. - '/usr/bin/env'
  39. - 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
  40. script:
  41. # Use `script` to emulate `tty` for colored output.
  42. - terraform --version
  43. - cp ./.terraformrc ~/.terraformrc
  44. - terraform init
  45. - terraform plan -out tf.plan
  46. - terraform show -json tf.plan > tf_plan.json
  47. artifacts:
  48. paths:
  49. - tf_plan.json
  50. name: tf_plan.json
  51. #Checkov test terrafrom plan file
  52. checkov-test-tfplan:
  53. stage: checkov-test-tfplan
  54. allow_failure: false # True for AutoDevOps compatibility
  55. image:
  56. name: bridgecrew/checkov:latest
  57. entrypoint:
  58. - '/usr/bin/env'
  59. - 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
  60. rules:
  61. - if: $SAST_DISABLED
  62. when: never
  63. - if: $CI_COMMIT_BRANCH
  64. exists:
  65. - '**/*.yml'
  66. - '**/*.yaml'
  67. - '**/*.json'
  68. - '**/*.template'
  69. - '**/*.tf'
  70. - '**/serverless.yml'
  71. - '**/serverless.yaml'
  72. script:
  73. # Use `script` to emulate `tty` for colored output.
  74. - script -q -c 'checkov -f ./tf_plan.json; echo $? > CKVEXIT'
  75. - exit $(cat CKVEXIT)
  76. #Terraform apply
  77. tf-apply:
  78. stage: tf-apply
  79. allow_failure: false # True for AutoDevOps compatibility
  80. image:
  81. name: hashicorp/terraform:light
  82. entrypoint:
  83. - '/usr/bin/env'
  84. - 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
  85. script:
  86. # Use `script` to emulate `tty` for colored output.
  87. - terraform --version
  88. - cp ./.terraformrc ~/.terraformrc
  89. - terraform init
  90. - terraform plan # change to apply in prod