Class: TerraformEnterprise::MainCommand

Inherits:
CommandLine::Command show all
Includes:
CommandLine
Defined in:
lib/terraform-enterprise-command-line.rb

Overview

Terraform Enterprise Command Line class

Constant Summary

Constants included from CommandLine

CommandLine::STRINGS, CommandLine::VERSION

Constants inherited from CommandLine::Command

CommandLine::Command::CMD_STR

Instance Method Summary collapse

Methods included from CommandLine::Util::Tar

#gzip, #tar, #tarball

Instance Method Details

#push(name) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/terraform-enterprise-command-line.rb', line 48

def push(name)
  name_parts        = name.split('/')
  organization_name = name_parts[0]
  workspace_name    = name_parts[1]
  workspace_params  = {
    organization: organization_name,
    workspace: workspace_name
  }

  begin
    content = tarball(options[:path])
  rescue
    error! "could not open that file or directory"
  end

  # Look up the workspace ID
  workspace_response = client.workspaces.get(workspace_params)
  workspace_id = workspace_response&.resource&.id
  error! "workspace '#{organization_name}/#{workspace_name}' was not found!" unless workspace_id

  # Create a configuration version and get upload-url
  configuration_version_response = client.configuration_versions.create(workspace: workspace_id)
  upload_url = (configuration_version_response&.resource&.attributes || {})['upload-url']
  error! "failed creationg configuration version with workspace id `#{workspace_id}`" unless upload_url      

  upload_params = { content: content, url: upload_url }
  render client.configuration_versions.upload(upload_params)
end