terraspace 2.0.2 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.cody/README.md +1 -1
- data/.cody/all/project.rb +4 -0
- data/.cody/aws/project.rb +4 -0
- data/.cody/azurerm/project.rb +4 -0
- data/.cody/google/project.rb +4 -0
- data/.cody/none/project.rb +4 -0
- data/.cody/shared/script/install/infracost.sh +6 -0
- data/.cody/shared/script/install/terraform.sh +2 -2
- data/.cody/shared/script/install.sh +1 -0
- data/.github/FUNDING.yml +1 -0
- data/.pipedream/README.md +1 -1
- data/.pipedream/pipeline.rb +15 -8
- data/CHANGELOG.md +16 -0
- data/lib/templates/base/project/Gemfile.tt +5 -0
- data/lib/templates/base/project/config/app.rb +6 -2
- data/lib/templates/plugin/ci/CHANGELOG.md.tt +1 -1
- data/lib/templates/plugin/ci/lib/%gem_name%/vars.rb.tt +1 -1
- data/lib/terraspace/app.rb +16 -0
- data/lib/terraspace/cli/base.rb +1 -0
- data/lib/terraspace/cli/commander.rb +2 -1
- data/lib/terraspace/cli/concerns/plan_path.rb +1 -1
- data/lib/terraspace/cli/down.rb +43 -6
- data/lib/terraspace/cli/logs/concern.rb +1 -1
- data/lib/terraspace/cli/new/plugin/ci.rb +1 -4
- data/lib/terraspace/cli/plan.rb +66 -2
- data/lib/terraspace/cli/up.rb +65 -11
- data/lib/terraspace/cloud/api/cani.rb +15 -9
- data/lib/terraspace/cloud/api/concern.rb +0 -1
- data/lib/terraspace/cloud/api/http_methods.rb +7 -2
- data/lib/terraspace/cloud/api.rb +29 -5
- data/lib/terraspace/cloud/base.rb +16 -29
- data/lib/terraspace/cloud/ci.rb +1 -8
- data/lib/terraspace/cloud/comment.rb +28 -0
- data/lib/terraspace/cloud/context.rb +1 -0
- data/lib/terraspace/cloud/cost/infracost.rb +80 -0
- data/lib/terraspace/cloud/cost.rb +68 -0
- data/lib/terraspace/cloud/git.rb +0 -0
- data/lib/terraspace/cloud/plan.rb +33 -15
- data/lib/terraspace/cloud/stream.rb +113 -0
- data/lib/terraspace/cloud/streamer.rb +9 -0
- data/lib/terraspace/cloud/update.rb +19 -19
- data/lib/terraspace/cloud/{folder → upload}/base.rb +2 -2
- data/lib/terraspace/cloud/{folder → upload}/package.rb +2 -2
- data/lib/terraspace/cloud/{folder → upload}/tidy.rb +1 -1
- data/lib/terraspace/cloud/upload.rb +53 -0
- data/lib/terraspace/cloud/vcs/base.rb +6 -0
- data/lib/terraspace/cloud/vcs/ci_env.rb +15 -0
- data/lib/terraspace/cloud/vcs/commenter.rb +75 -0
- data/lib/terraspace/cloud/vcs/interface.rb +14 -0
- data/lib/terraspace/cloud/vcs/local_env.rb +25 -0
- data/lib/terraspace/cloud/{ci/vcs → vcs/local_git}/base.rb +6 -3
- data/lib/terraspace/cloud/vcs/local_git/bitbucket.rb +17 -0
- data/lib/terraspace/cloud/vcs/local_git/github.rb +17 -0
- data/lib/terraspace/cloud/vcs/local_git/gitlab.rb +17 -0
- data/lib/terraspace/cloud/{ci/manual.rb → vcs/local_git.rb} +18 -10
- data/lib/terraspace/cloud/vcs.rb +21 -0
- data/lib/terraspace/compiler/strategy/tfvar/layer.rb +1 -1
- data/lib/terraspace/logger.rb +3 -2
- data/lib/terraspace/shell/error.rb +1 -1
- data/lib/terraspace/terraform/runner.rb +4 -22
- data/lib/terraspace/util/popen.rb +67 -0
- data/lib/terraspace/version.rb +1 -1
- metadata +26 -23
- data/lib/templates/plugin/ci/lib/%gem_name%/pr.rb.tt +0 -15
- data/lib/terraspace/cloud/api/concern/record.rb +0 -18
- data/lib/terraspace/cloud/ci/generic.rb +0 -25
- data/lib/terraspace/cloud/ci/vcs/bitbucket.rb +0 -11
- data/lib/terraspace/cloud/ci/vcs/github.rb +0 -11
- data/lib/terraspace/cloud/ci/vcs/gitlab.rb +0 -11
- data/lib/terraspace/cloud/ci/vcs.rb +0 -18
- data/lib/terraspace/cloud/folder/uploader.rb +0 -37
- data/lib/terraspace/cloud/folder.rb +0 -11
- data/lib/terraspace/terraform/ihooks/after/apply.rb +0 -8
- data/lib/terraspace/terraform/ihooks/after/destroy.rb +0 -8
- data/lib/terraspace/terraform/ihooks/after/plan.rb +0 -46
- data/lib/terraspace/terraform/ihooks/base.rb +0 -17
- data/lib/terraspace/terraform/ihooks/before/apply.rb +0 -8
- data/lib/terraspace/terraform/ihooks/before/destroy.rb +0 -8
- data/lib/terraspace/terraform/ihooks/before/plan.rb +0 -20
@@ -1,25 +0,0 @@
|
|
1
|
-
class Terraspace::Cloud::Ci
|
2
|
-
class Generic
|
3
|
-
def vars
|
4
|
-
{
|
5
|
-
build_system: "generic",
|
6
|
-
host: ENV['TS_CI_HOST'] || ENV['TS_VCS_HOST'],
|
7
|
-
full_repo: ENV['TS_CI_REPO'],
|
8
|
-
branch_name: ENV['TS_CI_BRANCH'],
|
9
|
-
# urls
|
10
|
-
commit_url: ENV['TS_CI_COMMIT_URL'],
|
11
|
-
branch_url: ENV['TS_CI_BRANCH_URL'],
|
12
|
-
pr_url: ENV['TS_CI_PR_URL'],
|
13
|
-
build_url: ENV['TS_CI_BUILD_URL'],
|
14
|
-
# additional properties
|
15
|
-
build_type: ENV['TS_CI_BUILD_TYPE'],
|
16
|
-
pr_number: ENV['TS_CI_PR_NUMBER'],
|
17
|
-
sha: ENV['TS_CI_SHA'],
|
18
|
-
# additional properties
|
19
|
-
commit_message: ENV['TS_CI_COMMIT_MESSAGE'],
|
20
|
-
build_id: ENV['TS_CI_BUILD_ID'],
|
21
|
-
build_number: ENV['TS_CI_BUILD_NUMBER'],
|
22
|
-
}
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
class Terraspace::Cloud::Ci
|
2
|
-
class Vcs
|
3
|
-
extend Memoist
|
4
|
-
|
5
|
-
def initialize(vars)
|
6
|
-
@vars = vars
|
7
|
-
end
|
8
|
-
|
9
|
-
def merged_vars
|
10
|
-
vcs_class = case @vars[:host]
|
11
|
-
when /github/ then Github
|
12
|
-
when /gitlab/ then Gitlab
|
13
|
-
when /bitbucket/ then Bitbucket
|
14
|
-
end
|
15
|
-
vcs_class ? vcs_class.new(@vars).merged_vars : {}
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -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,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,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
|