summaryrefslogtreecommitdiff
path: root/lib/gitlab/ci/parsers/terraform/tfplan.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-05-20 14:34:42 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-05-20 14:34:42 +0000
commit9f46488805e86b1bc341ea1620b866016c2ce5ed (patch)
treef9748c7e287041e37d6da49e0a29c9511dc34768 /lib/gitlab/ci/parsers/terraform/tfplan.rb
parentdfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff)
downloadgitlab-ce-9f46488805e86b1bc341ea1620b866016c2ce5ed.tar.gz
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'lib/gitlab/ci/parsers/terraform/tfplan.rb')
-rw-r--r--lib/gitlab/ci/parsers/terraform/tfplan.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/gitlab/ci/parsers/terraform/tfplan.rb b/lib/gitlab/ci/parsers/terraform/tfplan.rb
new file mode 100644
index 00000000000..26a18c6603e
--- /dev/null
+++ b/lib/gitlab/ci/parsers/terraform/tfplan.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Ci
+ module Parsers
+ module Terraform
+ class Tfplan
+ TfplanParserError = Class.new(Gitlab::Ci::Parsers::ParserError)
+
+ def parse!(json_data, terraform_reports, artifact:)
+ tfplan = Gitlab::Json.parse(json_data).tap do |parsed_data|
+ parsed_data['job_path'] = Gitlab::Routing.url_helpers.project_job_path(
+ artifact.job.project, artifact.job
+ )
+ end
+
+ raise TfplanParserError, 'Tfplan missing required key' unless valid_supported_keys?(tfplan)
+
+ terraform_reports.add_plan(artifact.filename, tfplan)
+ rescue JSON::ParserError
+ raise TfplanParserError, 'JSON parsing failed'
+ rescue
+ raise TfplanParserError, 'Tfplan parsing failed'
+ end
+
+ private
+
+ def valid_supported_keys?(tfplan)
+ tfplan.keys == %w[create update delete job_path]
+ end
+ end
+ end
+ end
+ end
+end