-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lib improvements; simplified kite errors (#11)
* Lib improvements - Added error module - Added file checks * Simplified Kite errors
- Loading branch information
1 parent
bcfcbc5
commit 0cef996
Showing
4 changed files
with
28 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class Kite::Error < Thor::Error | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,31 @@ | ||
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) | ||
tf_state = YAML.load(File.open(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 |