terraspace 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (332) hide show
  1. checksums.yaml +4 -4
  2. data/.cody/README.md +25 -0
  3. data/.cody/aws/bin/build.sh +13 -0
  4. data/.cody/aws/buildspec.yml +10 -0
  5. data/.cody/aws/project.rb +2 -0
  6. data/.cody/aws/role.rb +6 -0
  7. data/.cody/azurerm/bin/az/configure.sh +23 -0
  8. data/.cody/azurerm/bin/az/install.sh +17 -0
  9. data/.cody/azurerm/bin/build.sh +20 -0
  10. data/.cody/azurerm/bin/install.sh +6 -0
  11. data/.cody/azurerm/buildspec.yml +11 -0
  12. data/.cody/azurerm/project.rb +2 -0
  13. data/.cody/azurerm/role.rb +5 -0
  14. data/.cody/google/bin/build.sh +17 -0
  15. data/.cody/google/bin/gcloud/configure.sh +15 -0
  16. data/.cody/google/bin/gcloud/install.sh +18 -0
  17. data/.cody/google/bin/install.sh +6 -0
  18. data/.cody/google/buildspec.yml +11 -0
  19. data/.cody/google/project.rb +2 -0
  20. data/.cody/google/role.rb +5 -0
  21. data/.cody/shared/script/install.sh +6 -0
  22. data/.cody/shared/script/install/terraform.sh +11 -0
  23. data/.cody/shared/script/install/terraspace.sh +72 -0
  24. data/.cody/unit/bin/build.sh +4 -0
  25. data/.cody/unit/buildspec.yml +9 -0
  26. data/.cody/unit/project.rb +2 -0
  27. data/.github/ISSUE_TEMPLATE.md +7 -0
  28. data/.github/ISSUE_TEMPLATE/bug_report.md +84 -0
  29. data/.github/ISSUE_TEMPLATE/documentation.md +12 -0
  30. data/.github/ISSUE_TEMPLATE/feature_request.md +64 -0
  31. data/.github/ISSUE_TEMPLATE/question.md +14 -0
  32. data/.github/PULL_REQUEST_TEMPLATE.md +50 -0
  33. data/.gitignore +18 -9
  34. data/.pipedream/README.md +25 -0
  35. data/.pipedream/pipeline.rb +17 -0
  36. data/.pipedream/schedule.rb +3 -0
  37. data/.rspec +2 -2
  38. data/CHANGELOG.md +7 -0
  39. data/CONDUCT.md +1 -0
  40. data/CONTRIBUTING.md +1 -0
  41. data/Gemfile +1 -4
  42. data/Guardfile +19 -0
  43. data/LICENSE.txt +201 -21
  44. data/README.md +60 -27
  45. data/Rakefile +10 -2
  46. data/exe/terraspace +14 -0
  47. data/lib/templates/base/project/.gitignore +34 -0
  48. data/lib/templates/base/project/Gemfile.tt +9 -0
  49. data/lib/templates/base/project/Terrafile +14 -0
  50. data/lib/templates/base/project/config/app.rb +4 -0
  51. data/lib/templates/hcl/module/main.tf +1 -0
  52. data/lib/templates/hcl/module/outputs.tf +1 -0
  53. data/lib/templates/hcl/module/variables.tf +1 -0
  54. data/lib/templates/hcl/project/config/terraform/backend.tf.tt +18 -0
  55. data/lib/templates/hcl/project/config/terraform/provider.tf +16 -0
  56. data/lib/templates/hcl/stack/main.tf +1 -0
  57. data/lib/templates/hcl/stack/outputs.tf +1 -0
  58. data/lib/templates/hcl/stack/variables.tf +1 -0
  59. data/lib/templates/plugin/.gitignore +12 -0
  60. data/lib/templates/plugin/.rspec +3 -0
  61. data/lib/templates/plugin/CHANGELOG.md +7 -0
  62. data/lib/templates/plugin/Gemfile +7 -0
  63. data/lib/templates/plugin/LICENSE.txt +201 -0
  64. data/lib/templates/plugin/README.md.tt +34 -0
  65. data/lib/templates/plugin/Rakefile +6 -0
  66. data/{bin/console → lib/templates/plugin/bin/console.tt} +1 -1
  67. data/{bin → lib/templates/plugin/bin}/setup +0 -0
  68. data/lib/templates/plugin/lib/templates/hcl/module/main.tf +1 -0
  69. data/lib/templates/plugin/lib/templates/hcl/module/outputs.tf +1 -0
  70. data/lib/templates/plugin/lib/templates/hcl/module/variables.tf +1 -0
  71. data/lib/templates/plugin/lib/templates/hcl/project/config/terraform/backend.tf.tt +6 -0
  72. data/lib/templates/plugin/lib/templates/hcl/project/config/terraform/provider.tf +3 -0
  73. data/lib/templates/plugin/lib/templates/hcl/stack/main.tf +1 -0
  74. data/lib/templates/plugin/lib/templates/hcl/stack/outputs.tf +1 -0
  75. data/lib/templates/plugin/lib/templates/hcl/stack/variables.tf +1 -0
  76. data/lib/templates/plugin/lib/templates/ruby/module/main.rb +1 -0
  77. data/lib/templates/plugin/lib/templates/ruby/module/outputs.rb +1 -0
  78. data/lib/templates/plugin/lib/templates/ruby/module/variables.rb +1 -0
  79. data/lib/templates/plugin/lib/templates/ruby/project/config/terraform/backend.rb.tt +4 -0
  80. data/lib/templates/plugin/lib/templates/ruby/project/config/terraform/provider.rb +3 -0
  81. data/lib/templates/plugin/lib/templates/ruby/stack/main.rb +1 -0
  82. data/lib/templates/plugin/lib/templates/ruby/stack/outputs.rb +1 -0
  83. data/lib/templates/plugin/lib/templates/ruby/stack/variables.rb +1 -0
  84. data/lib/templates/plugin/lib/templates/test/rspec/module/test/.rspec +3 -0
  85. data/lib/templates/plugin/lib/templates/test/rspec/module/test/Gemfile +9 -0
  86. data/lib/templates/plugin/lib/templates/test/rspec/module/test/spec/fixtures/stack/main.tf +1 -0
  87. data/lib/templates/plugin/lib/templates/test/rspec/module/test/spec/fixtures/stack/outputs.tf +1 -0
  88. data/lib/templates/plugin/lib/templates/test/rspec/module/test/spec/fixtures/stack/variables.tf +1 -0
  89. data/lib/templates/plugin/lib/templates/test/rspec/module/test/spec/main_spec.rb +29 -0
  90. data/lib/templates/plugin/lib/templates/test/rspec/module/test/spec/spec_helper.rb +13 -0
  91. data/lib/templates/plugin/lib/terraspace_plugin_%name%.rb.tt +36 -0
  92. data/lib/templates/plugin/lib/terraspace_plugin_%name%/autoloader.rb.tt +23 -0
  93. data/lib/templates/plugin/lib/terraspace_plugin_%name%/clients.rb.tt +14 -0
  94. data/lib/templates/plugin/lib/terraspace_plugin_%name%/interfaces/backend.rb.tt +12 -0
  95. data/lib/templates/plugin/lib/terraspace_plugin_%name%/interfaces/config.rb.tt +18 -0
  96. data/lib/templates/plugin/lib/terraspace_plugin_%name%/interfaces/expander.rb.tt +15 -0
  97. data/lib/templates/plugin/lib/terraspace_plugin_%name%/interfaces/layer.rb.tt +20 -0
  98. data/lib/templates/plugin/lib/terraspace_plugin_%name%/version.rb.tt +3 -0
  99. data/lib/templates/plugin/spec/spec_helper.rb.tt +14 -0
  100. data/lib/templates/plugin/spec/terraspace_provider_%name%_spec.rb.tt +5 -0
  101. data/lib/templates/plugin/terraspace_plugin_%name%.gemspec.tt +27 -0
  102. data/lib/templates/ruby/module/main.rb +1 -0
  103. data/lib/templates/ruby/module/outputs.rb +1 -0
  104. data/lib/templates/ruby/module/variables.rb +1 -0
  105. data/lib/templates/ruby/project/config/terraform/backend.rb.tt +9 -0
  106. data/lib/templates/ruby/project/config/terraform/provider.rb +7 -0
  107. data/lib/templates/ruby/stack/main.rb +1 -0
  108. data/lib/templates/ruby/stack/outputs.rb +1 -0
  109. data/lib/templates/ruby/stack/variables.rb +1 -0
  110. data/lib/terraspace.rb +22 -1
  111. data/lib/terraspace/app.rb +30 -0
  112. data/lib/terraspace/app/hooks.rb +18 -0
  113. data/lib/terraspace/autoloader.rb +25 -0
  114. data/lib/terraspace/booter.rb +19 -0
  115. data/lib/terraspace/builder.rb +87 -0
  116. data/lib/terraspace/bundle.rb +54 -0
  117. data/lib/terraspace/cli.rb +185 -0
  118. data/lib/terraspace/cli/base.rb +11 -0
  119. data/lib/terraspace/cli/build.rb +7 -0
  120. data/lib/terraspace/cli/bundle.rb +28 -0
  121. data/lib/terraspace/cli/check_setup.rb +73 -0
  122. data/lib/terraspace/cli/clean.rb +12 -0
  123. data/lib/terraspace/cli/commander.rb +14 -0
  124. data/lib/terraspace/cli/help.rb +11 -0
  125. data/lib/terraspace/cli/help/bundle.md +14 -0
  126. data/lib/terraspace/cli/help/completion.md +20 -0
  127. data/lib/terraspace/cli/help/completion_script.md +3 -0
  128. data/lib/terraspace/cli/help/update.md +5 -0
  129. data/lib/terraspace/cli/info.rb +30 -0
  130. data/lib/terraspace/cli/new.rb +32 -0
  131. data/lib/terraspace/cli/new/helper.rb +15 -0
  132. data/lib/terraspace/cli/new/helper/plugin_gem.rb +12 -0
  133. data/lib/terraspace/cli/new/module.rb +26 -0
  134. data/lib/terraspace/cli/new/plugin.rb +20 -0
  135. data/lib/terraspace/cli/new/plugin/helper.rb +15 -0
  136. data/lib/terraspace/cli/new/project.rb +110 -0
  137. data/lib/terraspace/cli/new/sequence.rb +59 -0
  138. data/lib/terraspace/cli/new/source/core.rb +63 -0
  139. data/lib/terraspace/cli/new/source/plugin.rb +20 -0
  140. data/lib/terraspace/cli/new/source/test.rb +26 -0
  141. data/lib/terraspace/cli/new/stack.rb +26 -0
  142. data/lib/terraspace/cli/new/test/base.rb +17 -0
  143. data/lib/terraspace/cli/new/test/bootstrap.rb +18 -0
  144. data/lib/terraspace/cli/new/test/module.rb +15 -0
  145. data/lib/terraspace/cli/new/test/project.rb +15 -0
  146. data/lib/terraspace/cli/seed.rb +9 -0
  147. data/lib/terraspace/cli/summary.rb +61 -0
  148. data/lib/terraspace/cli/test.rb +35 -0
  149. data/lib/terraspace/command.rb +100 -0
  150. data/lib/terraspace/compiler/backend.rb +66 -0
  151. data/lib/terraspace/compiler/basename.rb +10 -0
  152. data/lib/terraspace/compiler/builder.rb +74 -0
  153. data/lib/terraspace/compiler/cleaner.rb +46 -0
  154. data/lib/terraspace/compiler/cleaner/backend_change.rb +45 -0
  155. data/lib/terraspace/compiler/dsl/base.rb +12 -0
  156. data/lib/terraspace/compiler/dsl/meta/local.rb +7 -0
  157. data/lib/terraspace/compiler/dsl/meta/var.rb +7 -0
  158. data/lib/terraspace/compiler/dsl/mod.rb +19 -0
  159. data/lib/terraspace/compiler/dsl/syntax/helpers/common.rb +28 -0
  160. data/lib/terraspace/compiler/dsl/syntax/mod.rb +6 -0
  161. data/lib/terraspace/compiler/dsl/syntax/mod/backend.rb +18 -0
  162. data/lib/terraspace/compiler/dsl/syntax/mod/data.rb +9 -0
  163. data/lib/terraspace/compiler/dsl/syntax/mod/locals.rb +7 -0
  164. data/lib/terraspace/compiler/dsl/syntax/mod/module.rb +10 -0
  165. data/lib/terraspace/compiler/dsl/syntax/mod/output.rb +8 -0
  166. data/lib/terraspace/compiler/dsl/syntax/mod/provider.rb +8 -0
  167. data/lib/terraspace/compiler/dsl/syntax/mod/resource.rb +24 -0
  168. data/lib/terraspace/compiler/dsl/syntax/mod/terraform.rb +8 -0
  169. data/lib/terraspace/compiler/dsl/syntax/mod/variable.rb +12 -0
  170. data/lib/terraspace/compiler/dsl/syntax/tfvar.rb +5 -0
  171. data/lib/terraspace/compiler/dsl/syntax/tfvar/common.rb +7 -0
  172. data/lib/terraspace/compiler/dsl/tfvars.rb +29 -0
  173. data/lib/terraspace/compiler/erb/context.rb +11 -0
  174. data/lib/terraspace/compiler/erb/render.rb +12 -0
  175. data/lib/terraspace/compiler/expander.rb +19 -0
  176. data/lib/terraspace/compiler/strategy/abstract_base.rb +7 -0
  177. data/lib/terraspace/compiler/strategy/mod.rb +15 -0
  178. data/lib/terraspace/compiler/strategy/mod/base.rb +4 -0
  179. data/lib/terraspace/compiler/strategy/mod/pass.rb +7 -0
  180. data/lib/terraspace/compiler/strategy/mod/rb.rb +7 -0
  181. data/lib/terraspace/compiler/strategy/mod/tf.rb +7 -0
  182. data/lib/terraspace/compiler/strategy/tfvar.rb +42 -0
  183. data/lib/terraspace/compiler/strategy/tfvar/base.rb +4 -0
  184. data/lib/terraspace/compiler/strategy/tfvar/layer.rb +110 -0
  185. data/lib/terraspace/compiler/strategy/tfvar/rb.rb +7 -0
  186. data/lib/terraspace/compiler/strategy/tfvar/tfvars.rb +7 -0
  187. data/lib/terraspace/compiler/writer.rb +36 -0
  188. data/lib/terraspace/completer.rb +159 -0
  189. data/lib/terraspace/completer/script.rb +6 -0
  190. data/lib/terraspace/completer/script.sh +10 -0
  191. data/lib/terraspace/core.rb +46 -0
  192. data/lib/terraspace/ext.rb +2 -0
  193. data/lib/terraspace/ext/bundler.rb +7 -0
  194. data/lib/terraspace/ext/core/module.rb +19 -0
  195. data/lib/terraspace/logger.rb +26 -0
  196. data/lib/terraspace/mod.rb +100 -0
  197. data/lib/terraspace/mod/remote.rb +18 -0
  198. data/lib/terraspace/plugin.rb +73 -0
  199. data/lib/terraspace/plugin/backend/interface.rb +8 -0
  200. data/lib/terraspace/plugin/config/interface.rb +27 -0
  201. data/lib/terraspace/plugin/decorator/interface.rb +8 -0
  202. data/lib/terraspace/plugin/expander/generic.rb +5 -0
  203. data/lib/terraspace/plugin/expander/interface.rb +52 -0
  204. data/lib/terraspace/plugin/finder.rb +45 -0
  205. data/lib/terraspace/plugin/meta.rb +29 -0
  206. data/lib/terraspace/plugin/summary/interface.rb +129 -0
  207. data/lib/terraspace/seeder.rb +66 -0
  208. data/lib/terraspace/seeder/actions.rb +24 -0
  209. data/lib/terraspace/seeder/content.rb +84 -0
  210. data/lib/terraspace/seeder/where.rb +30 -0
  211. data/lib/terraspace/terraform/args/custom.rb +47 -0
  212. data/lib/terraspace/terraform/args/default.rb +96 -0
  213. data/lib/terraspace/terraform/args/dsl.rb +30 -0
  214. data/lib/terraspace/terraform/args/shorthands.rb +47 -0
  215. data/lib/terraspace/terraform/hooks/builder.rb +40 -0
  216. data/lib/terraspace/terraform/hooks/dsl.rb +19 -0
  217. data/lib/terraspace/terraform/runner.rb +77 -0
  218. data/lib/terraspace/tester.rb +29 -0
  219. data/lib/terraspace/tester/finder.rb +25 -0
  220. data/lib/terraspace/tester/meta.rb +25 -0
  221. data/lib/terraspace/util.rb +13 -0
  222. data/lib/terraspace/util/logging.rb +7 -0
  223. data/lib/terraspace/util/sh.rb +19 -0
  224. data/lib/terraspace/util/sure.rb +22 -0
  225. data/lib/terraspace/version.rb +1 -1
  226. data/spec/cli_spec.rb +13 -0
  227. data/spec/fixtures/cache_build_dir/variables.tf +9 -0
  228. data/spec/fixtures/initialized/modules.json +29 -0
  229. data/spec/fixtures/orphans/config/backend.rb +8 -0
  230. data/spec/fixtures/orphans/config/provider.rb +3 -0
  231. data/spec/fixtures/orphans/config/providers_different.rb +6 -0
  232. data/spec/fixtures/orphans/config/providers_same.rb +16 -0
  233. data/spec/fixtures/orphans/data/aws_ami.rb +8 -0
  234. data/spec/fixtures/orphans/data/aws_instance.rb +16 -0
  235. data/spec/fixtures/orphans/locals/forum.rb +4 -0
  236. data/spec/fixtures/orphans/locals/qux.rb +7 -0
  237. data/spec/fixtures/orphans/module/core/main.rb +5 -0
  238. data/spec/fixtures/orphans/resource/security_group/hash_example.rb +18 -0
  239. data/spec/fixtures/orphans/resource/vpc/count_example.rb +7 -0
  240. data/spec/fixtures/orphans/terraform/terraform.rb +3 -0
  241. data/spec/fixtures/projects/hcl/aws/app/modules/instance/main.tf +30 -0
  242. data/spec/fixtures/projects/hcl/aws/app/modules/instance/variables.tf +7 -0
  243. data/spec/fixtures/projects/hcl/aws/app/modules/vpc/file.txt +1 -0
  244. data/spec/fixtures/projects/hcl/aws/app/modules/vpc/main.tf +7 -0
  245. data/spec/fixtures/projects/hcl/aws/app/modules/vpc/variables.tf +11 -0
  246. data/spec/fixtures/projects/hcl/aws/app/stacks/core/main.tf +3 -0
  247. data/spec/fixtures/projects/hcl/aws/app/stacks/monolith/main.tf +3 -0
  248. data/spec/fixtures/projects/hcl/aws/config/backend.tf +9 -0
  249. data/spec/fixtures/projects/hcl/aws/config/provider.tf +3 -0
  250. data/spec/fixtures/projects/hcl/google/app/modules/vpc/main.tf +4 -0
  251. data/spec/fixtures/projects/hcl/google/app/modules/vpc/outputs.tf +4 -0
  252. data/spec/fixtures/projects/hcl/google/app/modules/vpc/variables.tf +5 -0
  253. data/spec/fixtures/projects/hcl/google/config/backend.tf +6 -0
  254. data/spec/fixtures/projects/hcl/google/config/provider.tf +0 -0
  255. data/spec/fixtures/projects/ruby/aws/app/modules/existing_backend/backend.rb +7 -0
  256. data/spec/fixtures/projects/ruby/aws/app/modules/existing_backend/main.rb +7 -0
  257. data/spec/fixtures/projects/ruby/aws/app/modules/existing_backend/outputs.rb +4 -0
  258. data/spec/fixtures/projects/ruby/aws/app/modules/existing_backend/variables.rb +9 -0
  259. data/spec/fixtures/projects/ruby/aws/app/modules/instance/main.rb +28 -0
  260. data/spec/fixtures/projects/ruby/aws/app/modules/instance/outputs.rb +3 -0
  261. data/spec/fixtures/projects/ruby/aws/app/modules/instance/variables.rb +7 -0
  262. data/spec/fixtures/projects/ruby/aws/app/modules/security_group/main.rb +16 -0
  263. data/spec/fixtures/projects/ruby/aws/app/modules/security_group/variables.rb +5 -0
  264. data/spec/fixtures/projects/ruby/aws/app/modules/sg_child/main.rb +7 -0
  265. data/spec/fixtures/projects/ruby/aws/app/modules/sg_child/variables.rb +5 -0
  266. data/spec/fixtures/projects/ruby/aws/app/modules/sg_parent/main.rb +14 -0
  267. data/spec/fixtures/projects/ruby/aws/app/modules/sg_parent/variables.rb +3 -0
  268. data/spec/fixtures/projects/ruby/aws/app/modules/vpc/main.rb +7 -0
  269. data/spec/fixtures/projects/ruby/aws/app/modules/vpc/outputs.rb +4 -0
  270. data/spec/fixtures/projects/ruby/aws/app/modules/vpc/variables.rb +9 -0
  271. data/spec/fixtures/projects/ruby/aws/app/modules/wordpress/main.rb +0 -0
  272. data/spec/fixtures/projects/ruby/aws/app/stacks/core/a.tfvars +0 -0
  273. data/spec/fixtures/projects/ruby/aws/app/stacks/core/b.tfvars +1 -0
  274. data/spec/fixtures/projects/ruby/aws/app/stacks/core/main.rb +6 -0
  275. data/spec/fixtures/projects/ruby/aws/app/stacks/core/outputs.rb +4 -0
  276. data/spec/fixtures/projects/ruby/aws/app/stacks/core/variables.rb +2 -0
  277. data/spec/fixtures/projects/ruby/aws/app/stacks/gke/main.rb +0 -0
  278. data/spec/fixtures/projects/ruby/aws/app/stacks/monolith/main.rb +3 -0
  279. data/spec/fixtures/projects/ruby/aws/app/stacks/nested/main.rb +5 -0
  280. data/spec/fixtures/projects/ruby/aws/config/backend.rb +7 -0
  281. data/spec/fixtures/projects/ruby/aws/config/cli/args.rb +11 -0
  282. data/spec/fixtures/projects/ruby/aws/config/cli/hooks.rb +8 -0
  283. data/spec/fixtures/projects/ruby/aws/config/provider.rb +3 -0
  284. data/spec/fixtures/projects/ruby/aws/seed/tfvars/modules/instance/base.rb +1 -0
  285. data/spec/fixtures/projects/ruby/aws/seed/tfvars/modules/instance/dev.rb +1 -0
  286. data/spec/fixtures/projects/ruby/aws/seed/tfvars/modules/instance/prod.rb +0 -0
  287. data/spec/fixtures/projects/ruby/aws/seed/tfvars/modules/security_group/base.rb +1 -0
  288. data/spec/fixtures/projects/ruby/aws/seed/tfvars/modules/security_group/dev.rb +1 -0
  289. data/spec/fixtures/projects/ruby/aws/seed/tfvars/modules/vpc/base.tfvars +2 -0
  290. data/spec/fixtures/projects/ruby/aws/seed/tfvars/modules/vpc/dev.tfvars +1 -0
  291. data/spec/fixtures/projects/ruby/aws/seed/tfvars/modules/vpc/prod.tfvars +1 -0
  292. data/spec/fixtures/projects/ruby/aws/seed/tfvars/stacks/core/base.rb +4 -0
  293. data/spec/fixtures/projects/ruby/aws/seed/tfvars/stacks/core/dev.rb +1 -0
  294. data/spec/fixtures/projects/ruby/aws/seed/tfvars/stacks/core/prod.rb +1 -0
  295. data/spec/fixtures/projects/ruby/aws/vendor/modules/vpc/main.rb +7 -0
  296. data/spec/fixtures/projects/ruby/aws/vendor/modules/vpc/outputs.rb +4 -0
  297. data/spec/fixtures/projects/ruby/aws/vendor/modules/vpc/variables.rb +9 -0
  298. data/spec/fixtures/projects/ruby/google/app/modules/firewall/main.rb +17 -0
  299. data/spec/fixtures/projects/ruby/google/app/modules/network/main.rb +4 -0
  300. data/spec/fixtures/projects/ruby/google/app/modules/vm-simple/main.rb +28 -0
  301. data/spec/fixtures/projects/ruby/google/app/modules/vm/main.rb +32 -0
  302. data/spec/fixtures/projects/ruby/google/app/modules/vm/outputs.rb +3 -0
  303. data/spec/fixtures/projects/ruby/google/app/modules/vm/variables.rb +19 -0
  304. data/spec/fixtures/projects/ruby/google/app/stacks/core/main.rb +5 -0
  305. data/spec/fixtures/projects/ruby/google/config/backend.rb +4 -0
  306. data/spec/fixtures/projects/ruby/google/config/provider.rb +14 -0
  307. data/spec/fixtures/terraform/args/multiple.rb +4 -0
  308. data/spec/fixtures/terraform/args/single.rb +10 -0
  309. data/spec/fixtures/terraform/hooks/multiple.rb +3 -0
  310. data/spec/fixtures/terraform/hooks/single.rb +7 -0
  311. data/spec/spec_helper.rb +32 -0
  312. data/spec/terraspace/compiler/dsl/backend_spec.rb +33 -0
  313. data/spec/terraspace/compiler/dsl/data_spec.rb +30 -0
  314. data/spec/terraspace/compiler/dsl/locals_spec.rb +44 -0
  315. data/spec/terraspace/compiler/dsl/meta/local_spec.rb +10 -0
  316. data/spec/terraspace/compiler/dsl/meta/var_spec.rb +10 -0
  317. data/spec/terraspace/compiler/dsl/module_spec.rb +14 -0
  318. data/spec/terraspace/compiler/dsl/monolith_spec.rb +23 -0
  319. data/spec/terraspace/compiler/dsl/output_spec.rb +22 -0
  320. data/spec/terraspace/compiler/dsl/provider_spec.rb +72 -0
  321. data/spec/terraspace/compiler/dsl/resource/security_group_spec.rb +43 -0
  322. data/spec/terraspace/compiler/dsl/resource_spec.rb +64 -0
  323. data/spec/terraspace/compiler/dsl/terraform_spec.rb +21 -0
  324. data/spec/terraspace/compiler/dsl/variable_spec.rb +28 -0
  325. data/spec/terraspace/provider/expander/generic_spec.rb +30 -0
  326. data/spec/terraspace/seeder/content_spec.rb +49 -0
  327. data/spec/terraspace/seeder_spec.rb +20 -0
  328. data/spec/terraspace/terraform/args/custom_spec.rb +48 -0
  329. data/spec/terraspace/terraform/hooks/builder_spec.rb +35 -0
  330. data/terraspace.gemspec +31 -15
  331. metadata +687 -14
  332. data/.travis.yml +0 -6
@@ -0,0 +1,30 @@
1
+ module Terraspace::Terraform::Args
2
+ module Dsl
3
+ include Shorthands
4
+
5
+ def command(*commands, **props)
6
+ commands.each do |name|
7
+ if shorthand?(name)
8
+ shorthand_commands(name, props)
9
+ else
10
+ each_command(name, props)
11
+ end
12
+ end
13
+ end
14
+ alias_method :commands, :command
15
+
16
+ def shorthand?(name)
17
+ shorthands.key?(name.to_sym)
18
+ end
19
+
20
+ def shorthand_commands(name, props)
21
+ shorthands[name].each do |n|
22
+ each_command(n, props)
23
+ end
24
+ end
25
+
26
+ def each_command(name, props={})
27
+ @commands[name] = props
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,47 @@
1
+ module Terraspace::Terraform::Args
2
+ module Shorthands
3
+ COMMANDS_WITH_INPUT = %w[
4
+ apply
5
+ import
6
+ init
7
+ plan
8
+ refresh
9
+ ]
10
+
11
+ COMMANDS_WITH_LOCKING = %w[
12
+ apply
13
+ destroy
14
+ import
15
+ init
16
+ plan
17
+ refresh
18
+ taint
19
+ untaint
20
+ ]
21
+
22
+ COMMANDS_WITH_PARALLELISM = %w[
23
+ apply
24
+ plan
25
+ destroy
26
+ ]
27
+
28
+ COMMANDS_WITH_VARS = %w[
29
+ apply
30
+ console
31
+ destroy
32
+ import
33
+ plan
34
+ push
35
+ refresh
36
+ ]
37
+
38
+ def shorthands
39
+ {
40
+ with_input: COMMANDS_WITH_INPUT,
41
+ with_locking: COMMANDS_WITH_LOCKING,
42
+ with_parallelism: COMMANDS_WITH_PARALLELISM,
43
+ with_vars: COMMANDS_WITH_VARS,
44
+ }
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,40 @@
1
+ module Terraspace::Terraform::Hooks
2
+ class Builder
3
+ extend Memoist
4
+ include Dsl
5
+ include DslEvaluator
6
+ include Terraspace::Util
7
+
8
+ attr_accessor :name
9
+ def initialize(mod, name)
10
+ @mod, @name = mod, name
11
+ @file = "#{Terraspace.root}/config/cli/hooks.rb"
12
+ @hooks = {before: {}, after: {}}
13
+ end
14
+
15
+ def build
16
+ return @hooks unless File.exist?(@file)
17
+ evaluate_file(@file)
18
+ @hooks.deep_stringify_keys!
19
+ end
20
+ memoize :build
21
+
22
+ def run_hooks
23
+ build
24
+ run_hook("before")
25
+ yield if block_given?
26
+ run_hook("after")
27
+ end
28
+
29
+ def run_hook(type)
30
+ execute = @hooks.dig(type, @name.to_s, "execute")
31
+ return unless execute
32
+
33
+ exit_on_fail = @hooks.dig(type, @name.to_s, "exit_on_fail")
34
+ exit_on_fail = exit_on_fail.nil? ? true : exit_on_fail
35
+
36
+ logger.info "Running #{type} hook"
37
+ sh(execute, exit_on_fail: exit_on_fail)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,19 @@
1
+ module Terraspace::Terraform::Hooks
2
+ module Dsl
3
+ def before(*commands, **props)
4
+ commands.each do |name|
5
+ each_hook(:before, name, props)
6
+ end
7
+ end
8
+
9
+ def after(*commands, **props)
10
+ commands.each do |name|
11
+ each_hook(:after, name, props)
12
+ end
13
+ end
14
+
15
+ def each_hook(type, name, props={})
16
+ @hooks[type][name] = props
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,77 @@
1
+ module Terraspace::Terraform
2
+ class Runner < Terraspace::CLI::Base
3
+ extend Memoist
4
+ include Terraspace::Util
5
+
6
+ attr_reader :name
7
+ def initialize(name, options={})
8
+ @name = name
9
+ super(options)
10
+ end
11
+
12
+ def run
13
+ time_took do
14
+ terraform(name, args)
15
+ end
16
+ end
17
+
18
+ def terraform(name, *args)
19
+ current_dir_message # only show once
20
+
21
+ params = args.flatten.join(' ')
22
+ command = "terraform #{name} #{params}"
23
+ run_hooks(name) do
24
+ sh(command, env: custom.env_vars)
25
+ end
26
+ end
27
+
28
+ @@current_dir_message_shown = false
29
+ def current_dir_message
30
+ return if @@current_dir_message_shown
31
+ logger.info "Current directory: #{Terraspace::Util.pretty_path(@mod.cache_build_dir)}"
32
+ @@current_dir_message_shown = true
33
+ end
34
+
35
+ def run_hooks(name, &block)
36
+ hooks = Hooks::Builder.new(@mod, name)
37
+ hooks.build # build hooks
38
+ hooks.run_hooks(&block)
39
+ end
40
+
41
+ def args
42
+ # base at end in case of redirection. IE: terraform output > /path
43
+ custom.args + custom.var_files + default.args
44
+ end
45
+
46
+ def custom
47
+ Args::Custom.new(@mod, @name)
48
+ end
49
+ memoize :custom
50
+
51
+ def default
52
+ Args::Default.new(@mod, @name, @options)
53
+ end
54
+ memoize :default
55
+
56
+ private
57
+ def time_took
58
+ t1 = Time.now
59
+ yield
60
+ t2 = Time.now
61
+ if %w[apply destroy].include?(@name)
62
+ puts "Time took: #{pretty_time(t2-t1)}"
63
+ end
64
+ end
65
+
66
+ # http://stackoverflow.com/questions/4175733/convert-duration-to-hoursminutesseconds-or-similar-in-rails-3-or-ruby
67
+ def pretty_time(total_seconds)
68
+ minutes = (total_seconds / 60) % 60
69
+ seconds = total_seconds % 60
70
+ if total_seconds < 60
71
+ "#{seconds.to_i}s"
72
+ else
73
+ "#{minutes.to_i}m #{seconds.to_i}s"
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,29 @@
1
+ module Terraspace
2
+ module Tester
3
+ extend Memoist
4
+
5
+ # The tester metadata
6
+ #
7
+ # Example meta:
8
+ #
9
+ # {
10
+ # "rspec" => {root: "/path"}
11
+ # }
12
+ #
13
+ @@meta = {}
14
+ def meta
15
+ @@meta
16
+ end
17
+
18
+ def register(tester, data)
19
+ @@meta[tester] = data
20
+ end
21
+
22
+ def find_with(options={})
23
+ Finder.new.find_with(options)
24
+ end
25
+ memoize :find_with
26
+
27
+ extend self
28
+ end
29
+ end
@@ -0,0 +1,25 @@
1
+ module Terraspace::Tester
2
+ class Finder
3
+ def find_with(options)
4
+ result = if options.key?(:framework)
5
+ find_with_framework(options[:framework])
6
+ else
7
+ raise "Must provide framework_name option."
8
+ end
9
+
10
+ return unless result
11
+ raw = Hash[*result] # convert result to Hash instead of an Array
12
+ Meta.new(raw)
13
+ end
14
+
15
+ def find_with_framework(framework)
16
+ meta.find do |framework_name, data|
17
+ framework_name == framework
18
+ end
19
+ end
20
+
21
+ def meta
22
+ Terraspace::Tester.meta
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ module Terraspace::Tester
2
+ class Meta
3
+ # raw: {"rspec" => {root: "/path"}
4
+ def initialize(raw)
5
+ @raw = raw
6
+ end
7
+
8
+ def name
9
+ name = @raw.keys.first
10
+ unless name
11
+ raise "No tester gem found. Are you sure you have the terraspace test gem configured in your Gemfile?"
12
+ end
13
+ name.camelize
14
+ end
15
+ alias_method :tester, :name
16
+
17
+ def data
18
+ @raw.values.first
19
+ end
20
+
21
+ def root
22
+ data[:root]
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,13 @@
1
+ module Terraspace
2
+ module Util
3
+ include Logging
4
+ include Sh
5
+ include Sure
6
+
7
+ def pretty_path(path)
8
+ ENV['TS_TEST'] ? path : path.sub("#{Terraspace.root}/",'')
9
+ end
10
+
11
+ extend self
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ module Terraspace::Util
2
+ module Logging
3
+ def logger
4
+ Terraspace.logger
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,19 @@
1
+ module Terraspace::Util
2
+ module Sh
3
+ # requires @mod to be set
4
+ def sh(command, options={})
5
+ exit_on_fail = options[:exit_on_fail].nil? ? true : options[:exit_on_fail]
6
+ env = options[:env] || {}
7
+ env.stringify_keys!
8
+
9
+ logger.info "=> #{command}"
10
+ return if ENV['TS_TEST']
11
+
12
+ success = system(env, command, chdir: @mod.cache_build_dir)
13
+ unless success
14
+ logger.info "Error running command: #{command}".color(:red)
15
+ exit $?.exitstatus if exit_on_fail
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ module Terraspace::Util
2
+ module Sure
3
+ def sure?(message="Are you sure?", desc=nil)
4
+ if @options[:yes]
5
+ sure = 'y'
6
+ else
7
+ out = if desc
8
+ "\n#{desc}\n#{message} (y/N) "
9
+ else
10
+ "#{message} (y/N) "
11
+ end
12
+ print out
13
+ sure = $stdin.gets
14
+ end
15
+
16
+ unless sure =~ /^y/
17
+ puts "Whew! Exiting."
18
+ exit 0
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,3 +1,3 @@
1
1
  module Terraspace
2
- VERSION = "0.0.0"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -0,0 +1,13 @@
1
+ describe Terraspace::CLI do
2
+ before(:all) do
3
+ @args = "--from Tung"
4
+ end
5
+
6
+ describe "terraspace" do
7
+ it "up" do
8
+ # ts_root = "spec/fixtures/projects/hcl/aws"
9
+ # out = execute("TS_ROOT=#{ts_root} exe/terraspace up core")
10
+ # puts out
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ variable "project" {
2
+ description = "Project name. IE: test-project"
3
+ type = string
4
+ }
5
+
6
+ variable "name" {
7
+ default = "demo-name"
8
+ type = string
9
+ }
@@ -0,0 +1,29 @@
1
+ {
2
+ "Modules": [
3
+ {
4
+ "Key": "",
5
+ "Source": "",
6
+ "Dir": "."
7
+ },
8
+ {
9
+ "Key": "sg_parent",
10
+ "Source": "../../modules/sg_parent",
11
+ "Dir": "../../modules/sg_parent"
12
+ },
13
+ {
14
+ "Key": "sg_parent.sg_child_test",
15
+ "Source": "git@github.com:boltops-tools/sg_child.git",
16
+ "Dir": ".terraform/modules/sg_parent.sg_child_test"
17
+ },
18
+ {
19
+ "Key": "vpc",
20
+ "Source": "git@github.com:org/aws-vpc.git?ref=master",
21
+ "Dir": ".terraform/modules/vpc"
22
+ },
23
+ {
24
+ "Key": "vpc.aws_security_group",
25
+ "Source": "git@github.com:org/aws-security-group.git?ref=master",
26
+ "Dir": ".terraform/modules/vpc.aws_security_group"
27
+ }
28
+ ]
29
+ }
@@ -0,0 +1,8 @@
1
+ backend("s3",
2
+ bucket: "demo-bucket",
3
+ # hard-code region for spec only
4
+ key: "us-west-2/:ENV/:BUILD_DIR/terraform.tfstate", # variable notation expanded by terraspace IE: us-west-2/dev/modules/vm/terraform.tfstate
5
+ region: "us-west-2",
6
+ encrypt: true,
7
+ dynamodb_table: "terraform_locks",
8
+ )
@@ -0,0 +1,3 @@
1
+ provider("aws",
2
+ region: "us-west-2"
3
+ )