TerraformDevKit 0.3.7 → 0.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.appveyor.yml +0 -0
- data/.gitignore +0 -0
- data/.rspec +2 -2
- data/.travis.yml +8 -8
- data/Gemfile +4 -4
- data/LICENSE +0 -0
- data/README.md +239 -239
- data/Rakefile +6 -6
- data/TerraformDevKit.gemspec +36 -36
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/exe/wait_for_url +0 -0
- data/lib/TerraformDevKit.rb +21 -21
- data/lib/TerraformDevKit/aws/aws.rb +65 -65
- data/lib/TerraformDevKit/aws/cloudfront.rb +20 -20
- data/lib/TerraformDevKit/aws/dynamodb.rb +46 -46
- data/lib/TerraformDevKit/aws/s3.rb +44 -44
- data/lib/TerraformDevKit/aws/terraform_remote_state.rb +67 -67
- data/lib/TerraformDevKit/backup_state.rb +18 -18
- data/lib/TerraformDevKit/command.rb +31 -31
- data/lib/TerraformDevKit/config.rb +0 -0
- data/lib/TerraformDevKit/download.rb +0 -0
- data/lib/TerraformDevKit/environment.rb +0 -0
- data/lib/TerraformDevKit/errors/command_error.rb +0 -0
- data/lib/TerraformDevKit/extended_file_utils.rb +21 -21
- data/lib/TerraformDevKit/os.rb +0 -0
- data/lib/TerraformDevKit/project_config.rb +10 -10
- data/lib/TerraformDevKit/request.rb +0 -0
- data/lib/TerraformDevKit/retry.rb +0 -0
- data/lib/TerraformDevKit/template_config_file.rb +0 -0
- data/lib/TerraformDevKit/template_renderer.rb +0 -0
- data/lib/TerraformDevKit/terraform_config_manager.rb +0 -0
- data/lib/TerraformDevKit/terraform_env_manager.rb +0 -0
- data/lib/TerraformDevKit/terraform_installer.rb +1 -1
- data/lib/TerraformDevKit/terraform_log_filter.rb +0 -0
- data/lib/TerraformDevKit/url.rb +0 -0
- data/lib/TerraformDevKit/version.rb +3 -3
- data/lib/TerraformDevKit/zip_file_generator.rb +47 -47
- data/tasks/devkit.rake +187 -187
- metadata +7 -7
@@ -1,67 +1,67 @@
|
|
1
|
-
require 'aws-sdk-dynamodb'
|
2
|
-
require 'aws-sdk-s3'
|
3
|
-
|
4
|
-
module TerraformDevKit
|
5
|
-
module Aws
|
6
|
-
class TerraformRemoteState
|
7
|
-
ATTRIBUTES = [
|
8
|
-
{
|
9
|
-
attribute_name: 'LockID',
|
10
|
-
attribute_type: 'S'
|
11
|
-
}
|
12
|
-
]
|
13
|
-
KEYS = [
|
14
|
-
{
|
15
|
-
attribute_name: 'LockID',
|
16
|
-
key_type: 'HASH'
|
17
|
-
}
|
18
|
-
]
|
19
|
-
|
20
|
-
def initialize(dynamodb, s3)
|
21
|
-
@dynamodb = dynamodb
|
22
|
-
@s3 = s3
|
23
|
-
end
|
24
|
-
|
25
|
-
def init(environment, project)
|
26
|
-
table_name = table_name(environment, project)
|
27
|
-
return if lock_table_exists_and_is_active(table_name)
|
28
|
-
|
29
|
-
@dynamodb.create_table(table_name, ATTRIBUTES, KEYS, 1, 1)
|
30
|
-
|
31
|
-
begin
|
32
|
-
@s3.create_bucket(state_bucket_name(environment, project))
|
33
|
-
rescue ::Aws::S3::Errors::BucketAlreadyOwnedByYou
|
34
|
-
return
|
35
|
-
end
|
36
|
-
|
37
|
-
sleep(0.2) until lock_table_exists_and_is_active(table_name)
|
38
|
-
end
|
39
|
-
|
40
|
-
def destroy(environment, project)
|
41
|
-
table_name = table_name(environment, project)
|
42
|
-
|
43
|
-
@dynamodb.delete_table(table_name)
|
44
|
-
@s3.delete_bucket(state_bucket_name(environment, project))
|
45
|
-
end
|
46
|
-
|
47
|
-
private_class_method
|
48
|
-
def lock_table_exists_and_is_active(table_name)
|
49
|
-
begin
|
50
|
-
return @dynamodb.get_table_status(table_name) == 'ACTIVE'
|
51
|
-
rescue ::Aws::DynamoDB::Errors::ResourceNotFoundException
|
52
|
-
return false
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
private_class_method
|
57
|
-
def table_name(environment, project)
|
58
|
-
"#{project.acronym}-#{environment.name}-lock-table"
|
59
|
-
end
|
60
|
-
|
61
|
-
private_class_method
|
62
|
-
def state_bucket_name(environment, project)
|
63
|
-
"#{project.name}-#{environment.name}-state"
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
1
|
+
require 'aws-sdk-dynamodb'
|
2
|
+
require 'aws-sdk-s3'
|
3
|
+
|
4
|
+
module TerraformDevKit
|
5
|
+
module Aws
|
6
|
+
class TerraformRemoteState
|
7
|
+
ATTRIBUTES = [
|
8
|
+
{
|
9
|
+
attribute_name: 'LockID',
|
10
|
+
attribute_type: 'S'
|
11
|
+
}
|
12
|
+
]
|
13
|
+
KEYS = [
|
14
|
+
{
|
15
|
+
attribute_name: 'LockID',
|
16
|
+
key_type: 'HASH'
|
17
|
+
}
|
18
|
+
]
|
19
|
+
|
20
|
+
def initialize(dynamodb, s3)
|
21
|
+
@dynamodb = dynamodb
|
22
|
+
@s3 = s3
|
23
|
+
end
|
24
|
+
|
25
|
+
def init(environment, project)
|
26
|
+
table_name = table_name(environment, project)
|
27
|
+
return if lock_table_exists_and_is_active(table_name)
|
28
|
+
|
29
|
+
@dynamodb.create_table(table_name, ATTRIBUTES, KEYS, 1, 1)
|
30
|
+
|
31
|
+
begin
|
32
|
+
@s3.create_bucket(state_bucket_name(environment, project))
|
33
|
+
rescue ::Aws::S3::Errors::BucketAlreadyOwnedByYou
|
34
|
+
return
|
35
|
+
end
|
36
|
+
|
37
|
+
sleep(0.2) until lock_table_exists_and_is_active(table_name)
|
38
|
+
end
|
39
|
+
|
40
|
+
def destroy(environment, project)
|
41
|
+
table_name = table_name(environment, project)
|
42
|
+
|
43
|
+
@dynamodb.delete_table(table_name)
|
44
|
+
@s3.delete_bucket(state_bucket_name(environment, project))
|
45
|
+
end
|
46
|
+
|
47
|
+
private_class_method
|
48
|
+
def lock_table_exists_and_is_active(table_name)
|
49
|
+
begin
|
50
|
+
return @dynamodb.get_table_status(table_name) == 'ACTIVE'
|
51
|
+
rescue ::Aws::DynamoDB::Errors::ResourceNotFoundException
|
52
|
+
return false
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
private_class_method
|
57
|
+
def table_name(environment, project)
|
58
|
+
"#{project.acronym}-#{environment.name}-lock-table"
|
59
|
+
end
|
60
|
+
|
61
|
+
private_class_method
|
62
|
+
def state_bucket_name(environment, project)
|
63
|
+
"#{project.name}-#{environment.name}-state"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -1,18 +1,18 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
|
3
|
-
require_relative 'zip_file_generator'
|
4
|
-
|
5
|
-
module TerraformDevKit
|
6
|
-
class BackupState
|
7
|
-
def self.backup(prefix)
|
8
|
-
backup_path = ENV['TM_STATE_BACKUP_PATH']
|
9
|
-
return if backup_path.nil?
|
10
|
-
|
11
|
-
filename = "#{prefix}failure_state.zip"
|
12
|
-
ZipFileGenerator.new('.', filename).write
|
13
|
-
|
14
|
-
FileUtils.cp(filename, backup_path)
|
15
|
-
puts "Copied state to #{File.join(backup_path, filename)}"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
require_relative 'zip_file_generator'
|
4
|
+
|
5
|
+
module TerraformDevKit
|
6
|
+
class BackupState
|
7
|
+
def self.backup(prefix)
|
8
|
+
backup_path = ENV['TM_STATE_BACKUP_PATH']
|
9
|
+
return if backup_path.nil?
|
10
|
+
|
11
|
+
filename = "#{prefix}failure_state.zip"
|
12
|
+
ZipFileGenerator.new('.', filename).write
|
13
|
+
|
14
|
+
FileUtils.cp(filename, backup_path)
|
15
|
+
puts "Copied state to #{File.join(backup_path, filename)}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,31 +1,31 @@
|
|
1
|
-
require 'open3'
|
2
|
-
|
3
|
-
require 'TerraformDevKit/errors/command_error'
|
4
|
-
|
5
|
-
module TerraformDevKit
|
6
|
-
class Command
|
7
|
-
def self.run(cmd, directory: Dir.pwd, print_output: true)
|
8
|
-
out = IO.popen(cmd, err: %i[child out], chdir: directory) do |io|
|
9
|
-
begin
|
10
|
-
out = ''
|
11
|
-
loop do
|
12
|
-
chunk = io.readpartial(4096)
|
13
|
-
print chunk if print_output
|
14
|
-
out += chunk
|
15
|
-
end
|
16
|
-
rescue EOFError; end
|
17
|
-
out
|
18
|
-
end
|
19
|
-
|
20
|
-
out = process_output(out)
|
21
|
-
$?.exitstatus.zero? || (raise CommandError.new(cmd, out))
|
22
|
-
out
|
23
|
-
end
|
24
|
-
|
25
|
-
private_class_method
|
26
|
-
def self.process_output(out)
|
27
|
-
out.split("\n")
|
28
|
-
.map { |line| line.tr("\r\n", '') }
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
1
|
+
require 'open3'
|
2
|
+
|
3
|
+
require 'TerraformDevKit/errors/command_error'
|
4
|
+
|
5
|
+
module TerraformDevKit
|
6
|
+
class Command
|
7
|
+
def self.run(cmd, directory: Dir.pwd, print_output: true)
|
8
|
+
out = IO.popen(cmd, err: %i[child out], chdir: directory) do |io|
|
9
|
+
begin
|
10
|
+
out = ''
|
11
|
+
loop do
|
12
|
+
chunk = io.readpartial(4096)
|
13
|
+
print chunk if print_output
|
14
|
+
out += chunk
|
15
|
+
end
|
16
|
+
rescue EOFError; end
|
17
|
+
out
|
18
|
+
end
|
19
|
+
|
20
|
+
out = process_output(out)
|
21
|
+
$?.exitstatus.zero? || (raise CommandError.new(cmd, out))
|
22
|
+
out
|
23
|
+
end
|
24
|
+
|
25
|
+
private_class_method
|
26
|
+
def self.process_output(out)
|
27
|
+
out.split("\n")
|
28
|
+
.map { |line| line.tr("\r\n", '') }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,21 +1,21 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require 'TerraformDevKit/command'
|
3
|
-
require 'TerraformDevKit/os'
|
4
|
-
|
5
|
-
module TerraformDevKit::ExtendedFileUtils
|
6
|
-
def self.copy(files, dest_base_path)
|
7
|
-
files.to_h.each do |dest, src|
|
8
|
-
dest = File.join(dest_base_path, dest)
|
9
|
-
FileUtils.copy_entry(src, dest)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.rm_rf(list, options = {})
|
14
|
-
if TerraformDevKit::OS.host_os == 'windows'
|
15
|
-
windows_path = TerraformDevKit::OS.convert_to_local_path(list)
|
16
|
-
TerraformDevKit::Command.run("rmdir /s/q \"#{windows_path}\"")
|
17
|
-
else
|
18
|
-
FileUtils.rm_rf(list, options)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
1
|
+
require 'fileutils'
|
2
|
+
require 'TerraformDevKit/command'
|
3
|
+
require 'TerraformDevKit/os'
|
4
|
+
|
5
|
+
module TerraformDevKit::ExtendedFileUtils
|
6
|
+
def self.copy(files, dest_base_path)
|
7
|
+
files.to_h.each do |dest, src|
|
8
|
+
dest = File.join(dest_base_path, dest)
|
9
|
+
FileUtils.copy_entry(src, dest)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.rm_rf(list, options = {})
|
14
|
+
if TerraformDevKit::OS.host_os == 'windows'
|
15
|
+
windows_path = TerraformDevKit::OS.convert_to_local_path(list)
|
16
|
+
TerraformDevKit::Command.run("rmdir /s/q \"#{windows_path}\"")
|
17
|
+
else
|
18
|
+
FileUtils.rm_rf(list, options)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/TerraformDevKit/os.rb
CHANGED
File without changes
|
@@ -1,10 +1,10 @@
|
|
1
|
-
module TerraformDevKit
|
2
|
-
class ProjectConfig
|
3
|
-
attr_reader :name, :acronym
|
4
|
-
|
5
|
-
def initialize(project_name, project_acronym = nil)
|
6
|
-
@name = project_name.tr(' ', '-').downcase
|
7
|
-
@acronym = project_acronym || project_name.scan(/\b[a-z]/i).join.upcase
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
1
|
+
module TerraformDevKit
|
2
|
+
class ProjectConfig
|
3
|
+
attr_reader :name, :acronym
|
4
|
+
|
5
|
+
def initialize(project_name, project_acronym = nil)
|
6
|
+
@name = project_name.tr(' ', '-').downcase
|
7
|
+
@acronym = project_acronym || project_name.scan(/\b[a-z]/i).join.upcase
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/TerraformDevKit/url.rb
CHANGED
File without changes
|
@@ -1,3 +1,3 @@
|
|
1
|
-
module TerraformDevKit
|
2
|
-
VERSION = '0.3.
|
3
|
-
end
|
1
|
+
module TerraformDevKit
|
2
|
+
VERSION = '0.3.8'.freeze
|
3
|
+
end
|
@@ -1,47 +1,47 @@
|
|
1
|
-
require 'zip'
|
2
|
-
|
3
|
-
module TerraformDevKit
|
4
|
-
class ZipFileGenerator
|
5
|
-
def initialize(input_dir, output_file)
|
6
|
-
@input_dir = input_dir
|
7
|
-
@output_file = output_file
|
8
|
-
end
|
9
|
-
|
10
|
-
def write
|
11
|
-
entries = Dir.entries(@input_dir)
|
12
|
-
entries.delete('.')
|
13
|
-
entries.delete('..')
|
14
|
-
Zip::File.open(@output_file, Zip::File::CREATE) do |zipfile|
|
15
|
-
write_entries(entries, '', zipfile)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def write_entries(entries, path, zipfile)
|
22
|
-
entries.each do |e|
|
23
|
-
zip_file_path = path == '' ? e : File.join(path, e)
|
24
|
-
disk_file_path = File.join(@input_dir, zip_file_path)
|
25
|
-
if File.directory?(disk_file_path)
|
26
|
-
write_directory(disk_file_path, zip_file_path, zipfile)
|
27
|
-
else
|
28
|
-
write_file(disk_file_path, zip_file_path, zipfile)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def write_directory(disk_file_path, zip_file_path, zipfile)
|
34
|
-
zipfile.mkdir(zip_file_path)
|
35
|
-
subdir = Dir.entries(disk_file_path)
|
36
|
-
subdir.delete('.')
|
37
|
-
subdir.delete('..')
|
38
|
-
write_entries(subdir, zip_file_path, zipfile)
|
39
|
-
end
|
40
|
-
|
41
|
-
def write_file(disk_file_path, zip_file_path, zipfile)
|
42
|
-
zipfile.get_output_stream(zip_file_path) do |f|
|
43
|
-
f.puts(File.open(disk_file_path, 'rb').read)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
1
|
+
require 'zip'
|
2
|
+
|
3
|
+
module TerraformDevKit
|
4
|
+
class ZipFileGenerator
|
5
|
+
def initialize(input_dir, output_file)
|
6
|
+
@input_dir = input_dir
|
7
|
+
@output_file = output_file
|
8
|
+
end
|
9
|
+
|
10
|
+
def write
|
11
|
+
entries = Dir.entries(@input_dir)
|
12
|
+
entries.delete('.')
|
13
|
+
entries.delete('..')
|
14
|
+
Zip::File.open(@output_file, Zip::File::CREATE) do |zipfile|
|
15
|
+
write_entries(entries, '', zipfile)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def write_entries(entries, path, zipfile)
|
22
|
+
entries.each do |e|
|
23
|
+
zip_file_path = path == '' ? e : File.join(path, e)
|
24
|
+
disk_file_path = File.join(@input_dir, zip_file_path)
|
25
|
+
if File.directory?(disk_file_path)
|
26
|
+
write_directory(disk_file_path, zip_file_path, zipfile)
|
27
|
+
else
|
28
|
+
write_file(disk_file_path, zip_file_path, zipfile)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def write_directory(disk_file_path, zip_file_path, zipfile)
|
34
|
+
zipfile.mkdir(zip_file_path)
|
35
|
+
subdir = Dir.entries(disk_file_path)
|
36
|
+
subdir.delete('.')
|
37
|
+
subdir.delete('..')
|
38
|
+
write_entries(subdir, zip_file_path, zipfile)
|
39
|
+
end
|
40
|
+
|
41
|
+
def write_file(disk_file_path, zip_file_path, zipfile)
|
42
|
+
zipfile.get_output_stream(zip_file_path) do |f|
|
43
|
+
f.puts(File.open(disk_file_path, 'rb').read)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|