Class: Gitlab::Ci::Parsers::Terraform::Tfplan

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/ci/parsers/terraform/tfplan.rb

Constant Summary collapse

TfplanParserError =
Class.new(Gitlab::Ci::Parsers::ParserError)

Instance Method Summary collapse

Instance Method Details

#parse!(json_data, terraform_reports, artifact:) ⇒ Object


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/gitlab/ci/parsers/terraform/tfplan.rb', line 10

def parse!(json_data, terraform_reports, artifact:)
  job_details = job_details(artifact.job)
  job_id = job_details['job_id']
  plan_data = Gitlab::Json.parse(json_data)

  if has_required_keys?(plan_data)
    terraform_reports.add_plan(job_id, valid_tfplan(plan_data, job_details))
  else
    terraform_reports.add_plan(job_id, invalid_tfplan(:missing_json_keys, job_details))
  end
rescue JSON::ParserError
  terraform_reports.add_plan(job_id, invalid_tfplan(:invalid_json_format, job_details))
rescue
  details = job_details || {}
  plan_name = job_id || 'failed_tf_plan'
  terraform_reports.add_plan(plan_name, invalid_tfplan(:unknown_error, details))
end