Sha256: be3bbe2bdbc83861b6d94f5aea6ae65fabb8ae66c1be23af46135205bb6b1e5d

Contents?: true

Size: 939 Bytes

Versions: 2

Compression:

Stored size: 939 Bytes

Contents

module Kite::Helpers
  # Check config/cloud.yml file to be complete
  def check_cloud_config(config)
    raise Kite::Error, 'The config/cloud.yml is not filled out!' unless config.find { |key, hash| hash.find { |k, v| v.nil? } }.nil?
  end

  # Check if Terraform IaC was applied
  def check_terraform_applied
    raise Kite::Error, 'Did you terraform apply? terraform.tfstate is missing!' unless File.file? "terraform/terraform.tfstate"
  end

  # Parse Terraform .tfstate file, returning the output hash
  def parse_tf_state(path)
    check_terraform_applied

    tf_state = YAML.load(File.read(path))
    tf_output = tf_state["modules"].first["outputs"]
    tf_output.map { |k, v| tf_output[k] = v["value"] }

    tf_output
  end

  # Parse config/cloud.yml, returning the output hash
  def parse_cloud_config
    cloud_config = YAML.load(File.read('config/cloud.yml'))
    check_cloud_config(cloud_config)

    cloud_config
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
kite-0.0.7 lib/kite/helpers.rb
kite-0.0.6 lib/kite/helpers.rb