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 +4 -4
- data/README.md +40 -4
- data/lib/dome/environment.rb +12 -6
- data/lib/dome/state.rb +12 -6
- data/lib/dome/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7efabd99d90f998c7b6d2ad165fbd90322eea5f
|
4
|
+
data.tar.gz: 09504559d427ebb0a2a79e0477778a0dfdff1878
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9634171a656f5fc75030a519b9b8c5ddedd2453cb002b596ea8c527e533ce0e23cc09753bd2159df7c304ac536f8632bb84500d1a4cdd688ec4c9570f861452
|
7
|
+
data.tar.gz: 8e45508db4ea0260baab44e97eec4958e4d96bc855b93057948d22cce8952337883f2d166dfbf39e131c6b2f4f2caab93e0b757e54346be04f4ea721191edb8a
|
data/README.md
CHANGED
@@ -1,14 +1,50 @@
|
|
1
|
-
#
|
2
|
-
Simple
|
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
|
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
|
-
|
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
|
```
|
data/lib/dome/environment.rb
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
module Dome
|
2
2
|
class Environment
|
3
|
-
attr_reader :environment, :account
|
3
|
+
attr_reader :environment, :account
|
4
4
|
|
5
5
|
def initialize
|
6
|
-
|
7
|
-
@
|
8
|
-
@
|
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'
|
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'
|
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
|
data/lib/dome/state.rb
CHANGED
@@ -3,9 +3,15 @@ module Dome
|
|
3
3
|
include Dome::Shell
|
4
4
|
|
5
5
|
def initialize(environment)
|
6
|
-
@environment
|
7
|
-
|
8
|
-
|
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?(
|
60
|
+
if s3_bucket_exists?(state_bucket)
|
55
61
|
synchronise_s3_state
|
56
62
|
else
|
57
|
-
create_remote_state_bucket(
|
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=#{
|
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
|
data/lib/dome/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2015-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|