terraspace 0.0.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (352) 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 +37 -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 +62 -27
  45. data/Rakefile +10 -2
  46. data/exe/terraspace +14 -0
  47. data/lib/templates/base/git_hook/hook.sh +5 -0
  48. data/lib/templates/base/project/.gitignore +33 -0
  49. data/lib/templates/base/project/Gemfile.tt +9 -0
  50. data/lib/templates/base/project/Terrafile +14 -0
  51. data/lib/templates/base/project/config/app.rb +4 -0
  52. data/lib/templates/base/shim/terraspace +7 -0
  53. data/lib/templates/hcl/module/main.tf +1 -0
  54. data/lib/templates/hcl/module/outputs.tf +1 -0
  55. data/lib/templates/hcl/module/variables.tf +1 -0
  56. data/lib/templates/hcl/project/config/terraform/backend.tf.tt +18 -0
  57. data/lib/templates/hcl/project/config/terraform/provider.tf +16 -0
  58. data/lib/templates/hcl/stack/main.tf +1 -0
  59. data/lib/templates/hcl/stack/outputs.tf +1 -0
  60. data/lib/templates/hcl/stack/variables.tf +1 -0
  61. data/lib/templates/plugin/.gitignore +12 -0
  62. data/lib/templates/plugin/.rspec +3 -0
  63. data/lib/templates/plugin/CHANGELOG.md +7 -0
  64. data/lib/templates/plugin/Gemfile +7 -0
  65. data/lib/templates/plugin/LICENSE.txt +201 -0
  66. data/lib/templates/plugin/README.md.tt +34 -0
  67. data/lib/templates/plugin/Rakefile +6 -0
  68. data/{bin/console → lib/templates/plugin/bin/console.tt} +1 -1
  69. data/{bin → lib/templates/plugin/bin}/setup +0 -0
  70. data/lib/templates/plugin/lib/templates/hcl/module/main.tf +1 -0
  71. data/lib/templates/plugin/lib/templates/hcl/module/outputs.tf +1 -0
  72. data/lib/templates/plugin/lib/templates/hcl/module/variables.tf +1 -0
  73. data/lib/templates/plugin/lib/templates/hcl/project/config/terraform/backend.tf.tt +6 -0
  74. data/lib/templates/plugin/lib/templates/hcl/project/config/terraform/provider.tf +3 -0
  75. data/lib/templates/plugin/lib/templates/hcl/stack/main.tf +1 -0
  76. data/lib/templates/plugin/lib/templates/hcl/stack/outputs.tf +1 -0
  77. data/lib/templates/plugin/lib/templates/hcl/stack/variables.tf +1 -0
  78. data/lib/templates/plugin/lib/templates/ruby/module/main.rb +1 -0
  79. data/lib/templates/plugin/lib/templates/ruby/module/outputs.rb +1 -0
  80. data/lib/templates/plugin/lib/templates/ruby/module/variables.rb +1 -0
  81. data/lib/templates/plugin/lib/templates/ruby/project/config/terraform/backend.rb.tt +4 -0
  82. data/lib/templates/plugin/lib/templates/ruby/project/config/terraform/provider.rb +3 -0
  83. data/lib/templates/plugin/lib/templates/ruby/stack/main.rb +1 -0
  84. data/lib/templates/plugin/lib/templates/ruby/stack/outputs.rb +1 -0
  85. data/lib/templates/plugin/lib/templates/ruby/stack/variables.rb +1 -0
  86. data/lib/templates/plugin/lib/templates/test/rspec/module/test/.rspec +3 -0
  87. data/lib/templates/plugin/lib/templates/test/rspec/module/test/Gemfile +9 -0
  88. data/lib/templates/plugin/lib/templates/test/rspec/module/test/spec/fixtures/stack/main.tf +1 -0
  89. data/lib/templates/plugin/lib/templates/test/rspec/module/test/spec/fixtures/stack/outputs.tf +1 -0
  90. data/lib/templates/plugin/lib/templates/test/rspec/module/test/spec/fixtures/stack/variables.tf +1 -0
  91. data/lib/templates/plugin/lib/templates/test/rspec/module/test/spec/main_spec.rb +29 -0
  92. data/lib/templates/plugin/lib/templates/test/rspec/module/test/spec/spec_helper.rb +13 -0
  93. data/lib/templates/plugin/lib/terraspace_plugin_%name%.rb.tt +36 -0
  94. data/lib/templates/plugin/lib/terraspace_plugin_%name%/autoloader.rb.tt +23 -0
  95. data/lib/templates/plugin/lib/terraspace_plugin_%name%/clients.rb.tt +14 -0
  96. data/lib/templates/plugin/lib/terraspace_plugin_%name%/interfaces/backend.rb.tt +12 -0
  97. data/lib/templates/plugin/lib/terraspace_plugin_%name%/interfaces/config.rb.tt +18 -0
  98. data/lib/templates/plugin/lib/terraspace_plugin_%name%/interfaces/expander.rb.tt +15 -0
  99. data/lib/templates/plugin/lib/terraspace_plugin_%name%/interfaces/layer.rb.tt +20 -0
  100. data/lib/templates/plugin/lib/terraspace_plugin_%name%/version.rb.tt +3 -0
  101. data/lib/templates/plugin/spec/spec_helper.rb.tt +14 -0
  102. data/lib/templates/plugin/spec/terraspace_provider_%name%_spec.rb.tt +5 -0
  103. data/lib/templates/plugin/terraspace_plugin_%name%.gemspec.tt +27 -0
  104. data/lib/templates/ruby/module/main.rb +1 -0
  105. data/lib/templates/ruby/module/outputs.rb +1 -0
  106. data/lib/templates/ruby/module/variables.rb +1 -0
  107. data/lib/templates/ruby/project/config/terraform/backend.rb.tt +9 -0
  108. data/lib/templates/ruby/project/config/terraform/provider.rb +7 -0
  109. data/lib/templates/ruby/stack/main.rb +1 -0
  110. data/lib/templates/ruby/stack/outputs.rb +1 -0
  111. data/lib/templates/ruby/stack/variables.rb +1 -0
  112. data/lib/terraspace.rb +22 -1
  113. data/lib/terraspace/app.rb +36 -0
  114. data/lib/terraspace/app/hooks.rb +18 -0
  115. data/lib/terraspace/autoloader.rb +25 -0
  116. data/lib/terraspace/booter.rb +19 -0
  117. data/lib/terraspace/builder.rb +43 -0
  118. data/lib/terraspace/bundle.rb +54 -0
  119. data/lib/terraspace/cli.rb +202 -0
  120. data/lib/terraspace/cli/base.rb +11 -0
  121. data/lib/terraspace/cli/build/placeholder.rb +40 -0
  122. data/lib/terraspace/cli/bundle.rb +28 -0
  123. data/lib/terraspace/cli/check_setup.rb +73 -0
  124. data/lib/terraspace/cli/clean.rb +12 -0
  125. data/lib/terraspace/cli/cloud.rb +24 -0
  126. data/lib/terraspace/cli/commander.rb +21 -0
  127. data/lib/terraspace/cli/help.rb +11 -0
  128. data/lib/terraspace/cli/help/bundle.md +14 -0
  129. data/lib/terraspace/cli/help/completion.md +20 -0
  130. data/lib/terraspace/cli/help/completion_script.md +3 -0
  131. data/lib/terraspace/cli/help/update.md +5 -0
  132. data/lib/terraspace/cli/info.rb +30 -0
  133. data/lib/terraspace/cli/init.rb +67 -0
  134. data/lib/terraspace/cli/list.rb +13 -0
  135. data/lib/terraspace/cli/new.rb +40 -0
  136. data/lib/terraspace/cli/new/git_hook.rb +33 -0
  137. data/lib/terraspace/cli/new/helper.rb +15 -0
  138. data/lib/terraspace/cli/new/helper/plugin_gem.rb +12 -0
  139. data/lib/terraspace/cli/new/module.rb +26 -0
  140. data/lib/terraspace/cli/new/plugin.rb +20 -0
  141. data/lib/terraspace/cli/new/plugin/helper.rb +15 -0
  142. data/lib/terraspace/cli/new/project.rb +110 -0
  143. data/lib/terraspace/cli/new/sequence.rb +59 -0
  144. data/lib/terraspace/cli/new/shim.rb +58 -0
  145. data/lib/terraspace/cli/new/source/core.rb +63 -0
  146. data/lib/terraspace/cli/new/source/plugin.rb +20 -0
  147. data/lib/terraspace/cli/new/source/test.rb +26 -0
  148. data/lib/terraspace/cli/new/stack.rb +26 -0
  149. data/lib/terraspace/cli/new/test/base.rb +17 -0
  150. data/lib/terraspace/cli/new/test/bootstrap.rb +18 -0
  151. data/lib/terraspace/cli/new/test/module.rb +15 -0
  152. data/lib/terraspace/cli/new/test/project.rb +15 -0
  153. data/lib/terraspace/cli/seed.rb +9 -0
  154. data/lib/terraspace/cli/summary.rb +58 -0
  155. data/lib/terraspace/cli/test.rb +35 -0
  156. data/lib/terraspace/command.rb +100 -0
  157. data/lib/terraspace/compiler/backend.rb +38 -0
  158. data/lib/terraspace/compiler/backend/parser.rb +42 -0
  159. data/lib/terraspace/compiler/basename.rb +10 -0
  160. data/lib/terraspace/compiler/builder.rb +78 -0
  161. data/lib/terraspace/compiler/cleaner.rb +63 -0
  162. data/lib/terraspace/compiler/cleaner/backend_change.rb +45 -0
  163. data/lib/terraspace/compiler/dsl/base.rb +12 -0
  164. data/lib/terraspace/compiler/dsl/meta/local.rb +7 -0
  165. data/lib/terraspace/compiler/dsl/meta/var.rb +7 -0
  166. data/lib/terraspace/compiler/dsl/mod.rb +19 -0
  167. data/lib/terraspace/compiler/dsl/syntax/helpers/common.rb +28 -0
  168. data/lib/terraspace/compiler/dsl/syntax/mod.rb +7 -0
  169. data/lib/terraspace/compiler/dsl/syntax/mod/backend.rb +31 -0
  170. data/lib/terraspace/compiler/dsl/syntax/mod/data.rb +9 -0
  171. data/lib/terraspace/compiler/dsl/syntax/mod/locals.rb +7 -0
  172. data/lib/terraspace/compiler/dsl/syntax/mod/module.rb +10 -0
  173. data/lib/terraspace/compiler/dsl/syntax/mod/output.rb +8 -0
  174. data/lib/terraspace/compiler/dsl/syntax/mod/provider.rb +8 -0
  175. data/lib/terraspace/compiler/dsl/syntax/mod/resource.rb +24 -0
  176. data/lib/terraspace/compiler/dsl/syntax/mod/terraform.rb +8 -0
  177. data/lib/terraspace/compiler/dsl/syntax/mod/variable.rb +12 -0
  178. data/lib/terraspace/compiler/dsl/syntax/tfvar.rb +5 -0
  179. data/lib/terraspace/compiler/dsl/syntax/tfvar/common.rb +7 -0
  180. data/lib/terraspace/compiler/dsl/tfvars.rb +29 -0
  181. data/lib/terraspace/compiler/erb/context.rb +11 -0
  182. data/lib/terraspace/compiler/erb/render.rb +12 -0
  183. data/lib/terraspace/compiler/expander.rb +46 -0
  184. data/lib/terraspace/compiler/strategy/abstract_base.rb +7 -0
  185. data/lib/terraspace/compiler/strategy/mod.rb +15 -0
  186. data/lib/terraspace/compiler/strategy/mod/base.rb +4 -0
  187. data/lib/terraspace/compiler/strategy/mod/pass.rb +7 -0
  188. data/lib/terraspace/compiler/strategy/mod/rb.rb +7 -0
  189. data/lib/terraspace/compiler/strategy/mod/tf.rb +7 -0
  190. data/lib/terraspace/compiler/strategy/tfvar.rb +42 -0
  191. data/lib/terraspace/compiler/strategy/tfvar/base.rb +4 -0
  192. data/lib/terraspace/compiler/strategy/tfvar/layer.rb +110 -0
  193. data/lib/terraspace/compiler/strategy/tfvar/rb.rb +7 -0
  194. data/lib/terraspace/compiler/strategy/tfvar/tfvars.rb +7 -0
  195. data/lib/terraspace/compiler/writer.rb +36 -0
  196. data/lib/terraspace/completer.rb +159 -0
  197. data/lib/terraspace/completer/script.rb +6 -0
  198. data/lib/terraspace/completer/script.sh +10 -0
  199. data/lib/terraspace/core.rb +52 -0
  200. data/lib/terraspace/ext.rb +2 -0
  201. data/lib/terraspace/ext/bundler.rb +7 -0
  202. data/lib/terraspace/ext/core/module.rb +19 -0
  203. data/lib/terraspace/logger.rb +26 -0
  204. data/lib/terraspace/mod.rb +125 -0
  205. data/lib/terraspace/mod/remote.rb +18 -0
  206. data/lib/terraspace/plugin.rb +73 -0
  207. data/lib/terraspace/plugin/backend/interface.rb +8 -0
  208. data/lib/terraspace/plugin/config/interface.rb +27 -0
  209. data/lib/terraspace/plugin/decorator/interface.rb +8 -0
  210. data/lib/terraspace/plugin/expander/generic.rb +5 -0
  211. data/lib/terraspace/plugin/expander/interface.rb +95 -0
  212. data/lib/terraspace/plugin/finder.rb +45 -0
  213. data/lib/terraspace/plugin/infer_provider.rb +15 -0
  214. data/lib/terraspace/plugin/layer/interface.rb +5 -0
  215. data/lib/terraspace/plugin/meta.rb +29 -0
  216. data/lib/terraspace/plugin/summary/interface.rb +130 -0
  217. data/lib/terraspace/seeder.rb +66 -0
  218. data/lib/terraspace/seeder/actions.rb +24 -0
  219. data/lib/terraspace/seeder/content.rb +84 -0
  220. data/lib/terraspace/seeder/where.rb +30 -0
  221. data/lib/terraspace/terraform/api.rb +53 -0
  222. data/lib/terraspace/terraform/api/client.rb +10 -0
  223. data/lib/terraspace/terraform/api/http.rb +106 -0
  224. data/lib/terraspace/terraform/api/var.rb +72 -0
  225. data/lib/terraspace/terraform/api/vars.rb +38 -0
  226. data/lib/terraspace/terraform/api/vars/base.rb +7 -0
  227. data/lib/terraspace/terraform/api/vars/json.rb +14 -0
  228. data/lib/terraspace/terraform/api/vars/rb.rb +21 -0
  229. data/lib/terraspace/terraform/args/custom.rb +47 -0
  230. data/lib/terraspace/terraform/args/default.rb +110 -0
  231. data/lib/terraspace/terraform/args/dsl.rb +30 -0
  232. data/lib/terraspace/terraform/args/shorthands.rb +47 -0
  233. data/lib/terraspace/terraform/cloud.rb +25 -0
  234. data/lib/terraspace/terraform/cloud/workspace.rb +95 -0
  235. data/lib/terraspace/terraform/hooks/builder.rb +40 -0
  236. data/lib/terraspace/terraform/hooks/dsl.rb +19 -0
  237. data/lib/terraspace/terraform/runner.rb +77 -0
  238. data/lib/terraspace/tester.rb +29 -0
  239. data/lib/terraspace/tester/finder.rb +25 -0
  240. data/lib/terraspace/tester/meta.rb +25 -0
  241. data/lib/terraspace/util.rb +13 -0
  242. data/lib/terraspace/util/logging.rb +7 -0
  243. data/lib/terraspace/util/sh.rb +19 -0
  244. data/lib/terraspace/util/sure.rb +22 -0
  245. data/lib/terraspace/version.rb +1 -1
  246. data/spec/cli_spec.rb +13 -0
  247. data/spec/fixtures/cache_dir/variables.tf +9 -0
  248. data/spec/fixtures/initialized/modules.json +29 -0
  249. data/spec/fixtures/orphans/config/backend.rb +8 -0
  250. data/spec/fixtures/orphans/config/provider.rb +3 -0
  251. data/spec/fixtures/orphans/config/providers_different.rb +6 -0
  252. data/spec/fixtures/orphans/config/providers_same.rb +16 -0
  253. data/spec/fixtures/orphans/data/aws_ami.rb +8 -0
  254. data/spec/fixtures/orphans/data/aws_instance.rb +16 -0
  255. data/spec/fixtures/orphans/locals/forum.rb +4 -0
  256. data/spec/fixtures/orphans/locals/qux.rb +7 -0
  257. data/spec/fixtures/orphans/module/core/main.rb +5 -0
  258. data/spec/fixtures/orphans/resource/security_group/hash_example.rb +18 -0
  259. data/spec/fixtures/orphans/resource/vpc/count_example.rb +7 -0
  260. data/spec/fixtures/orphans/terraform/terraform.rb +3 -0
  261. data/spec/fixtures/projects/hcl/aws/app/modules/instance/main.tf +30 -0
  262. data/spec/fixtures/projects/hcl/aws/app/modules/instance/variables.tf +7 -0
  263. data/spec/fixtures/projects/hcl/aws/app/modules/vpc/file.txt +1 -0
  264. data/spec/fixtures/projects/hcl/aws/app/modules/vpc/main.tf +7 -0
  265. data/spec/fixtures/projects/hcl/aws/app/modules/vpc/variables.tf +11 -0
  266. data/spec/fixtures/projects/hcl/aws/app/stacks/core/main.tf +3 -0
  267. data/spec/fixtures/projects/hcl/aws/app/stacks/monolith/main.tf +3 -0
  268. data/spec/fixtures/projects/hcl/aws/config/backend.tf +9 -0
  269. data/spec/fixtures/projects/hcl/aws/config/provider.tf +3 -0
  270. data/spec/fixtures/projects/hcl/google/app/modules/vpc/main.tf +4 -0
  271. data/spec/fixtures/projects/hcl/google/app/modules/vpc/outputs.tf +4 -0
  272. data/spec/fixtures/projects/hcl/google/app/modules/vpc/variables.tf +5 -0
  273. data/spec/fixtures/projects/hcl/google/config/backend.tf +6 -0
  274. data/spec/fixtures/projects/hcl/google/config/provider.tf +0 -0
  275. data/spec/fixtures/projects/ruby/aws/app/modules/existing_backend/backend.rb +7 -0
  276. data/spec/fixtures/projects/ruby/aws/app/modules/existing_backend/main.rb +7 -0
  277. data/spec/fixtures/projects/ruby/aws/app/modules/existing_backend/outputs.rb +4 -0
  278. data/spec/fixtures/projects/ruby/aws/app/modules/existing_backend/variables.rb +9 -0
  279. data/spec/fixtures/projects/ruby/aws/app/modules/instance/main.rb +28 -0
  280. data/spec/fixtures/projects/ruby/aws/app/modules/instance/outputs.rb +3 -0
  281. data/spec/fixtures/projects/ruby/aws/app/modules/instance/variables.rb +7 -0
  282. data/spec/fixtures/projects/ruby/aws/app/modules/security_group/main.rb +16 -0
  283. data/spec/fixtures/projects/ruby/aws/app/modules/security_group/variables.rb +5 -0
  284. data/spec/fixtures/projects/ruby/aws/app/modules/sg_child/main.rb +7 -0
  285. data/spec/fixtures/projects/ruby/aws/app/modules/sg_child/variables.rb +5 -0
  286. data/spec/fixtures/projects/ruby/aws/app/modules/sg_parent/main.rb +14 -0
  287. data/spec/fixtures/projects/ruby/aws/app/modules/sg_parent/variables.rb +3 -0
  288. data/spec/fixtures/projects/ruby/aws/app/modules/vpc/main.rb +7 -0
  289. data/spec/fixtures/projects/ruby/aws/app/modules/vpc/outputs.rb +4 -0
  290. data/spec/fixtures/projects/ruby/aws/app/modules/vpc/variables.rb +9 -0
  291. data/spec/fixtures/projects/ruby/aws/app/modules/wordpress/main.rb +0 -0
  292. data/spec/fixtures/projects/ruby/aws/app/stacks/core/a.tfvars +0 -0
  293. data/spec/fixtures/projects/ruby/aws/app/stacks/core/b.tfvars +1 -0
  294. data/spec/fixtures/projects/ruby/aws/app/stacks/core/main.rb +6 -0
  295. data/spec/fixtures/projects/ruby/aws/app/stacks/core/outputs.rb +4 -0
  296. data/spec/fixtures/projects/ruby/aws/app/stacks/core/variables.rb +2 -0
  297. data/spec/fixtures/projects/ruby/aws/app/stacks/gke/main.rb +0 -0
  298. data/spec/fixtures/projects/ruby/aws/app/stacks/monolith/main.rb +3 -0
  299. data/spec/fixtures/projects/ruby/aws/app/stacks/nested/main.rb +5 -0
  300. data/spec/fixtures/projects/ruby/aws/config/backend.rb +7 -0
  301. data/spec/fixtures/projects/ruby/aws/config/cli/args.rb +11 -0
  302. data/spec/fixtures/projects/ruby/aws/config/cli/hooks.rb +8 -0
  303. data/spec/fixtures/projects/ruby/aws/config/provider.rb +3 -0
  304. data/spec/fixtures/projects/ruby/aws/seed/tfvars/modules/instance/base.rb +1 -0
  305. data/spec/fixtures/projects/ruby/aws/seed/tfvars/modules/instance/dev.rb +1 -0
  306. data/spec/fixtures/projects/ruby/aws/seed/tfvars/modules/instance/prod.rb +0 -0
  307. data/spec/fixtures/projects/ruby/aws/seed/tfvars/modules/security_group/base.rb +1 -0
  308. data/spec/fixtures/projects/ruby/aws/seed/tfvars/modules/security_group/dev.rb +1 -0
  309. data/spec/fixtures/projects/ruby/aws/seed/tfvars/modules/vpc/base.tfvars +2 -0
  310. data/spec/fixtures/projects/ruby/aws/seed/tfvars/modules/vpc/dev.tfvars +1 -0
  311. data/spec/fixtures/projects/ruby/aws/seed/tfvars/modules/vpc/prod.tfvars +1 -0
  312. data/spec/fixtures/projects/ruby/aws/seed/tfvars/stacks/core/base.rb +4 -0
  313. data/spec/fixtures/projects/ruby/aws/seed/tfvars/stacks/core/dev.rb +1 -0
  314. data/spec/fixtures/projects/ruby/aws/seed/tfvars/stacks/core/prod.rb +1 -0
  315. data/spec/fixtures/projects/ruby/aws/vendor/modules/vpc/main.rb +7 -0
  316. data/spec/fixtures/projects/ruby/aws/vendor/modules/vpc/outputs.rb +4 -0
  317. data/spec/fixtures/projects/ruby/aws/vendor/modules/vpc/variables.rb +9 -0
  318. data/spec/fixtures/projects/ruby/google/app/modules/firewall/main.rb +17 -0
  319. data/spec/fixtures/projects/ruby/google/app/modules/network/main.rb +4 -0
  320. data/spec/fixtures/projects/ruby/google/app/modules/vm-simple/main.rb +28 -0
  321. data/spec/fixtures/projects/ruby/google/app/modules/vm/main.rb +32 -0
  322. data/spec/fixtures/projects/ruby/google/app/modules/vm/outputs.rb +3 -0
  323. data/spec/fixtures/projects/ruby/google/app/modules/vm/variables.rb +19 -0
  324. data/spec/fixtures/projects/ruby/google/app/stacks/core/main.rb +5 -0
  325. data/spec/fixtures/projects/ruby/google/config/backend.rb +4 -0
  326. data/spec/fixtures/projects/ruby/google/config/provider.rb +14 -0
  327. data/spec/fixtures/terraform/args/multiple.rb +4 -0
  328. data/spec/fixtures/terraform/args/single.rb +10 -0
  329. data/spec/fixtures/terraform/hooks/multiple.rb +3 -0
  330. data/spec/fixtures/terraform/hooks/single.rb +7 -0
  331. data/spec/spec_helper.rb +32 -0
  332. data/spec/terraspace/compiler/dsl/backend_spec.rb +33 -0
  333. data/spec/terraspace/compiler/dsl/data_spec.rb +30 -0
  334. data/spec/terraspace/compiler/dsl/locals_spec.rb +44 -0
  335. data/spec/terraspace/compiler/dsl/meta/local_spec.rb +10 -0
  336. data/spec/terraspace/compiler/dsl/meta/var_spec.rb +10 -0
  337. data/spec/terraspace/compiler/dsl/module_spec.rb +14 -0
  338. data/spec/terraspace/compiler/dsl/monolith_spec.rb +23 -0
  339. data/spec/terraspace/compiler/dsl/output_spec.rb +22 -0
  340. data/spec/terraspace/compiler/dsl/provider_spec.rb +72 -0
  341. data/spec/terraspace/compiler/dsl/resource/security_group_spec.rb +43 -0
  342. data/spec/terraspace/compiler/dsl/resource_spec.rb +64 -0
  343. data/spec/terraspace/compiler/dsl/terraform_spec.rb +21 -0
  344. data/spec/terraspace/compiler/dsl/variable_spec.rb +28 -0
  345. data/spec/terraspace/provider/expander/generic_spec.rb +30 -0
  346. data/spec/terraspace/seeder/content_spec.rb +49 -0
  347. data/spec/terraspace/seeder_spec.rb +20 -0
  348. data/spec/terraspace/terraform/args/custom_spec.rb +48 -0
  349. data/spec/terraspace/terraform/hooks/builder_spec.rb +35 -0
  350. data/terraspace.gemspec +32 -15
  351. metadata +721 -14
  352. data/.travis.yml +0 -6
@@ -0,0 +1,15 @@
1
+ module Terraspace::Plugin
2
+ module InferProvider
3
+ # Examples:
4
+ # TerraspacePluginAws => aws
5
+ # TerraspacePluginAzurerm => azurerm
6
+ # TerraspacePluginGoogle => google
7
+ #
8
+ # If multiple clouds used in a single Terraspace project. The TS_PROVIDER_EXPANSION env var provides a way to
9
+ # change it. Can possibly use config hooks to set different values based on the module being deployed:
10
+ # https://terraspace.cloud/docs/config/hooks/
11
+ def provider
12
+ ENV['TS_PROVIDER'] || self.class.to_s.split('::').first.sub('TerraspacePlugin','').underscore
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ module Terraspace::Plugin::Layer
2
+ module Interface
3
+ include Terraspace::Plugin::InferProvider
4
+ end
5
+ end
@@ -0,0 +1,29 @@
1
+ module Terraspace::Plugin
2
+ class Meta
3
+ # raw: {"aws" => {root: "/path", backend: "s3"}
4
+ def initialize(raw)
5
+ @raw = raw
6
+ end
7
+
8
+ def name
9
+ name = @raw.keys.first
10
+ unless name
11
+ raise "No plugin found. Are you sure you have the terraspace_plugin_XXX configured in your Gemfile?"
12
+ end
13
+ name.camelize
14
+ end
15
+ alias_method :plugin, :name
16
+
17
+ def data
18
+ @raw.values.first
19
+ end
20
+
21
+ def backend
22
+ data[:backend]
23
+ end
24
+
25
+ def root
26
+ data[:root]
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,130 @@
1
+ # Should implement methods:
2
+ #
3
+ # key_field: if need to override default key
4
+ # bucket_field: if need to override default bucket
5
+ # download
6
+ #
7
+ # If need more customization, then override and implement the call method.
8
+ #
9
+ module Terraspace::Plugin::Summary
10
+ module Interface
11
+ def initialize(info, options={})
12
+ @info, @options = info, options
13
+ end
14
+
15
+ # 1. download state files to temp area
16
+ # 2. show resources for each
17
+ def call
18
+ # Note: will not change any of these instance variables unless we note breaking changes
19
+ @bucket = @info[bucket_field]
20
+ @key = @info[key_field] # key_field is INTERFACE METHOD IE: aws: key , google: prefix
21
+ @folder = folder(@key)
22
+ @dest = dest(@bucket)
23
+ # May change any of these instance variables that follow
24
+ @dest_folder = "#{@dest}/#{@folder}"
25
+
26
+ download_statefiles
27
+ show_resources
28
+ end
29
+
30
+ # default because aws and azurerm uses it.
31
+ # google uses prefix
32
+ # interface method
33
+ def key_field
34
+ 'key'
35
+ end
36
+
37
+ # default because aws and google uses it.
38
+ # azure uses storage_account_name and other attributes
39
+ # interface method
40
+ def bucket_field
41
+ 'bucket'
42
+ end
43
+
44
+ # Allow override by plugin implementation class. Generally, all files in these folders are tfstate files.
45
+ def statefile_expr
46
+ "#{@dest_folder}**/*"
47
+ end
48
+
49
+ def download_statefiles
50
+ return unless download?
51
+ FileUtils.rm_rf(@dest_folder)
52
+ logger.info("Downloading statefiles to #{@dest_folder}")
53
+ download # INTERFACE METHOD
54
+ end
55
+
56
+ def show_resources
57
+ Dir.glob(statefile_expr).sort.each do |path|
58
+ next unless File.file?(path)
59
+ next if path.include?(".tflock")
60
+ show_each(path)
61
+ end
62
+ logger.info("No resources found in statefiles") unless @has_shown_resources
63
+ end
64
+
65
+ def show_each(path)
66
+ data = JSON.load(IO.read(path))
67
+ resources = data['resources']
68
+ remove_statefile(path) if resources && resources.size == 0 && !ENV['TS_KEEP_EMPTY_STATEFILES']
69
+ return unless resources && resources.size > 0
70
+
71
+ pretty_path = path.sub(Regexp.new(".*#{@bucket}/#{@folder}"), '')
72
+ logger.info pretty_path.color(:green)
73
+ resources.each do |r|
74
+ @has_shown_resources = true # flag to note some resources there were shown
75
+ identifier = r['instances'].map do |i|
76
+ i['attributes']['name'] || i['attributes']['id']
77
+ end.join(',')
78
+ return if @options[:short]
79
+ logger.info " #{r['type']} #{r['name']}: #{identifier}"
80
+ end
81
+ end
82
+
83
+ # Clean up empty statefiles because over time the extra network calls to download them
84
+ # slow down the summary command
85
+ def remove_statefile(path)
86
+ key = path.sub("#{statefiles_root}/#{@bucket}/",'')
87
+ delete_empty_statefile(key)
88
+ end
89
+
90
+ # interface method
91
+ def delete_empty_statefile(key)
92
+ end
93
+
94
+ private
95
+ def folder(path)
96
+ index = locate_env_index(path)
97
+ path[0..index] # Example folder: us-central1/dev/
98
+ end
99
+
100
+ # Assume that the state files are within a env folder.
101
+ # IE: us-central1/dev/stacks/vm
102
+ def locate_env_index(path)
103
+ regexp = Regexp.new("/#{Terraspace.env}/")
104
+ index = path.index(regexp)
105
+ unless index
106
+ logger.error "ERROR: Unable to find the #{Terraspace.env} position in the prefix"
107
+ logger.error "path used: #{path}"
108
+ exit 1
109
+ end
110
+ env_chars = Terraspace.env.size + 1
111
+ index + env_chars
112
+ end
113
+
114
+ def dest(bucket)
115
+ "#{statefiles_root}/#{bucket}"
116
+ end
117
+
118
+ def statefiles_root
119
+ "#{Terraspace.tmp_root}/statefiles"
120
+ end
121
+
122
+ def logger
123
+ Terraspace.logger
124
+ end
125
+
126
+ def download?
127
+ ENV['TS_SUMMARY_DOWNLOAD'] != '0'
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,66 @@
1
+ require "hcl_parser"
2
+
3
+ module Terraspace
4
+ class Seeder
5
+ extend Memoist
6
+ include Terraspace::Util
7
+
8
+ def initialize(mod, options={})
9
+ @mod, @options = mod, options
10
+ end
11
+
12
+ def seed
13
+ parsed = parse # make @parsed available for rest of processing
14
+ content = Content.new(parsed).build
15
+ write(content)
16
+ end
17
+
18
+ def parse
19
+ if exist?("variables.tf")
20
+ load_hcl_variables
21
+ elsif exist?("variables.tf.json")
22
+ JSON.load(read("variables.tf.json"))
23
+ else
24
+ logger.warn "WARN: no variables.tf or variables.tf.json found in: #{@mod.cache_dir}"
25
+ ENV['TS_TEST'] ? raise : exit
26
+ end
27
+ end
28
+ memoize :parse
29
+
30
+ def load_hcl_variables
31
+ HclParser.load(read("variables.tf"))
32
+ rescue Racc::ParseError => e
33
+ logger.error "ERROR: Unable to parse the #{Util.pretty_path(@mod.cache_dir)}/variables.tf file".color(:red)
34
+ logger.error "and generate the starter tfvars file. This is probably due to a complex variable type."
35
+ logger.error "#{e.class}: #{e.message}"
36
+ puts
37
+ logger.error "You will have to create the tfvars file manually at: #{Util.pretty_path(dest_path)}"
38
+ exit 1
39
+ end
40
+
41
+ def write(content)
42
+ actions.create_file(dest_path, content)
43
+ end
44
+
45
+ def dest_path
46
+ Where.new(@mod, @options).dest_path
47
+ end
48
+ memoize :dest_path
49
+
50
+ def exist?(file)
51
+ path = "#{@mod.cache_dir}/#{file}"
52
+ File.exist?(path)
53
+ end
54
+
55
+ def read(file)
56
+ path = "#{@mod.cache_dir}/#{file}"
57
+ logger.info "Reading: #{Util.pretty_path(path)}"
58
+ IO.read(path)
59
+ end
60
+
61
+ def actions
62
+ Actions.new(@options)
63
+ end
64
+ memoize :actions
65
+ end
66
+ end
@@ -0,0 +1,24 @@
1
+ require "thor"
2
+
3
+ # Usage:
4
+ #
5
+ # @actions = Actions.new
6
+ # @actions.create_file("content", "/path/to/file.txt")
7
+ #
8
+ class Terraspace::Seeder
9
+ class Actions
10
+ # What's needed for a Thor::Group or "Sequence"
11
+ # Gives us Thor::Actions commands like create_file
12
+ include Thor::Actions
13
+ include Thor::Base
14
+
15
+ attr_reader :options # Thor requires options
16
+ # Override Thor::Base initialize to set destination_root
17
+ def initialize(options={})
18
+ # Thor::Base.initialize(args = [], local_options = {}, config = {}) <= original signature
19
+ options[:force] = options[:yes]
20
+ super([], options)
21
+ self.destination_root = Dir.pwd # Thor::Actions require destination_root to be set
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,84 @@
1
+ class Terraspace::Seeder
2
+ class Content
3
+ extend Memoist
4
+
5
+ def initialize(parsed)
6
+ @parsed = parsed
7
+ end
8
+
9
+ def build
10
+ lines = []
11
+ lines << "# Required variables:" unless required_vars.empty?
12
+ required_vars.each do |name, meta|
13
+ lines << build_line(name, meta)
14
+ end
15
+ lines << "" unless required_vars.empty?
16
+ lines << "# Optional variables:" unless optional_vars.empty?
17
+ optional_vars.each do |name, meta|
18
+ lines << build_line(name, meta)
19
+ end
20
+ lines.join("\n") + "\n"
21
+ end
22
+
23
+ def build_line(name, meta)
24
+ value = var_value(meta)
25
+ name = "# #{name}" if meta["default"] # optional so add as a comment
26
+ name = "%-#{rpad}s" % name # rpad to align = signs
27
+ "#{name} = #{value}"
28
+ end
29
+
30
+ def var_value(meta)
31
+ type, default = meta["type"], meta["default"]
32
+
33
+ if default
34
+ escape(type, default)
35
+ else
36
+ value = desc_example(meta["description"]) || type || "any"
37
+ escape(type, value)
38
+ end
39
+ end
40
+
41
+ def escape(type, value)
42
+ if type&.include?('(') # complex type
43
+ "[...] # #{type}"
44
+ elsif %w[null any true false].include?(value)
45
+ value # no quotes
46
+ else
47
+ %Q|"#{value}"| # add quotes
48
+ end
49
+ end
50
+
51
+ def rpad
52
+ all_vars.keys.map(&:size).max
53
+ end
54
+ memoize :rpad
55
+
56
+ def desc_example(desc)
57
+ return unless desc
58
+ md = desc.match(/([eE]xample|IE): (.*)/)
59
+ return unless md
60
+ md[2]
61
+ end
62
+
63
+ def required_vars
64
+ select_vars(@parsed) { |meta| meta["default"].nil? }
65
+ end
66
+
67
+ def optional_vars
68
+ select_vars(@parsed) { |meta| !meta["default"].nil? }
69
+ end
70
+
71
+ def all_vars
72
+ select_vars(@parsed)
73
+ end
74
+
75
+ def select_vars(parsed)
76
+ vars = parsed.dig("variable")
77
+ return [] unless vars
78
+ vars.select do |name,meta|
79
+ block_given? ? yield(meta) : true
80
+ end
81
+ end
82
+
83
+ end
84
+ end
@@ -0,0 +1,30 @@
1
+ class Terraspace::Seeder
2
+ class Where
3
+ def initialize(mod, options={})
4
+ @mod, @options = mod, options
5
+ end
6
+
7
+ def dest_path
8
+ case @options[:where]
9
+ when "app"
10
+ app_path
11
+ when "seed"
12
+ seed_path
13
+ else
14
+ infer_dest_path
15
+ end
16
+ end
17
+
18
+ def infer_dest_path
19
+ @mod.type == "stack" ? app_path : seed_path
20
+ end
21
+
22
+ def app_path
23
+ "#{Terraspace.root}/app/#{@mod.build_dir}/tfvars/#{Terraspace.env}.tfvars"
24
+ end
25
+
26
+ def seed_path
27
+ "#{Terraspace.root}/seed/tfvars/#{@mod.build_dir}/#{Terraspace.env}.tfvars"
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,53 @@
1
+ module Terraspace::Terraform
2
+ class Api
3
+ extend Memoist
4
+ include Client
5
+ include Terraspace::Util::Logging
6
+
7
+ def initialize(mod, remote)
8
+ @mod = mod
9
+ @organization = remote['organization']
10
+ @workspace_name = remote['workspaces']['name']
11
+ end
12
+
13
+ # Docs: https://www.terraform.io/docs/cloud/api/workspaces.html
14
+ def set_working_dir
15
+ working_directory = @mod.cache_dir.sub("#{Terraspace.root}/", '')
16
+ return if working_directory == workspace['attributes']['working-directory']
17
+
18
+ payload = {
19
+ data: {
20
+ attributes: {
21
+ "working-directory": working_directory
22
+ },
23
+ type: "workspaces"
24
+ }
25
+ }
26
+ http.patch("organizations/#{@organization}/workspaces/#{@workspace_name}", payload)
27
+ end
28
+
29
+ def set_env_vars
30
+ Vars.new(@mod, workspace).run
31
+ end
32
+
33
+ def workspace(options={})
34
+ payload = http.get("organizations/#{@organization}/workspaces/#{@workspace_name}")
35
+ # Note only way to get here is to bypass init. Example:
36
+ #
37
+ # terraspace up demo --no-init
38
+ #
39
+ unless payload || options[:exit_on_fail] == false
40
+ logger.error "ERROR: Unable to find the workspace. The workspace may not exist. Or the Terraform token may be invalid. Please double check your Terraform token.".color(:red)
41
+ exit 1
42
+ end
43
+ return unless payload
44
+ payload['data']
45
+ end
46
+ memoize :workspace
47
+
48
+ def destroy_workspace
49
+ # resp payload from delete operation is nil
50
+ http.delete("/organizations/#{@organization}/workspaces/#{@workspace_name}")
51
+ end
52
+ end
53
+ end