Class: Pangea::Magma::Workspace

Inherits:
Object
  • Object
show all
Defined in:
lib/pangea/magma/workspace.rb

Overview

Typed Pangea workspace declaration — the M0.1 primitive that mirrors ‘magma_pangea::workspace::Workspace` (the Rust trait). Per theory/PANGEA-MAGMA-ORCHESTRATION.md §III.1.

Authors:

vpc = Pangea::Magma::Workspace.declare(
  name:           :seph_vpc,
  template:       'seph_vpc.rb',
  workspace_dir:  'workspaces/seph-vpc',
  inputs: {
    cidr_block: { type: String, default: '10.0.0.0/16' },
  },
  outputs: {
    vpc_id:    { type: String, sensitive: false },
    subnet_id: { type: String },
  },
  requires: {
    input_format: 'terraform-json',
  },
)

Then composes into a Chain (see chain.rb) for multi-workspace orchestration. Each Workspace consumes magma-arch-test under the hood via Pangea::Magma.verify_workspace.

Defined Under Namespace

Classes: Requires, Slot

Constant Summary collapse

DEFAULT_REQUIRES =

Default requires for every Pangea-rendered workspace. Most workspaces target the terraform-json input format; declaring this on every workspace is boilerplate, so we make it the default and let exotic workspaces override it.

{ input_format: 'terraform-json' }.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, template:, workspace_dir:, inputs:, outputs:, requires:) ⇒ Workspace

Returns a new instance of Workspace.



93
94
95
96
97
98
99
100
101
# File 'lib/pangea/magma/workspace.rb', line 93

def initialize(name:, template:, workspace_dir:,
               inputs:, outputs:, requires:)
  @name          = name
  @template      = template
  @workspace_dir = workspace_dir
  @inputs        = inputs
  @outputs       = outputs
  @requires      = requires
end

Instance Attribute Details

#inputsObject (readonly)

Returns the value of attribute inputs.



91
92
93
# File 'lib/pangea/magma/workspace.rb', line 91

def inputs
  @inputs
end

#nameObject (readonly)

Returns the value of attribute name.



91
92
93
# File 'lib/pangea/magma/workspace.rb', line 91

def name
  @name
end

#outputsObject (readonly)

Returns the value of attribute outputs.



91
92
93
# File 'lib/pangea/magma/workspace.rb', line 91

def outputs
  @outputs
end

#requiresObject (readonly)

Returns the value of attribute requires.



91
92
93
# File 'lib/pangea/magma/workspace.rb', line 91

def requires
  @requires
end

#templateObject (readonly)

Returns the value of attribute template.



91
92
93
# File 'lib/pangea/magma/workspace.rb', line 91

def template
  @template
end

#workspace_dirObject (readonly)

Returns the value of attribute workspace_dir.



91
92
93
# File 'lib/pangea/magma/workspace.rb', line 91

def workspace_dir
  @workspace_dir
end

Class Method Details

.declare(name:, template:, workspace_dir:, inputs: {}, outputs: {}, requires: DEFAULT_REQUIRES) ⇒ Object

Build a typed Workspace declaration. Raises ArgumentError if the declaration is malformed.

Raises:

  • (ArgumentError)


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/pangea/magma/workspace.rb', line 64

def declare(name:, template:, workspace_dir:,
            inputs: {}, outputs: {}, requires: DEFAULT_REQUIRES)
  raise ArgumentError, 'name required (Symbol or String)' if name.nil?
  raise ArgumentError, 'template required' if template.nil?
  raise ArgumentError, 'workspace_dir required' if workspace_dir.nil?

  new(
    name:          name.to_sym,
    template:      template.to_s,
    workspace_dir: workspace_dir.to_s,
    inputs:        coerce_slots(inputs),
    outputs:       coerce_slots(outputs),
    requires:      Requires.new(**requires),
  )
end

Instance Method Details

#to_hObject

Serialize for magma flow run consumption.



111
112
113
114
115
116
117
118
119
120
# File 'lib/pangea/magma/workspace.rb', line 111

def to_h
  {
    name:          @name.to_s,
    template:      @template,
    workspace_dir: @workspace_dir,
    inputs:        @inputs.transform_values(&:to_h),
    outputs:       @outputs.transform_values(&:to_h),
    requires:      @requires.to_h,
  }
end

#to_json(*args) ⇒ Object



122
123
124
# File 'lib/pangea/magma/workspace.rb', line 122

def to_json(*args)
  to_h.to_json(*args)
end

#verify(backend: 'magma') ⇒ Object

Verify this workspace works under the chosen backend. Routes through Pangea::Magma.verify_workspace + Pangea::Backend.



105
106
107
108
# File 'lib/pangea/magma/workspace.rb', line 105

def verify(backend: 'magma')
  Pangea::Backend.verify_compatible!(backend, @requires.to_h) unless @requires.empty?
  Pangea::Magma.verify_workspace(@workspace_dir)
end