Class: Cryptoform::ConfigGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/cryptoform/config_generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(name:, port:, storage_backend:, encryption_backend:) ⇒ ConfigGenerator

Returns a new instance of ConfigGenerator.



4
5
6
7
8
9
# File 'lib/cryptoform/config_generator.rb', line 4

def initialize(name:, port:, storage_backend:, encryption_backend:)
  @name = name
  @port = port
  @storage_backend = storage_backend
  @encryption_backend = encryption_backend
end

Instance Method Details

#generate_cryptofileObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/cryptoform/config_generator.rb', line 11

def generate_cryptofile
  <<~RUBY
    # frozen_string_literal: true

    port #{@port}

    state :#{@name} do
      storage_backend :#{@storage_backend}
      encryption_backend :#{@encryption_backend}, key: -> { ENV.fetch("CRYPTOFORM_KEY") }
    end
  RUBY
end

#generate_terraform_backendObject



24
25
26
27
28
29
30
31
32
# File 'lib/cryptoform/config_generator.rb', line 24

def generate_terraform_backend
  <<~HCL
    terraform {
      backend "http" {
        address = "http://127.0.0.1:#{@port}/states/#{@name}"
      }
    }
  HCL
end

#generate_terraform_remote_state_data_sourceObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/cryptoform/config_generator.rb', line 34

def generate_terraform_remote_state_data_source
  <<~HCL
    data "terraform_remote_state" "#{@name}_remote_state" {
      backend = "http"

      config = {
        address = "http://127.0.0.1:#{@port}/states/#{@name}"
      }
    }
  HCL
end