hashicorptools 0.5.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +14 -0
- data/.ruby-version +1 -1
- data/Gemfile +4 -4
- data/README.md +2 -0
- data/Rakefile +2 -2
- data/VERSION +1 -1
- data/hashicorptools.gemspec +28 -37
- data/lib/hashicorptools/auto_scaling_group.rb +10 -5
- data/lib/hashicorptools/code_deploy.rb +35 -8
- data/lib/hashicorptools/ec2_utilities.rb +7 -6
- data/lib/hashicorptools/host.rb +2 -0
- data/lib/hashicorptools/packer.rb +37 -23
- data/lib/hashicorptools.rb +0 -2
- data/spec/ec2_utilities_spec.rb +14 -0
- metadata +45 -14
- data/.travis.yml +0 -7
- data/spec/hashicorptools_spec.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e67a96a4dfde0442db2f2a7765bb8bccef2c2a241a6035a2cc71668cd7c52a2e
|
4
|
+
data.tar.gz: 160e51476f890b2f986277ef7caf9ae18cd72d3062ec0de4a28ef3352757a1a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3b67f51f3fbd83fc526ee4ac71623c045dcd2c0949d0eda49bdd0a09820933a1e2b38c290517a1627c8b6f4c960294e2a3269566337f798d7700c020200446c
|
7
|
+
data.tar.gz: 0c0f240592241afb1956f5f03c34d769b2161b01e50cde3c755eee8da6f5f671901abf6526c0a8bcb041467ac38b846d454f5e875c1c6eb78ce9e72a6b9af7ab
|
@@ -0,0 +1,14 @@
|
|
1
|
+
name: CI
|
2
|
+
on: [push]
|
3
|
+
|
4
|
+
jobs:
|
5
|
+
test:
|
6
|
+
runs-on: ubuntu-latest
|
7
|
+
steps:
|
8
|
+
- uses: actions/checkout@v2
|
9
|
+
- uses: ruby/setup-ruby@477b21f02be01bcb8030d50f37cfec92bfa615b6
|
10
|
+
with:
|
11
|
+
ruby-version: 2.7
|
12
|
+
bundler-cache: true
|
13
|
+
- run: bundle install
|
14
|
+
- run: bundle exec rspec
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.
|
1
|
+
ruby-2.7.4
|
data/Gemfile
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
|
3
|
-
|
4
|
-
gem 'aws-sdk', '~>
|
3
|
+
gem 'aws-sdk-autoscaling', '~> 1'
|
4
|
+
gem 'aws-sdk-codedeploy', '~> 1'
|
5
|
+
gem 'aws-sdk-ec2', '~> 1'
|
6
|
+
gem 'aws-sdk-elasticloadbalancing', '~> 1'
|
5
7
|
|
6
|
-
# this is somewhat undesirable but lets us update json gem version. We should really replace the old v1 code.
|
7
|
-
gem 'aws-sdk-v1-ruby24', github: 'seielit/aws-sdk-v1-ruby24', ref: 'aws-sdk-v1-ruby24'
|
8
8
|
gem 'dotenv', '~> 2.2', '>= 2.2.1'
|
9
9
|
gem 'thor', '>= 0.20.0'
|
10
10
|
gem 'activesupport', '>= 5.1.4'
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# hashicorptools
|
2
2
|
a set of ruby utilities for interacting with and wrapping packer, terraform and amazon web services.
|
3
3
|
|
4
|
+
![CI Status](https://github.com/controlshift/hashicorptools/actions/workflows/ci.yml/badge.svg)
|
5
|
+
|
4
6
|
## ec2_host
|
5
7
|
|
6
8
|
Allows quick lookup and ssh to machines by role and environment. Queries for instances by AWS tags.
|
data/Rakefile
CHANGED
@@ -15,12 +15,12 @@ require 'juwelier'
|
|
15
15
|
Juwelier::Tasks.new do |gem|
|
16
16
|
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
17
17
|
gem.name = "hashicorptools"
|
18
|
-
gem.homepage = "http://github.com/
|
18
|
+
gem.homepage = "http://github.com/controlshift/hashicorptools"
|
19
19
|
gem.license = "MIT"
|
20
20
|
gem.summary = %Q{Wrappers for terraform and packer}
|
21
21
|
gem.description = %Q{Wrappers for terraform and packer}
|
22
22
|
gem.email = "systems@controlshiftlabs.com"
|
23
|
-
gem.authors = [
|
23
|
+
gem.authors = ['Kathy Lu', 'Diego Marcet', 'Grey Moore', 'Nathan Woodhull']
|
24
24
|
gem.executables = ['ec2_host']
|
25
25
|
# dependencies defined in Gemfile
|
26
26
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
2.1.0
|
data/hashicorptools.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: hashicorptools
|
5
|
+
# stub: hashicorptools 2.1.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "hashicorptools".freeze
|
9
|
-
s.version = "
|
9
|
+
s.version = "2.1.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
13
|
-
s.authors = ["Nathan Woodhull".freeze]
|
14
|
-
s.date = "
|
13
|
+
s.authors = ["Kathy Lu".freeze, "Diego Marcet".freeze, "Grey Moore".freeze, "Nathan Woodhull".freeze]
|
14
|
+
s.date = "2022-02-03"
|
15
15
|
s.description = "Wrappers for terraform and packer".freeze
|
16
16
|
s.email = "systems@controlshiftlabs.com".freeze
|
17
17
|
s.executables = ["ec2_host".freeze]
|
@@ -20,9 +20,9 @@ Gem::Specification.new do |s|
|
|
20
20
|
"README.md"
|
21
21
|
]
|
22
22
|
s.files = [
|
23
|
+
".github/workflows/ci.yml",
|
23
24
|
".ruby-gemset",
|
24
25
|
".ruby-version",
|
25
|
-
".travis.yml",
|
26
26
|
"Gemfile",
|
27
27
|
"LICENSE",
|
28
28
|
"README.md",
|
@@ -39,47 +39,38 @@ Gem::Specification.new do |s|
|
|
39
39
|
"lib/hashicorptools/packer.rb",
|
40
40
|
"lib/hashicorptools/update_launch_configuration.rb",
|
41
41
|
"lib/hashicorptools/variables.rb",
|
42
|
-
"spec/
|
42
|
+
"spec/ec2_utilities_spec.rb",
|
43
43
|
"spec/spec_helper.rb"
|
44
44
|
]
|
45
|
-
s.homepage = "http://github.com/
|
45
|
+
s.homepage = "http://github.com/controlshift/hashicorptools".freeze
|
46
46
|
s.licenses = ["MIT".freeze]
|
47
|
-
s.rubygems_version = "3.
|
47
|
+
s.rubygems_version = "3.2.32".freeze
|
48
48
|
s.summary = "Wrappers for terraform and packer".freeze
|
49
49
|
|
50
50
|
if s.respond_to? :specification_version then
|
51
51
|
s.specification_version = 4
|
52
|
+
end
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
s.add_dependency(%q<aws-sdk-v1-ruby24>.freeze, [">= 0"])
|
69
|
-
s.add_dependency(%q<dotenv>.freeze, ["~> 2.2", ">= 2.2.1"])
|
70
|
-
s.add_dependency(%q<thor>.freeze, [">= 0.20.0"])
|
71
|
-
s.add_dependency(%q<activesupport>.freeze, [">= 5.1.4"])
|
72
|
-
s.add_dependency(%q<byebug>.freeze, [">= 10.0.2"])
|
73
|
-
s.add_dependency(%q<git>.freeze, ["> 1.3"])
|
74
|
-
s.add_dependency(%q<rspec>.freeze, ["> 3.7"])
|
75
|
-
s.add_dependency(%q<rdoc>.freeze, ["> 3.12"])
|
76
|
-
s.add_dependency(%q<bundler>.freeze, ["> 2.0"])
|
77
|
-
s.add_dependency(%q<juwelier>.freeze, [">= 0"])
|
78
|
-
s.add_dependency(%q<simplecov>.freeze, [">= 0"])
|
79
|
-
end
|
54
|
+
if s.respond_to? :add_runtime_dependency then
|
55
|
+
s.add_runtime_dependency(%q<aws-sdk-autoscaling>.freeze, ["~> 1"])
|
56
|
+
s.add_runtime_dependency(%q<aws-sdk-codedeploy>.freeze, ["~> 1"])
|
57
|
+
s.add_runtime_dependency(%q<aws-sdk-ec2>.freeze, ["~> 1"])
|
58
|
+
s.add_runtime_dependency(%q<aws-sdk-elasticloadbalancing>.freeze, ["~> 1"])
|
59
|
+
s.add_runtime_dependency(%q<dotenv>.freeze, ["~> 2.2", ">= 2.2.1"])
|
60
|
+
s.add_runtime_dependency(%q<thor>.freeze, [">= 0.20.0"])
|
61
|
+
s.add_runtime_dependency(%q<activesupport>.freeze, [">= 5.1.4"])
|
62
|
+
s.add_runtime_dependency(%q<byebug>.freeze, [">= 10.0.2"])
|
63
|
+
s.add_runtime_dependency(%q<git>.freeze, ["> 1.3"])
|
64
|
+
s.add_development_dependency(%q<rspec>.freeze, ["> 3.7"])
|
65
|
+
s.add_development_dependency(%q<rdoc>.freeze, ["> 3.12"])
|
66
|
+
s.add_development_dependency(%q<bundler>.freeze, ["> 2.0"])
|
67
|
+
s.add_development_dependency(%q<juwelier>.freeze, [">= 0"])
|
68
|
+
s.add_development_dependency(%q<simplecov>.freeze, [">= 0"])
|
80
69
|
else
|
81
|
-
s.add_dependency(%q<aws-sdk>.freeze, ["~>
|
82
|
-
s.add_dependency(%q<aws-sdk-
|
70
|
+
s.add_dependency(%q<aws-sdk-autoscaling>.freeze, ["~> 1"])
|
71
|
+
s.add_dependency(%q<aws-sdk-codedeploy>.freeze, ["~> 1"])
|
72
|
+
s.add_dependency(%q<aws-sdk-ec2>.freeze, ["~> 1"])
|
73
|
+
s.add_dependency(%q<aws-sdk-elasticloadbalancing>.freeze, ["~> 1"])
|
83
74
|
s.add_dependency(%q<dotenv>.freeze, ["~> 2.2", ">= 2.2.1"])
|
84
75
|
s.add_dependency(%q<thor>.freeze, [">= 0.20.0"])
|
85
76
|
s.add_dependency(%q<activesupport>.freeze, [">= 5.1.4"])
|
@@ -1,4 +1,7 @@
|
|
1
1
|
require "timeout"
|
2
|
+
require 'aws-sdk-autoscaling'
|
3
|
+
require 'aws-sdk-ec2'
|
4
|
+
require 'aws-sdk-elasticloadbalancing'
|
2
5
|
|
3
6
|
module Hashicorptools
|
4
7
|
class AutoScalingGroup
|
@@ -91,11 +94,13 @@ module Hashicorptools
|
|
91
94
|
end
|
92
95
|
|
93
96
|
def verify_all_instances_using_correct_ami
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
97
|
+
if group.launch_configuration_name
|
98
|
+
launch_configuration = Aws::AutoScaling::LaunchConfiguration.new(name: group.launch_configuration_name, client: autoscaling)
|
99
|
+
image_id = launch_configuration.image_id
|
100
|
+
group.instances.each do |i|
|
101
|
+
instance = Aws::EC2::Instance.new(i.instance_id, client: ec2)
|
102
|
+
raise "#{i.instance_id} has the incorrect AMI, not #{image_id} from current LaunchConfig" if instance.image_id != image_id
|
103
|
+
end
|
99
104
|
end
|
100
105
|
end
|
101
106
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require 'aws-sdk'
|
3
|
+
require 'aws-sdk-codedeploy'
|
4
4
|
require 'dotenv'
|
5
5
|
require 'git'
|
6
6
|
require 'logger'
|
@@ -31,6 +31,9 @@ module Hashicorptools
|
|
31
31
|
})
|
32
32
|
output "created deployment #{response.deployment_id}"
|
33
33
|
output "https://console.aws.amazon.com/codedeploy/home?region=#{aws_region}#/deployments/#{response.deployment_id}"
|
34
|
+
|
35
|
+
# Classes that override this method should return true for a successful deployment, false otherwise
|
36
|
+
return true
|
34
37
|
end
|
35
38
|
|
36
39
|
private
|
@@ -47,23 +50,25 @@ module Hashicorptools
|
|
47
50
|
class CodeDeploy < Thor
|
48
51
|
AWS_REGION_US_EAST_1 = 'us-east-1'
|
49
52
|
|
53
|
+
attr_reader :git
|
54
|
+
|
50
55
|
desc 'deploy', 'deploy latest code to environment'
|
51
56
|
option :environment, required: true
|
52
57
|
option :branch
|
53
58
|
option :aws_regions, type: :array
|
54
59
|
option :commit
|
55
60
|
def deploy
|
56
|
-
|
61
|
+
@git = Git.open('..')
|
57
62
|
|
58
63
|
# We set defaults (depending on environment) for aws_regions if not passed in
|
59
64
|
aws_regions = options[:aws_regions] || default_regions
|
60
65
|
|
61
66
|
commit = if options[:commit].present?
|
62
|
-
|
67
|
+
git.gcommit(options[:commit])
|
63
68
|
else
|
64
69
|
branch = options[:branch].nil? ? :main : options[:branch].to_sym
|
65
|
-
|
66
|
-
|
70
|
+
git.checkout(branch)
|
71
|
+
git.log.first
|
67
72
|
end
|
68
73
|
|
69
74
|
puts "Deploying to environment #{options[:environment]} - regions: #{aws_regions.join(', ')}
|
@@ -72,9 +77,11 @@ module Hashicorptools
|
|
72
77
|
|
73
78
|
puts "Deploying for regions: #{aws_regions}"
|
74
79
|
|
75
|
-
|
80
|
+
all_succeeded = true
|
76
81
|
aws_regions.each_slice(2) do |aws_regions_batch|
|
77
82
|
puts "Deploying for batch of regions: #{aws_regions_batch}"
|
83
|
+
|
84
|
+
threads = []
|
78
85
|
aws_regions_batch.each do |aws_region|
|
79
86
|
thread = Thread.new{ region_deployment(aws_region).create_deployment(commit.sha, commit.message) }
|
80
87
|
threads.push(thread)
|
@@ -82,13 +89,24 @@ module Hashicorptools
|
|
82
89
|
|
83
90
|
threads.each_with_index do |thread, index|
|
84
91
|
begin
|
85
|
-
thread.join
|
86
|
-
|
92
|
+
# thread.value waits for the thread to finish with #join, then returns the value of the expression
|
93
|
+
thread_succeeded = thread.value
|
94
|
+
all_succeeded = all_succeeded && thread_succeeded
|
95
|
+
rescue StandardError => e
|
87
96
|
# Don't quit whole program on exception in thread, just print exception and exit thread
|
88
97
|
puts "[#{aws_regions[index]}] EXCEPTION: #{e}"
|
98
|
+
all_succeeded = false
|
89
99
|
end
|
90
100
|
end
|
91
101
|
end
|
102
|
+
|
103
|
+
# If deployment succeeded, tag the commit that was deployed for the environment
|
104
|
+
if all_succeeded
|
105
|
+
create_tag(options[:environment], commit)
|
106
|
+
end
|
107
|
+
|
108
|
+
# Return a success or failure status code to be consumed by bash
|
109
|
+
exit(all_succeeded)
|
92
110
|
end
|
93
111
|
|
94
112
|
private
|
@@ -100,5 +118,14 @@ module Hashicorptools
|
|
100
118
|
def default_regions
|
101
119
|
[AWS_REGION_US_EAST_1]
|
102
120
|
end
|
121
|
+
|
122
|
+
def create_tag(environment, commit)
|
123
|
+
# Delete previous tag in the remote repository
|
124
|
+
git.push('origin', ":#{environment}")
|
125
|
+
|
126
|
+
# Create the tag (replacing if it already exists) and push to remote repository
|
127
|
+
git.add_tag(environment, commit.sha, {f: true})
|
128
|
+
git.push('origin', environment)
|
129
|
+
end
|
103
130
|
end
|
104
131
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'aws-sdk-ec2'
|
2
|
+
|
1
3
|
module Hashicorptools
|
2
4
|
module Ec2Utilities
|
3
5
|
def current_ami(tag = tag_name)
|
@@ -5,7 +7,8 @@ module Hashicorptools
|
|
5
7
|
end
|
6
8
|
|
7
9
|
def amis(tag = tag_name)
|
8
|
-
|
10
|
+
images = ec2.describe_images({owners: ['self'], filters: [{name: 'tag:Name', values: [tag]}]}).images
|
11
|
+
sort_by_created_at(images)
|
9
12
|
end
|
10
13
|
|
11
14
|
def ec2
|
@@ -17,17 +20,15 @@ module Hashicorptools
|
|
17
20
|
'us-east-1'
|
18
21
|
end
|
19
22
|
|
20
|
-
@_ec2 =
|
23
|
+
@_ec2 = Aws::EC2::Client.new(region: reg)
|
21
24
|
end
|
22
25
|
|
23
26
|
def vpc_with_name(name)
|
24
|
-
|
25
|
-
vpcs.first
|
27
|
+
ec2.describe_vpcs({filters: [{name: 'tag:Name', values: [name]}]}).vpcs.first
|
26
28
|
end
|
27
29
|
|
28
30
|
def internet_gateway_for_vpc(vpc_id)
|
29
|
-
|
30
|
-
igs.first
|
31
|
+
ec2.describe_internet_gateways({filters: [{name: 'attachment.vpc-id', values: [vpc_id]}]}).internet_gateways.first
|
31
32
|
end
|
32
33
|
|
33
34
|
def sort_by_created_at(collection)
|
data/lib/hashicorptools/host.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'aws-sdk-autoscaling'
|
2
|
+
require 'aws-sdk-ec2'
|
3
|
+
|
1
4
|
module Hashicorptools
|
2
5
|
NUMBER_OF_AMIS_TO_KEEP = 2
|
3
6
|
|
@@ -45,7 +48,7 @@ module Hashicorptools
|
|
45
48
|
|
46
49
|
desc "clean_snapshots", "clean obsolete EBS snapshots not associated with any AMI"
|
47
50
|
def clean_snapshots
|
48
|
-
snapshots = ec2.
|
51
|
+
snapshots = ec2.describe_snapshots({owner_ids: ['self']}).snapshots
|
49
52
|
snapshots.each do |snapshot|
|
50
53
|
match = snapshot.description.match(/Created by CreateImage\(.+\) for (ami-[0-9a-f]+) from vol-.+/)
|
51
54
|
if match.nil?
|
@@ -54,25 +57,28 @@ module Hashicorptools
|
|
54
57
|
end
|
55
58
|
|
56
59
|
ami_id = match[1]
|
57
|
-
unless
|
58
|
-
puts "Removing obsolete snapshot #{snapshot.
|
59
|
-
|
60
|
-
snapshot.delete
|
60
|
+
unless Aws::EC2::Image.new(ami_id, region: region).exists?
|
61
|
+
puts "Removing obsolete snapshot #{snapshot.snapshot_id} - #{snapshot.description}"
|
62
|
+
ec2.delete_snapshot({snapshot_id: snapshot.snapshot_id})
|
61
63
|
end
|
62
64
|
end
|
63
65
|
end
|
64
66
|
|
65
67
|
desc "boot", "start up an instance of the latest version of AMI"
|
66
68
|
def boot
|
67
|
-
run_instances_resp = ec2.run_instances(
|
69
|
+
run_instances_resp = ec2.run_instances({
|
70
|
+
image_id: current_ami('base-image').image_id,
|
68
71
|
min_count: 1,
|
69
72
|
max_count: 1,
|
70
|
-
instance_type: "t2.micro"
|
73
|
+
instance_type: "t2.micro"
|
74
|
+
})
|
71
75
|
|
72
|
-
ec2.create_tags(
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
+
ec2.create_tags({
|
77
|
+
resources: run_instances_resp.instances.collect(&:instance_id),
|
78
|
+
tags: [ {key: 'Name', value: "packer test boot #{tag_name}"},
|
79
|
+
{key: 'environment', value: 'packer-development'},
|
80
|
+
{key: 'temporary', value: 'kill me'}]
|
81
|
+
})
|
76
82
|
|
77
83
|
require 'byebug'
|
78
84
|
byebug
|
@@ -106,7 +112,7 @@ module Hashicorptools
|
|
106
112
|
end
|
107
113
|
|
108
114
|
def ami_building_subnet_id
|
109
|
-
ec2.
|
115
|
+
ec2.describe_subnets({filters: [{name: "vpc-id", values: [ami_building_vpc_id]}]}).subnets.first.subnet_id
|
110
116
|
end
|
111
117
|
|
112
118
|
def format_variable(key, value)
|
@@ -133,15 +139,16 @@ module Hashicorptools
|
|
133
139
|
@auto_scaling ||= Aws::AutoScaling::Client.new(region: client_region)
|
134
140
|
end
|
135
141
|
|
136
|
-
def
|
137
|
-
@
|
142
|
+
def regional_ec2_client(client_region=region)
|
143
|
+
@_regional_ec2_clients = {} if @_regional_ec2_clients.nil?
|
144
|
+
@_regional_ec2_clients[client_region] ||= Aws::EC2::Client.new(region: client_region)
|
138
145
|
end
|
139
146
|
|
140
147
|
def amis_in_use(client_region)
|
141
148
|
launch_configs = auto_scaling(client_region).describe_launch_configurations
|
142
149
|
image_ids = launch_configs.data['launch_configurations'].collect{|lc| lc.image_id}.flatten
|
143
150
|
|
144
|
-
ec2_reservations =
|
151
|
+
ec2_reservations = regional_ec2_client(client_region).describe_instances
|
145
152
|
image_ids << ec2_reservations.reservations.collect{|res| res.instances.collect{|r| r.image_id}}.flatten
|
146
153
|
image_ids.flatten
|
147
154
|
end
|
@@ -170,7 +177,9 @@ module Hashicorptools
|
|
170
177
|
amis_to_remove.each do |ami|
|
171
178
|
ebs_mappings = ami.block_device_mappings
|
172
179
|
puts "Deregistering #{ami.image_id}"
|
173
|
-
|
180
|
+
regional_ec2_client(region_to_clean).deregister_image({
|
181
|
+
image_id: ami.image_id
|
182
|
+
})
|
174
183
|
delete_ami_snapshots(ebs_mappings, snapshot_region: region_to_clean)
|
175
184
|
end
|
176
185
|
|
@@ -184,16 +193,21 @@ module Hashicorptools
|
|
184
193
|
end
|
185
194
|
|
186
195
|
def amis_in_region(ami_region)
|
187
|
-
|
188
|
-
|
189
|
-
|
196
|
+
images = regional_ec2_client(ami_region).describe_images({
|
197
|
+
owners: ['self'],
|
198
|
+
filters: [{name: 'tag:Name', values: [tag_name]}]
|
199
|
+
}).images
|
200
|
+
sort_by_created_at(images)
|
190
201
|
end
|
191
202
|
|
192
203
|
def delete_ami_snapshots(ebs_mappings, snapshot_region:)
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
204
|
+
ec2_client = regional_ec2_client(snapshot_region)
|
205
|
+
|
206
|
+
ebs_mappings.each do |ebs_mapping|
|
207
|
+
unless ebs_mapping.ebs.nil?
|
208
|
+
puts "Deleting snapshot #{ebs_mapping.ebs.snapshot_id}"
|
209
|
+
ec2_client.delete_snapshot({snapshot_id: ebs_mapping.ebs.snapshot_id})
|
210
|
+
end
|
197
211
|
end
|
198
212
|
end
|
199
213
|
end
|
data/lib/hashicorptools.rb
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Hashicorptools::Ec2Utilities, type: :helper do
|
4
|
+
let(:including_class) { Class.new { include Hashicorptools::Ec2Utilities } }
|
5
|
+
|
6
|
+
subject { including_class.new }
|
7
|
+
|
8
|
+
describe '#ec2' do
|
9
|
+
it 'should return a client' do
|
10
|
+
client = subject.ec2
|
11
|
+
expect(client).to be_a Aws::EC2::Client
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
CHANGED
@@ -1,43 +1,74 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hashicorptools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
+
- Kathy Lu
|
8
|
+
- Diego Marcet
|
9
|
+
- Grey Moore
|
7
10
|
- Nathan Woodhull
|
8
11
|
autorequire:
|
9
12
|
bindir: bin
|
10
13
|
cert_chain: []
|
11
|
-
date:
|
14
|
+
date: 2022-02-03 00:00:00.000000000 Z
|
12
15
|
dependencies:
|
13
16
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: aws-sdk
|
17
|
+
name: aws-sdk-autoscaling
|
15
18
|
requirement: !ruby/object:Gem::Requirement
|
16
19
|
requirements:
|
17
20
|
- - "~>"
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
22
|
+
version: '1'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
27
|
- - "~>"
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
29
|
+
version: '1'
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: aws-sdk-
|
31
|
+
name: aws-sdk-codedeploy
|
29
32
|
requirement: !ruby/object:Gem::Requirement
|
30
33
|
requirements:
|
31
|
-
- - "
|
34
|
+
- - "~>"
|
32
35
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
36
|
+
version: '1'
|
34
37
|
type: :runtime
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
38
|
-
- - "
|
41
|
+
- - "~>"
|
39
42
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
43
|
+
version: '1'
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: aws-sdk-ec2
|
46
|
+
requirement: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - "~>"
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '1'
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '1'
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: aws-sdk-elasticloadbalancing
|
60
|
+
requirement: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - "~>"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '1'
|
65
|
+
type: :runtime
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '1'
|
41
72
|
- !ruby/object:Gem::Dependency
|
42
73
|
name: dotenv
|
43
74
|
requirement: !ruby/object:Gem::Requirement
|
@@ -193,9 +224,9 @@ extra_rdoc_files:
|
|
193
224
|
- LICENSE
|
194
225
|
- README.md
|
195
226
|
files:
|
227
|
+
- ".github/workflows/ci.yml"
|
196
228
|
- ".ruby-gemset"
|
197
229
|
- ".ruby-version"
|
198
|
-
- ".travis.yml"
|
199
230
|
- Gemfile
|
200
231
|
- LICENSE
|
201
232
|
- README.md
|
@@ -212,9 +243,9 @@ files:
|
|
212
243
|
- lib/hashicorptools/packer.rb
|
213
244
|
- lib/hashicorptools/update_launch_configuration.rb
|
214
245
|
- lib/hashicorptools/variables.rb
|
215
|
-
- spec/
|
246
|
+
- spec/ec2_utilities_spec.rb
|
216
247
|
- spec/spec_helper.rb
|
217
|
-
homepage: http://github.com/
|
248
|
+
homepage: http://github.com/controlshift/hashicorptools
|
218
249
|
licenses:
|
219
250
|
- MIT
|
220
251
|
metadata: {}
|
@@ -233,7 +264,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
233
264
|
- !ruby/object:Gem::Version
|
234
265
|
version: '0'
|
235
266
|
requirements: []
|
236
|
-
rubygems_version: 3.
|
267
|
+
rubygems_version: 3.2.32
|
237
268
|
signing_key:
|
238
269
|
specification_version: 4
|
239
270
|
summary: Wrappers for terraform and packer
|
data/.travis.yml
DELETED