terraspace 2.0.3 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/.cody/README.md +1 -1
  3. data/.cody/all/project.rb +4 -0
  4. data/.cody/aws/project.rb +4 -0
  5. data/.cody/azurerm/project.rb +4 -0
  6. data/.cody/google/project.rb +4 -0
  7. data/.cody/none/project.rb +4 -0
  8. data/.cody/shared/script/install/infracost.sh +6 -0
  9. data/.cody/shared/script/install/terraform.sh +2 -2
  10. data/.cody/shared/script/install.sh +1 -0
  11. data/.pipedream/README.md +1 -1
  12. data/.pipedream/pipeline.rb +15 -8
  13. data/CHANGELOG.md +8 -0
  14. data/lib/templates/base/project/Gemfile.tt +5 -0
  15. data/lib/templates/base/project/config/app.rb +6 -2
  16. data/lib/templates/plugin/ci/CHANGELOG.md.tt +1 -1
  17. data/lib/templates/plugin/ci/lib/%gem_name%/vars.rb.tt +1 -1
  18. data/lib/terraspace/app.rb +16 -0
  19. data/lib/terraspace/cli/base.rb +1 -0
  20. data/lib/terraspace/cli/commander.rb +2 -1
  21. data/lib/terraspace/cli/down.rb +42 -6
  22. data/lib/terraspace/cli/new/plugin/ci.rb +1 -4
  23. data/lib/terraspace/cli/plan.rb +66 -2
  24. data/lib/terraspace/cli/up.rb +65 -11
  25. data/lib/terraspace/cloud/api/cani.rb +15 -9
  26. data/lib/terraspace/cloud/api/concern.rb +0 -1
  27. data/lib/terraspace/cloud/api/http_methods.rb +7 -2
  28. data/lib/terraspace/cloud/api.rb +29 -5
  29. data/lib/terraspace/cloud/base.rb +15 -28
  30. data/lib/terraspace/cloud/ci.rb +1 -8
  31. data/lib/terraspace/cloud/comment.rb +28 -0
  32. data/lib/terraspace/cloud/context.rb +1 -0
  33. data/lib/terraspace/cloud/cost/infracost.rb +80 -0
  34. data/lib/terraspace/cloud/cost.rb +68 -0
  35. data/lib/terraspace/cloud/git.rb +0 -0
  36. data/lib/terraspace/cloud/plan.rb +33 -15
  37. data/lib/terraspace/cloud/stream.rb +113 -0
  38. data/lib/terraspace/cloud/streamer.rb +9 -0
  39. data/lib/terraspace/cloud/update.rb +19 -19
  40. data/lib/terraspace/cloud/{folder → upload}/base.rb +1 -1
  41. data/lib/terraspace/cloud/{folder → upload}/package.rb +1 -1
  42. data/lib/terraspace/cloud/{folder → upload}/tidy.rb +1 -1
  43. data/lib/terraspace/cloud/upload.rb +53 -0
  44. data/lib/terraspace/cloud/vcs/base.rb +6 -0
  45. data/lib/terraspace/cloud/vcs/ci_env.rb +15 -0
  46. data/lib/terraspace/cloud/vcs/commenter.rb +75 -0
  47. data/lib/terraspace/cloud/vcs/interface.rb +14 -0
  48. data/lib/terraspace/cloud/vcs/local_env.rb +25 -0
  49. data/lib/terraspace/cloud/{ci/vcs → vcs/local_git}/base.rb +6 -3
  50. data/lib/terraspace/cloud/vcs/local_git/bitbucket.rb +17 -0
  51. data/lib/terraspace/cloud/vcs/local_git/github.rb +17 -0
  52. data/lib/terraspace/cloud/vcs/local_git/gitlab.rb +17 -0
  53. data/lib/terraspace/cloud/{ci/manual.rb → vcs/local_git.rb} +18 -10
  54. data/lib/terraspace/cloud/vcs.rb +21 -0
  55. data/lib/terraspace/logger.rb +1 -1
  56. data/lib/terraspace/shell/error.rb +1 -1
  57. data/lib/terraspace/terraform/runner.rb +4 -22
  58. data/lib/terraspace/util/popen.rb +67 -0
  59. data/lib/terraspace/version.rb +1 -1
  60. metadata +25 -23
  61. data/lib/templates/plugin/ci/lib/%gem_name%/pr.rb.tt +0 -15
  62. data/lib/terraspace/cloud/api/concern/record.rb +0 -18
  63. data/lib/terraspace/cloud/ci/generic.rb +0 -25
  64. data/lib/terraspace/cloud/ci/vcs/bitbucket.rb +0 -11
  65. data/lib/terraspace/cloud/ci/vcs/github.rb +0 -11
  66. data/lib/terraspace/cloud/ci/vcs/gitlab.rb +0 -11
  67. data/lib/terraspace/cloud/ci/vcs.rb +0 -18
  68. data/lib/terraspace/cloud/folder/uploader.rb +0 -37
  69. data/lib/terraspace/cloud/folder.rb +0 -11
  70. data/lib/terraspace/terraform/ihooks/after/apply.rb +0 -8
  71. data/lib/terraspace/terraform/ihooks/after/destroy.rb +0 -8
  72. data/lib/terraspace/terraform/ihooks/after/plan.rb +0 -46
  73. data/lib/terraspace/terraform/ihooks/base.rb +0 -17
  74. data/lib/terraspace/terraform/ihooks/before/apply.rb +0 -8
  75. data/lib/terraspace/terraform/ihooks/before/destroy.rb +0 -8
  76. data/lib/terraspace/terraform/ihooks/before/plan.rb +0 -20
@@ -1,37 +0,0 @@
1
- class Terraspace::Cloud::Folder
2
- class Uploader < Base
3
- attr_reader :record
4
- def upload
5
- @record = create_record # set @record for start_plan(uploader.record)
6
- upload_project(@record['url'], zip_path)
7
- end
8
-
9
- def create_record
10
- result = api.create_upload
11
- if errors?(result)
12
- error_message(result)
13
- exit 1 # Consider: raise exception can rescue higher up
14
- else
15
- load_record(result)
16
- end
17
- end
18
-
19
- def upload_project(url, path)
20
- uri = URI.parse(url)
21
- object_content = IO.read(path)
22
- resp = Net::HTTP.start(uri.host) do |http|
23
- http.send_request(
24
- 'PUT',
25
- uri.request_uri,
26
- object_content,
27
- 'content-type' => ''
28
- )
29
- end
30
- unless resp.code =~ /^20/
31
- puts "ERROR: Uploading code"
32
- puts "resp.body #{resp.body}"
33
- exit 1 # TODO: consider raising error
34
- end
35
- end
36
- end
37
- end
@@ -1,11 +0,0 @@
1
- module Terraspace::Cloud
2
- class Folder < Base
3
- def upload_data
4
- Package.new(@options).build
5
- uploader = Uploader.new(@options)
6
- uploader.upload
7
- @upload = uploader.record
8
- end
9
- attr_reader :upload # upload record
10
- end
11
- end
@@ -1,8 +0,0 @@
1
- module Terraspace::Terraform::Ihooks::After
2
- class Apply < Terraspace::Terraform::Ihooks::Base
3
- def run
4
- return unless Terraspace.cloud?
5
- Terraspace::Cloud::Update.new(@options.merge(stack: @mod.name, kind: "apply")).run
6
- end
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- module Terraspace::Terraform::Ihooks::After
2
- class Destroy < Terraspace::Terraform::Ihooks::Base
3
- def run
4
- return unless Terraspace.cloud?
5
- Terraspace::Cloud::Update.new(@options.merge(stack: @mod.name, kind: "destroy")).run
6
- end
7
- end
8
- end
@@ -1,46 +0,0 @@
1
- module Terraspace::Terraform::Ihooks::After
2
- class Plan < Terraspace::Terraform::Ihooks::Base
3
- include Terraspace::CLI::Concerns::PlanPath
4
-
5
- def run
6
- return if !@mod.out_option || @options[:copy_to_root] == false
7
- @success = copy_to_root(@mod.out_option)
8
- cloud_create_plan
9
- end
10
-
11
- def copy_to_root(file)
12
- return if file =~ %r{^/} # not need to copy absolute path
13
- name = file.sub("#{Terraspace.root}/",'')
14
- src = "#{@mod.cache_dir}/#{name}"
15
- dest = name
16
- return false unless File.exist?(src) # plan wont exists if the plan errors
17
- FileUtils.mkdir_p(File.dirname(dest))
18
- FileUtils.cp(src, dest)
19
- !!dest
20
- end
21
-
22
- def cloud_create_plan
23
- return unless Terraspace.cloud?
24
-
25
- unless @mod.out_option.include?(".cache2/")
26
- # copy absolute path directly
27
- src = @mod.out_option.starts_with?('/') ? @mod.out_option : "#{@mod.cache_dir}/#{@mod.out_option}"
28
- dest = "#{@mod.cache_dir}/#{plan_path}"
29
- FileUtils.mkdir_p(File.dirname(dest))
30
- FileUtils.cp(src, dest)
31
- end
32
-
33
- # for both:
34
- # terraspace plan demo --destroy
35
- # terraspace down demo
36
- kind = destroy? ? "destroy" : "apply"
37
- if Terraspace.command?("plan")
38
- Terraspace::Cloud::Plan.new(@options.merge(stack: @mod.name, kind: kind)).run
39
- end
40
- # create update if not plan and plan failed
41
- if !Terraspace.command?("plan") && !@success
42
- Terraspace::Cloud::Update.new(@options.merge(stack: @mod.name, kind: kind)).run
43
- end
44
- end
45
- end
46
- end
@@ -1,17 +0,0 @@
1
- module Terraspace::Terraform::Ihooks
2
- class Base < Terraspace::CLI::Base
3
- include Terraspace::Cloud::Api::Concern
4
-
5
- def initialize(name, options={})
6
- @name = name
7
- @success = options[:success]
8
- super(options)
9
- end
10
-
11
- def destroy?
12
- return false if @options.nil?
13
- result = @options[:args]&.include?('--destroy') || @options[:destroy]
14
- !!result
15
- end
16
- end
17
- end
@@ -1,8 +0,0 @@
1
- module Terraspace::Terraform::Ihooks::Before
2
- class Apply < Terraspace::Terraform::Ihooks::Base
3
- def run
4
- return unless Terraspace.cloud?
5
- Terraspace::Cloud::Update.new(@options.merge(stack: @mod.name, kind: "apply")).cani?
6
- end
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- module Terraspace::Terraform::Ihooks::Before
2
- class Destroy < Terraspace::Terraform::Ihooks::Base
3
- def run
4
- return unless Terraspace.cloud?
5
- Terraspace::Cloud::Update.new(@options.merge(stack: @mod.name, kind: "destroy")).cani?
6
- end
7
- end
8
- end
@@ -1,20 +0,0 @@
1
- module Terraspace::Terraform::Ihooks::Before
2
- class Plan < Terraspace::Terraform::Ihooks::Base
3
- def run
4
- cani?
5
-
6
- return unless @mod.out_option
7
- return if @mod.out_option =~ %r{^/} # not need to create parent dir for copy with absolute path
8
-
9
- name = @mod.out_option.sub("#{Terraspace.root}/",'')
10
- dest = "#{@mod.cache_dir}/#{name}"
11
- FileUtils.mkdir_p(File.dirname(dest))
12
- end
13
-
14
- def cani?
15
- return unless Terraspace.cloud?
16
- kind = destroy? ? "destroy" : "apply"
17
- Terraspace::Cloud::Plan.new(@options.merge(stack: @mod.name, kind: kind)).cani?
18
- end
19
- end
20
- end