Class: Pangea::Testing::MockTerraformSynthesizer

Inherits:
Object
  • Object
show all
Defined in:
lib/pangea/testing/mock_terraform_synthesizer.rb

Overview

Mock synthesizer for testing when TerraformSynthesizer is not available. Accepts resource method calls matching known provider prefixes (aws_, google_, azurerm_, hcloud_, cloudflare_, etc.) and records the resource in the synthesis output.

Constant Summary collapse

VALID_RESOURCE_PREFIXES =

Known Terraform provider resource prefixes

%w[
  aws_ google_ azurerm_ hcloud_ cloudflare_ kubernetes_ helm_
  null_ random_ local_ tls_ time_ archive_ external_ template_
  akeyless_ datadog_ splunk_ vault_ consul_ nomad_ digitalocean_
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMockTerraformSynthesizer

Returns a new instance of MockTerraformSynthesizer.



34
35
36
37
38
# File 'lib/pangea/testing/mock_terraform_synthesizer.rb', line 34

def initialize
  @resources = {}
  @data_sources = {}
  @outputs = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/pangea/testing/mock_terraform_synthesizer.rb', line 48

def method_missing(method_name, *args, &block)
  resource_type = method_name.to_s

  unless valid_resource_type?(resource_type)
    super
  end

  resource_name = args[0].to_s
  resource_config = args[1] || {}

  @resources[resource_type] ||= {}
  @resources[resource_type][resource_name] = resource_config

  MockResourceReference.new(resource_type, resource_name, resource_config)
end

Instance Attribute Details

#data_sourcesObject (readonly)

Returns the value of attribute data_sources.



32
33
34
# File 'lib/pangea/testing/mock_terraform_synthesizer.rb', line 32

def data_sources
  @data_sources
end

#outputsObject (readonly)

Returns the value of attribute outputs.



32
33
34
# File 'lib/pangea/testing/mock_terraform_synthesizer.rb', line 32

def outputs
  @outputs
end

#resourcesObject (readonly)

Returns the value of attribute resources.



32
33
34
# File 'lib/pangea/testing/mock_terraform_synthesizer.rb', line 32

def resources
  @resources
end

Instance Method Details

#respond_to_missing?(method_name, _include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/pangea/testing/mock_terraform_synthesizer.rb', line 64

def respond_to_missing?(method_name, _include_private = false)
  valid_resource_type?(method_name.to_s) || super
end

#synthesisObject



40
41
42
43
44
45
46
# File 'lib/pangea/testing/mock_terraform_synthesizer.rb', line 40

def synthesis
  result = {}
  result['resource'] = @resources unless @resources.empty?
  result['data'] = @data_sources unless @data_sources.empty?
  result['output'] = @outputs unless @outputs.empty?
  result
end