domed-city 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dc30be20e47da94a3dba7850dcbeace2d40dcd7f
4
- data.tar.gz: 8e9255071a4b955afefdfc7af8dd833b7bb88778
3
+ metadata.gz: a7efabd99d90f998c7b6d2ad165fbd90322eea5f
4
+ data.tar.gz: 09504559d427ebb0a2a79e0477778a0dfdff1878
5
5
  SHA512:
6
- metadata.gz: f692ed025597cbda665c7f42dc4442abc71be05d7288fdc3c30b43a5eeb20dfe08e466f0351ae473fa001584a347d45d44249059edca15cfc6189111ab5ff0ab
7
- data.tar.gz: 0ca6e96eb0c50e23663c45d971ab341d2712748ba7cf982e47974a8c239fb6c5b94b9f133ca6dda4d2684c02498a0e25f1269a73bbc609b741b593577a5f7f21
6
+ metadata.gz: f9634171a656f5fc75030a519b9b8c5ddedd2453cb002b596ea8c527e533ce0e23cc09753bd2159df7c304ac536f8632bb84500d1a4cdd688ec4c9570f861452
7
+ data.tar.gz: 8e45508db4ea0260baab44e97eec4958e4d96bc855b93057948d22cce8952337883f2d166dfbf39e131c6b2f4f2caab93e0b757e54346be04f4ea721191edb8a
data/README.md CHANGED
@@ -1,14 +1,50 @@
1
- # dome
2
- Simple Terraform API wrapper in Ruby.
1
+ # domed-city
2
+ Simple CLI application that wraps the Terraform API.
3
3
 
4
4
  ## Purpose
5
5
 
6
- To consolidate, improve and enforce standards around ITV's use of Terraform (via Rake) across product teams.
6
+ To consolidate, improve and enforce standards around ITV's use of Terraform across product teams.
7
+
8
+ This gem provides two main functions:
9
+
10
+ 1. Wrap the main Terraform functions (e.g. `plan`, `apply`).
11
+ 2. Ensure alignment to ITV's Common Platform VPC and environment policy.
12
+
13
+ ## Disclaimer
14
+
15
+ This gem is very specific to how ITV utilise Terraform so it is unlikely to be useful to others except
16
+ to serve as an example of how we do things.
7
17
 
8
18
  ## Naming
9
19
 
10
20
  From [Wikipedia](https://en.wikipedia.org/wiki/Domed_city):
11
21
 
22
+ > ...the dome is airtight and pressurized, creating a habitat that can be controlled for air temperature, composition and quality, typically due to an external atmosphere (or lack thereof) that is inimical to habitation for one or more reasons.
23
+
24
+ ## Installation
25
+
26
+ Add to your Gemfile:
27
+
12
28
  ```
13
- ...the dome is airtight and pressurized, creating a habitat that can be controlled for air temperature, composition and quality, typically due to an external atmosphere (or lack thereof) that is inimical to habitation for one or more reasons.
29
+ gem 'domed-city'
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ For ease of use, type `dome` in the CLI:
35
+
36
+ ```
37
+ $ dome
38
+
39
+ Dome wraps the Terraform API and performs useful stuff.
40
+
41
+ Usage:
42
+ dome [command]
43
+ where [commands] are:
44
+ -p, --plan Creates a Terraform plan
45
+ -a, --apply Applies a Terraform plan
46
+ -l, --plan-destroy Creates a destructive Terraform plan
47
+ -s, --state Synchronises the Terraform state
48
+ -v, --version Print version and exit
49
+ -h, --help Show this message
14
50
  ```
@@ -1,11 +1,15 @@
1
1
  module Dome
2
2
  class Environment
3
- attr_reader :environment, :account, :team
3
+ attr_reader :environment, :account
4
4
 
5
5
  def initialize
6
- @environment = Dir.pwd.split('/')[-1]
7
- @account = Dir.pwd.split('/')[-2]
8
- @team = @account.match(/(\w+)-\w+\z/)[1]
6
+ directories = Dir.pwd.split('/')
7
+ @environment = directories[-1]
8
+ @account = directories[-2]
9
+ end
10
+
11
+ def team
12
+ @account.match(/(\w+)-\w+\z/)[1]
9
13
  end
10
14
 
11
15
  def accounts
@@ -50,7 +54,8 @@ module Dome
50
54
 
51
55
  def invalid_account_message
52
56
  puts "\n'#{@account}' is not a valid account.\n".colorize(:red)
53
- puts "The 'account' and 'environment' values are calculated based on your current directory.\n".colorize(:red)
57
+ puts "The 'account' and 'environment' variables are assigned based on your current directory.\n".colorize(:red)
58
+ puts "The expected directory structure is '.../<account>/<environment>'\n".colorize(:red)
54
59
  puts "Valid accounts are: #{accounts}."
55
60
  puts "\nEither:"
56
61
  puts '1. Set your .aws/config to one of the valid accounts above.'
@@ -60,7 +65,8 @@ module Dome
60
65
 
61
66
  def invalid_environment_message
62
67
  puts "\n'#{@environment}' is not a valid environment for the account: '#{@account}'.\n".colorize(:red)
63
- puts "The 'account' and 'environment' values are calculated based on your current directory.\n".colorize(:red)
68
+ puts "The 'account' and 'environment' variables are assigned based on your current directory.\n".colorize(:red)
69
+ puts "The expected directory structure is '.../<account>/<environment>'\n".colorize(:red)
64
70
 
65
71
  env = if account[-4..-1] == '-dev'
66
72
  non_production_environments
@@ -3,9 +3,15 @@ module Dome
3
3
  include Dome::Shell
4
4
 
5
5
  def initialize(environment)
6
- @environment = environment
7
- @state_bucket = "#{@environment.team}-tfstate-#{@environment.environment}"
8
- @state_file = "#{@environment.environment}-terraform.tfstate"
6
+ @environment = environment
7
+ end
8
+
9
+ def state_bucket
10
+ "#{@environment.team}-tfstate-#{@environment.environment}"
11
+ end
12
+
13
+ def state_file
14
+ "#{@environment.environment}-terraform.tfstate"
9
15
  end
10
16
 
11
17
  def s3_client
@@ -51,17 +57,17 @@ module Dome
51
57
  end
52
58
 
53
59
  def s3_state
54
- if s3_bucket_exists?(@state_bucket)
60
+ if s3_bucket_exists?(state_bucket)
55
61
  synchronise_s3_state
56
62
  else
57
- create_remote_state_bucket(@state_bucket, @state_file)
63
+ create_remote_state_bucket(state_bucket, state_file)
58
64
  end
59
65
  end
60
66
 
61
67
  def synchronise_s3_state
62
68
  puts 'Synchronising the remote S3 state...'
63
69
  command = 'terraform remote config -backend=S3'\
64
- " -backend-config='bucket=#{@state_bucket}' -backend-config='key=#{@state_file}'"
70
+ " -backend-config='bucket=#{state_bucket}' -backend-config='key=#{state_file}'"
65
71
  failure_message = 'Something went wrong when synchronising the S3 state.'
66
72
  execute_command(command, failure_message)
67
73
  end
@@ -1,3 +1,3 @@
1
1
  module Dome
2
- VERSION = '1.1.0'
2
+ VERSION = '1.1.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: domed-city
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Snape
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-02 00:00:00.000000000 Z
11
+ date: 2015-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler