domed-city 2.0.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/CONTRIBUTORS.md +6 -0
- data/LICENSE +5 -20
- data/README.md +0 -3
- data/dome.gemspec +2 -3
- data/lib/dome.rb +0 -1
- data/lib/dome/environment.rb +9 -12
- data/lib/dome/helpers/shell.rb +1 -1
- data/lib/dome/state.rb +24 -16
- data/lib/dome/terraform.rb +18 -3
- data/lib/dome/version.rb +1 -1
- metadata +7 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6cc7ecbabc62d32ad05359b3c283be1e67407ef8
|
4
|
+
data.tar.gz: 4468f74c45e4817503a079992fc27b69e019e88a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b86362790fb01c9523938cbee392e3760a44498c58bdce70c0107566bdcf204ed033478dc89ebbce2e338a01e5322f9ece813c7617b1c8aaa7f56725066668c5
|
7
|
+
data.tar.gz: 5109c87e9fe98d85dfd30e08c5f3a016676d8ce6955162d6908316b78224735a211ea7fbc01327cdec436f8e086f4a001efb688247fe15913a9580c21b17f099
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# 3.0.0
|
2
|
+
|
3
|
+
Thanks to [@Russell-IO](https://github.com/Russell-IO) for helping with these changes.
|
4
|
+
|
5
|
+
- Internal refactoring.
|
6
|
+
- More tests added (but lots more needed).
|
7
|
+
- Improved debug output and explained up front how variables are set.
|
8
|
+
- Removed `aws_profile_parser` and used environment variables instead to unify
|
9
|
+
the AWS CLI and terraform calls.
|
10
|
+
|
11
|
+
ROADMAP:
|
12
|
+
- Merge [@mhlias](https://github.com/mhlias) changes that implements assumed-role support.
|
data/CONTRIBUTORS.md
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
- [Andrew Stangl](https://github.com/madandroid)
|
2
|
+
- [Ben Snape](https://github.com/bsnape)
|
3
|
+
- [Cameron Adams](https://github.com/cam-itv)
|
4
|
+
- [Efstathios Xagoraris](https://github.com/xiii)
|
5
|
+
- [Ilias Bertsimas](https://github.com/mhlias)
|
6
|
+
- [Russell Clare](https://github.com/Russell-IO)
|
data/LICENSE
CHANGED
@@ -1,22 +1,7 @@
|
|
1
|
-
|
1
|
+
Copyright 2016 ITV PLC, licensed under the ITV Open Source Software Licence, Version 1.0 (the “Licence"). You may not use any of the files in this repository except in compliance with the Licence”.
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
13
|
-
copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|
3
|
+
You may not use this file except in compliance with the Licence. You may obtain a copy of the Licence at http://itv.com/itv-oss-licence-v1.0.
|
22
4
|
|
5
|
+
Unless required by applicable law or as otherwise agreed in writing, software distributed under the Licence is distributed on an “as is” basis, without warranties or conditions of any kind, either express or implied, including without limitation,
|
6
|
+
any warranties or conditions as to title, non-infringement, merchantability or fitness for a particular purpose.
|
7
|
+
Please see the Licence for the specific language governing permissions and limitations under the Licence.
|
data/README.md
CHANGED
@@ -53,6 +53,3 @@ where [commands] are:
|
|
53
53
|
### NOTICE
|
54
54
|
|
55
55
|
When used for the first time in an environment you need to run `dome -s` for domed-city to create the S3 bucket and and enable file versioning on it. If you run it after the bucket has been created, it will just sync the remote state, something planning already does by default.
|
56
|
-
|
57
|
-
## Acknowledgment
|
58
|
-
The initial release of `domed-city` is based on the original, and unpublished work, done by @stefancocora and @madAndroid for an internal project at itv.
|
data/dome.gemspec
CHANGED
@@ -6,8 +6,8 @@ require 'dome/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'domed-city'
|
8
8
|
spec.version = Dome::VERSION
|
9
|
-
spec.authors = ['
|
10
|
-
spec.email = ['
|
9
|
+
spec.authors = ['ITV'] # see CONTRIBUTORS.md
|
10
|
+
spec.email = ['common-platform-team-group@itv.com']
|
11
11
|
|
12
12
|
spec.summary = 'A simple Terraform API wrapper and helpers for ITV.'
|
13
13
|
spec.homepage = 'https://github.com/ITV/dome'
|
@@ -23,7 +23,6 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency 'rubocop', '~> 0.37'
|
24
24
|
|
25
25
|
spec.add_dependency 'trollop', '~> 2.1'
|
26
|
-
spec.add_dependency 'aws-profile_parser', '~> 0.0'
|
27
26
|
spec.add_dependency 'aws-sdk', '~> 2.1'
|
28
27
|
spec.add_dependency 'colorize', '~> 0.7'
|
29
28
|
end
|
data/lib/dome.rb
CHANGED
data/lib/dome/environment.rb
CHANGED
@@ -8,12 +8,12 @@ module Dome
|
|
8
8
|
@settings = Dome::Settings.new
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
11
|
+
def project
|
12
12
|
@settings.parse['project']
|
13
13
|
end
|
14
14
|
|
15
15
|
def accounts
|
16
|
-
%W(#{
|
16
|
+
%W(#{project}-dev #{project}-prd)
|
17
17
|
end
|
18
18
|
|
19
19
|
def environments
|
@@ -21,15 +21,12 @@ module Dome
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def aws_credentials
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
ENV['AWS_ACCESS_KEY_ID'] = aws_credentials[:access_key_id]
|
31
|
-
ENV['AWS_SECRET_ACCESS_KEY'] = aws_credentials[:secret_access_key]
|
32
|
-
ENV['AWS_DEFAULT_REGION'] = aws_credentials[:region]
|
24
|
+
puts "Setting environment variable #{'AWS_PROFILE'.colorize(:green)} to your "\
|
25
|
+
"'account' name: #{@account.colorize(:green)}"
|
26
|
+
ENV['AWS_PROFILE'] = @account
|
27
|
+
puts "Setting environment variable #{'AWS_DEFAULT_REGION'.colorize(:green)} "\
|
28
|
+
"to #{'eu-west-1'.colorize(:green)}"
|
29
|
+
ENV['AWS_DEFAULT_REGION'] = 'eu-west-1' # should we let people override this? doubtful
|
33
30
|
end
|
34
31
|
|
35
32
|
def valid_account?(account_name)
|
@@ -60,7 +57,7 @@ module Dome
|
|
60
57
|
# rubocop:disable Metrics/AbcSize
|
61
58
|
def generic_error_message
|
62
59
|
puts "The 'account' and 'environment' variables are assigned based on your current directory.\n".colorize(:red)
|
63
|
-
puts "The expected directory structure is '
|
60
|
+
puts "The expected directory structure is 'terraform/<account>/<environment>'\n".colorize(:red)
|
64
61
|
puts '============================================================================='
|
65
62
|
puts "Valid environments are defined using the 'environments' key in your itv.yaml."
|
66
63
|
puts "The environments you have defined are: #{environments}."
|
data/lib/dome/helpers/shell.rb
CHANGED
data/lib/dome/state.rb
CHANGED
@@ -6,22 +6,30 @@ module Dome
|
|
6
6
|
@environment = environment
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
10
|
-
"#{@environment.
|
9
|
+
def state_bucket_name
|
10
|
+
"#{@environment.project}-tfstate-#{@environment.environment}"
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def state_file_name
|
14
14
|
"#{@environment.environment}-terraform.tfstate"
|
15
15
|
end
|
16
16
|
|
17
17
|
def s3_client
|
18
|
-
@s3_client ||= Aws::S3::Client.new
|
18
|
+
@s3_client ||= Aws::S3::Client.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def list_buckets
|
22
|
+
s3_client.list_buckets
|
23
|
+
end
|
24
|
+
|
25
|
+
def bucket_names
|
26
|
+
bucket_names = list_buckets.buckets.map(&:name)
|
27
|
+
puts "Found the following buckets: #{bucket_names}".colorize(:yellow)
|
28
|
+
bucket_names
|
19
29
|
end
|
20
30
|
|
21
31
|
def s3_bucket_exists?(bucket_name)
|
22
|
-
|
23
|
-
resp.buckets.each { |bucket| return true if bucket.name == bucket_name }
|
24
|
-
false
|
32
|
+
bucket_names.find { |bucket| bucket == bucket_name }
|
25
33
|
end
|
26
34
|
|
27
35
|
def create_bucket(name)
|
@@ -48,24 +56,24 @@ module Dome
|
|
48
56
|
)
|
49
57
|
end
|
50
58
|
|
51
|
-
def create_remote_state_bucket(
|
52
|
-
create_bucket
|
53
|
-
enable_bucket_versioning
|
54
|
-
put_empty_object_in_bucket(
|
59
|
+
def create_remote_state_bucket(bucket_name, state_file)
|
60
|
+
create_bucket bucket_name
|
61
|
+
enable_bucket_versioning bucket_name
|
62
|
+
put_empty_object_in_bucket(bucket_name, state_file)
|
55
63
|
end
|
56
64
|
|
57
65
|
def s3_state
|
58
|
-
if s3_bucket_exists?(
|
59
|
-
synchronise_s3_state
|
66
|
+
if s3_bucket_exists?(state_bucket_name)
|
67
|
+
synchronise_s3_state(state_bucket_name, state_file_name)
|
60
68
|
else
|
61
|
-
create_remote_state_bucket(
|
69
|
+
create_remote_state_bucket(state_bucket_name, state_file_name)
|
62
70
|
end
|
63
71
|
end
|
64
72
|
|
65
|
-
def synchronise_s3_state
|
73
|
+
def synchronise_s3_state(bucket_name, state_file_name)
|
66
74
|
puts 'Synchronising the remote S3 state...'
|
67
75
|
command = 'terraform remote config -backend=S3'\
|
68
|
-
" -backend-config='bucket=#{
|
76
|
+
" -backend-config='bucket=#{bucket_name}' -backend-config='key=#{state_file_name}'"
|
69
77
|
failure_message = 'Something went wrong when synchronising the S3 state.'
|
70
78
|
execute_command(command, failure_message)
|
71
79
|
end
|
data/lib/dome/terraform.rb
CHANGED
@@ -10,21 +10,36 @@ module Dome
|
|
10
10
|
@plan_file = "plans/#{@environment.account}-#{@environment.environment}-plan.tf"
|
11
11
|
end
|
12
12
|
|
13
|
+
# TODO: this method is a bit of a mess and needs looking at
|
14
|
+
# rubocop:disable Metrics/MethodLength
|
15
|
+
# rubocop:disable Metrics/AbcSize
|
13
16
|
def validate_environment
|
17
|
+
puts 'Initialising domed-city...'
|
18
|
+
puts "* Your 'account' and 'environment' are assigned based on your current directory. "\
|
19
|
+
"The expected directory structure is 'terraform/<account>/<environment>'".colorize(:yellow)
|
20
|
+
puts "* Your 'project' is defined using the 'project' key in your 'itv.yaml'.".colorize(:yellow)
|
21
|
+
puts "* Valid environments are defined using the 'environments' key in your 'itv.yaml'. "\
|
22
|
+
"You have defined: #{@environment.environments}".colorize(:yellow)
|
23
|
+
puts '* Valid accounts are of the format <project>-dev and <project>-prd and are calculated '\
|
24
|
+
"automatically using your 'project' variable.".colorize(:yellow)
|
25
|
+
|
26
|
+
puts "\nDebug output:\n------------"
|
14
27
|
environment = @environment.environment
|
15
28
|
account = @environment.account
|
16
29
|
@environment.invalid_account_message unless @environment.valid_account? account
|
17
30
|
@environment.invalid_environment_message unless @environment.valid_environment? environment
|
18
|
-
puts "
|
31
|
+
puts "Project: #{@environment.project.colorize(:green)}"
|
32
|
+
puts "State S3 bucket name: #{@state.state_bucket_name.colorize(:green)}"
|
33
|
+
puts "State file name: #{@state.state_file_name.colorize(:green)}"
|
34
|
+
@environment.aws_credentials
|
19
35
|
puts '----------------------------------------------------------------'
|
20
|
-
@environment.populate_aws_access_keys
|
21
36
|
end
|
22
37
|
|
23
38
|
def plan
|
24
39
|
delete_terraform_directory
|
25
40
|
delete_plan_file
|
26
41
|
install_terraform_modules
|
27
|
-
@state.synchronise_s3_state
|
42
|
+
@state.synchronise_s3_state(@state.state_bucket_name, @state.state_file_name)
|
28
43
|
create_plan
|
29
44
|
end
|
30
45
|
|
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:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- ITV
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,20 +80,6 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '2.1'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: aws-profile_parser
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0.0'
|
90
|
-
type: :runtime
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0.0'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: aws-sdk
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -124,7 +110,7 @@ dependencies:
|
|
124
110
|
version: '0.7'
|
125
111
|
description:
|
126
112
|
email:
|
127
|
-
-
|
113
|
+
- common-platform-team-group@itv.com
|
128
114
|
executables:
|
129
115
|
- dome
|
130
116
|
extensions: []
|
@@ -134,6 +120,8 @@ files:
|
|
134
120
|
- ".rspec"
|
135
121
|
- ".rubocop.yml"
|
136
122
|
- ".travis.yml"
|
123
|
+
- CHANGELOG.md
|
124
|
+
- CONTRIBUTORS.md
|
137
125
|
- Gemfile
|
138
126
|
- LICENSE
|
139
127
|
- README.md
|
@@ -166,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
154
|
version: '0'
|
167
155
|
requirements: []
|
168
156
|
rubyforge_project:
|
169
|
-
rubygems_version: 2.
|
157
|
+
rubygems_version: 2.2.5
|
170
158
|
signing_key:
|
171
159
|
specification_version: 4
|
172
160
|
summary: A simple Terraform API wrapper and helpers for ITV.
|