fog_to_terraform 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ec7bcd76444b28a226d7c0c5febce96c925bcd23
4
+ data.tar.gz: 55449680571636b23918800906c4e4febfffa140
5
+ SHA512:
6
+ metadata.gz: 2cf7eaf4e4f03ba30f6e94343f686e70ffa0977c9fe7ee2ca720844da4d669cfde5a9c1641dc9e9e09b3f738b9ad9f76117095f37ccfac75738828af1fb7dd9f
7
+ data.tar.gz: 6b56a7854bc35f9e45994bd4887bcb583356692110dbbb1fd0c43a19b21253155db10c8fb43fcbc57878d7348fb8de4c17a38e341bbc129f807323683167346e
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+
16
+ terraform.tf
17
+ ssh/*.pem
18
+ settings.yml
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fog_to_terraform.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Dr Nic Williams
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ fog to terraform
2
+ ================
3
+
4
+ Creates a `terraform.tf` input variable file for terraform plans using credentials from a fog-formatted YAML file.
5
+
6
+ Given the following example fog file (defaults to `~/.fog`\):
7
+
8
+ ```yaml
9
+ ---
10
+ :student1:
11
+ :aws_access_key_id: ACCESS
12
+ :aws_secret_access_key: SECRET
13
+ ```
14
+
15
+ A `terraform.tf` file will be created in the current folder with the following command:
16
+
17
+ ```
18
+ fog_to_terraform -C path/to/fog.yml student1
19
+ ```
20
+
21
+ The output `/path/to/terraform.tf` will look like:
22
+
23
+ ```hcl
24
+ aws_access_key = "ACCESS"
25
+ aws_secret_key = "SECRET"
26
+ aws_key_path = "/path/to/ssh/student1.pem"
27
+ aws_key_name = "student1"
28
+ aws_region = "us-west-2"
29
+ network = "10.10"
30
+ ```
31
+
32
+ The keypair `student1` will be created for you in the AWS region (defaults to us-west-2) and the `ssh/student1.pem` is located in the current/target folder.
33
+
34
+ Requires
35
+ --------
36
+
37
+ - Ruby 1.9+
38
+ - RubyGems
39
+
40
+ Installation
41
+ ------------
42
+
43
+ Install using RubyGems:
44
+
45
+ ```
46
+ $ gem install fog_to_terraform
47
+ ```
48
+
49
+ Usage
50
+ -----
51
+
52
+ TODO: Write usage instructions here
53
+
54
+ Contributing
55
+ ------------
56
+
57
+ 1. Fork it ( https://github.com/[my-github-username]/fog_to_terraform/fork )
58
+ 2. Create your feature branch (`git checkout -b my-new-feature`\)
59
+ 3. Commit your changes (`git commit -am 'Add some feature'`\)
60
+ 4. Push to the branch (`git push origin my-new-feature`\)
61
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.expand_path("../../lib", __FILE__))
4
+ require 'fog_to_terraform'
5
+
6
+ FogToTerraform::App.start(ARGV)
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fog_to_terraform/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fog_to_terraform"
8
+ spec.version = FogToTerraform::VERSION
9
+ spec.authors = ["Dr Nic Williams"]
10
+ spec.email = ["drnicwilliams@gmail.com"]
11
+ spec.summary = %q{Creates a `terraform.tf` input variable file for terraform plans using credentials from a fog-formatted YAML file.}
12
+ spec.description = %q{Creates a `terraform.tf` input variable file for terraform plans using credentials from a fog-formatted YAML file.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "cyoi", "~> 0.11"
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
@@ -0,0 +1,6 @@
1
+ require "fog_to_terraform/version"
2
+ require "fog_to_terraform/app"
3
+
4
+ module FogToTerraform
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,82 @@
1
+ require "optparse"
2
+ require "yaml"
3
+ require "cyoi/cli/key_pair"
4
+
5
+ class FogToTerraform::App
6
+
7
+ def self.start(args)
8
+ # for cyoi
9
+ extend Cyoi::Cli::Helpers::Settings
10
+ @settings_dir = File.expand_path(".")
11
+
12
+ credentials_file = "~/.fog"
13
+ aws_region = "us-west-2"
14
+
15
+ opts = OptionParser.new do |opts|
16
+ opts.banner = "fog_to_terraform {options} credentials-key"
17
+ opts.separator ""
18
+ opts.separator "Options are ..."
19
+
20
+ opts.on_tail("-h", "--help", "-H", "Display this help message.") do
21
+ puts opts
22
+ exit 1
23
+ end
24
+
25
+ opts.on '--credentials-path="FILE"', '-C',
26
+ 'Path to the credentials file',
27
+ lambda { |value| credentials_file = value }
28
+ end
29
+ remaining_args = opts.parse(args)
30
+ credentials_key = remaining_args.shift || "default"
31
+
32
+ all_credentials = YAML.load_file(File.expand_path(credentials_file))
33
+ credentials = all_credentials[credentials_key.to_sym] || all_credentials[credentials_key.to_s]
34
+ unless credentials
35
+ $stderr.puts "Cannot find '#{credentials_key}' key in #{credentials_file}\n\n"
36
+ puts opts
37
+ exit 1
38
+ end
39
+
40
+ # Only AWS supported currently
41
+ aws_access_key_id = credentials[:aws_access_key_id]
42
+ aws_secret_access_key = credentials[:aws_secret_access_key]
43
+ unless aws_access_key_id && aws_secret_access_key
44
+ $stderr.puts "AWS credentials require :aws_access_key_id and :aws_secret_access_key keys"
45
+ exit 1
46
+ end
47
+
48
+ aws_key_path = "ssh/#{credentials_key.to_s}.pem"
49
+ aws_key_name = credentials_key.to_s
50
+
51
+ File.open("terraform.tf", "w") do |f|
52
+ f << <<-EOS
53
+ aws_access_key = "#{aws_access_key_id}"
54
+ aws_secret_key = "#{aws_secret_access_key}"
55
+ aws_key_path = "#{aws_key_path}"
56
+ aws_key_name = "#{aws_key_name}"
57
+ aws_region = "#{aws_region}"
58
+ network = "10.10"
59
+ EOS
60
+ end
61
+ puts "created terraform.tf"
62
+
63
+
64
+ settings.set "provider.name", "aws"
65
+ settings.set "provider.credentials.aws_access_key_id", aws_access_key_id
66
+ settings.set "provider.credentials.aws_secret_access_key", aws_secret_access_key
67
+ settings.set "provider.region", aws_region
68
+ save_settings!
69
+ reload_settings!
70
+
71
+ keypair = Cyoi::Cli::KeyPair.new([aws_key_name, settings_dir])
72
+ keypair.execute!
73
+
74
+ mkdir_p(File.dirname(aws_key_path))
75
+ chmod(0700, File.dirname(aws_key_path))
76
+
77
+ private_key = settings.key_pair.private_key
78
+ File.open(aws_key_path, "w") { |file| file << private_key }
79
+ chmod(0600, aws_key_path)
80
+ puts "created #{aws_key_path}"
81
+ end
82
+ end
@@ -0,0 +1,3 @@
1
+ module FogToTerraform
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fog_to_terraform
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dr Nic Williams
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: cyoi
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.11'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Creates a `terraform.tf` input variable file for terraform plans using
56
+ credentials from a fog-formatted YAML file.
57
+ email:
58
+ - drnicwilliams@gmail.com
59
+ executables:
60
+ - fog_to_terraform
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/fog_to_terraform
70
+ - fog_to_terraform.gemspec
71
+ - lib/fog_to_terraform.rb
72
+ - lib/fog_to_terraform/app.rb
73
+ - lib/fog_to_terraform/version.rb
74
+ homepage: ''
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.4.3
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Creates a `terraform.tf` input variable file for terraform plans using credentials
98
+ from a fog-formatted YAML file.
99
+ test_files: []