aws-cft-tools 0.1.0

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.
Files changed (68) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +10 -0
  3. data/.gitignore +52 -0
  4. data/.rspec +2 -0
  5. data/.rubocop.yml +19 -0
  6. data/.travis.yml +5 -0
  7. data/.yardopts +1 -0
  8. data/BEST-PRACTICES.md +136 -0
  9. data/CONTRIBUTING.md +38 -0
  10. data/Gemfile +8 -0
  11. data/LICENSE +15 -0
  12. data/README.md +118 -0
  13. data/Rakefile +17 -0
  14. data/USAGE.adoc +404 -0
  15. data/aws-cft-tools.gemspec +53 -0
  16. data/bin/console +15 -0
  17. data/bin/setup +8 -0
  18. data/code.json +24 -0
  19. data/exe/aws-cft +176 -0
  20. data/lib/aws-cft-tools.rb +3 -0
  21. data/lib/aws_cft_tools.rb +31 -0
  22. data/lib/aws_cft_tools/aws_enumerator.rb +55 -0
  23. data/lib/aws_cft_tools/change.rb +66 -0
  24. data/lib/aws_cft_tools/client.rb +84 -0
  25. data/lib/aws_cft_tools/client/base.rb +40 -0
  26. data/lib/aws_cft_tools/client/cft.rb +93 -0
  27. data/lib/aws_cft_tools/client/cft/changeset_management.rb +109 -0
  28. data/lib/aws_cft_tools/client/cft/stack_management.rb +85 -0
  29. data/lib/aws_cft_tools/client/ec2.rb +136 -0
  30. data/lib/aws_cft_tools/client/templates.rb +84 -0
  31. data/lib/aws_cft_tools/deletion_change.rb +43 -0
  32. data/lib/aws_cft_tools/dependency_tree.rb +109 -0
  33. data/lib/aws_cft_tools/dependency_tree/nodes.rb +71 -0
  34. data/lib/aws_cft_tools/dependency_tree/variables.rb +37 -0
  35. data/lib/aws_cft_tools/errors.rb +25 -0
  36. data/lib/aws_cft_tools/runbook.rb +166 -0
  37. data/lib/aws_cft_tools/runbook/report.rb +30 -0
  38. data/lib/aws_cft_tools/runbooks.rb +16 -0
  39. data/lib/aws_cft_tools/runbooks/common/changesets.rb +30 -0
  40. data/lib/aws_cft_tools/runbooks/common/templates.rb +38 -0
  41. data/lib/aws_cft_tools/runbooks/deploy.rb +107 -0
  42. data/lib/aws_cft_tools/runbooks/deploy/reporting.rb +50 -0
  43. data/lib/aws_cft_tools/runbooks/deploy/stacks.rb +109 -0
  44. data/lib/aws_cft_tools/runbooks/deploy/templates.rb +37 -0
  45. data/lib/aws_cft_tools/runbooks/deploy/threading.rb +37 -0
  46. data/lib/aws_cft_tools/runbooks/diff.rb +28 -0
  47. data/lib/aws_cft_tools/runbooks/diff/context.rb +86 -0
  48. data/lib/aws_cft_tools/runbooks/diff/context/reporting.rb +87 -0
  49. data/lib/aws_cft_tools/runbooks/hosts.rb +43 -0
  50. data/lib/aws_cft_tools/runbooks/images.rb +43 -0
  51. data/lib/aws_cft_tools/runbooks/init.rb +86 -0
  52. data/lib/aws_cft_tools/runbooks/retract.rb +69 -0
  53. data/lib/aws_cft_tools/runbooks/retract/templates.rb +44 -0
  54. data/lib/aws_cft_tools/runbooks/stacks.rb +43 -0
  55. data/lib/aws_cft_tools/stack.rb +83 -0
  56. data/lib/aws_cft_tools/template.rb +177 -0
  57. data/lib/aws_cft_tools/template/dsl_context.rb +14 -0
  58. data/lib/aws_cft_tools/template/file_system.rb +62 -0
  59. data/lib/aws_cft_tools/template/metadata.rb +144 -0
  60. data/lib/aws_cft_tools/template/properties.rb +129 -0
  61. data/lib/aws_cft_tools/template_set.rb +120 -0
  62. data/lib/aws_cft_tools/template_set/array_methods.rb +63 -0
  63. data/lib/aws_cft_tools/template_set/closure.rb +77 -0
  64. data/lib/aws_cft_tools/template_set/dependencies.rb +55 -0
  65. data/lib/aws_cft_tools/template_set/each_slice_state.rb +58 -0
  66. data/lib/aws_cft_tools/version.rb +8 -0
  67. data/rubycritic.reek +3 -0
  68. metadata +321 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 32c8025214a49ca0ed274d45c3c6ee266dcbfb71
4
+ data.tar.gz: 135e9ef53e1081cc471bf095dd3a5e218364162e
5
+ SHA512:
6
+ metadata.gz: bae7aae8cdc869ed5fcf53e9dd8e8419765d6ed475f8035ed482fbbdb9042a185df1323639a2263ef52e0169d0607a55ba11fe473eb0667a6327e4f28f016579
7
+ data.tar.gz: 8f06dceea86f02f3be1b3507a09da24d257484160437eb9d109c044965e3652084937bd6eadff37e7f64da92bf2534520ccc52a7aa17fdd599d2c560e71b9715
@@ -0,0 +1,10 @@
1
+ # EditorConfig is awesome: http://EditorConfig.org
2
+ root = true
3
+
4
+ [*]
5
+ charset = utf-8
6
+ end_of_line = lf
7
+ insert_final_newline = true
8
+ indent_size = 2
9
+ indent_style = space
10
+ trim_trailing_whitespace = true
@@ -0,0 +1,52 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ Gemfile.lock
46
+ .ruby-version
47
+ .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
51
+
52
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,19 @@
1
+ ---
2
+ require: rubocop-rspec
3
+
4
+ Metrics/BlockLength:
5
+ Exclude:
6
+ - 'aws-cft-tools.gemspec'
7
+ - 'example/**/*'
8
+ - 'exe/aws-cft'
9
+ - 'spec/**/*'
10
+
11
+ Metrics/LineLength:
12
+ Max: 108
13
+ Details: >-
14
+ Long lines require scrolling left/right when reviewing in GitHub. Keep lines below
15
+ 108 characters to avoid this. Be kind to your fellow reviewers.
16
+
17
+ Style/FileName:
18
+ Exclude:
19
+ - 'lib/aws-cft-tools.rb'
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.15.3
@@ -0,0 +1 @@
1
+ lib/**/*.rb - README.md CONTRIBUTING.md LICENSE BEST-PRACTICES.md USAGE.adoc
@@ -0,0 +1,136 @@
1
+ # Best Practices
2
+
3
+ ## Environment-Dependent Settings
4
+
5
+ It's common to use mappings to manage settings that depend on the deployment environment when using only
6
+ CloudFormation templates. When adding a new environment, the template has to be modified to accommodate the
7
+ new environment.
8
+
9
+ While we don't get away from this completely -- the template has to list the environment as an allowed
10
+ value -- the goal is to minimize the changes to templates when deploying to a new environment.
11
+
12
+ By putting environment-dependent settings in a YAML parameters file that sits alongside the CloudFormation
13
+ template, we can leverage the YAML dictionary merging features to extract common settings across environments.
14
+ This lets us avoid
15
+ [magic numbers](<https://en.wikipedia.org/wiki/Magic_number_(programming)#Unnamed_numerical_constants>)
16
+ as well.
17
+
18
+ For example, if we have a template setting up an auto scaling group with instance sizing dependent on
19
+ the environment, and with two AWS accounts (e.g., a lower and an upper account) and deployments in two
20
+ regions, we can create a parameters file like so:
21
+
22
+ ```yaml
23
+ ---
24
+ Lower: &Lower
25
+ InstanceType: m3.medium
26
+ Upper: &Upper
27
+ InstanceType: m4.large
28
+ USEast1: &USEast1
29
+ Foo: bar
30
+ USWest1: &USWest1
31
+ Foo: baz
32
+
33
+ Lower-us-east-1: &Lower-us-east-1
34
+ <<: *Lower
35
+ <<: *USEast1
36
+ AmiId: ami-abcdef12
37
+ Upper-us-east-1: &Upper-us-east-1
38
+ <<: *Upper
39
+ <<: *USEast1
40
+ AmiId: ami-123456ab
41
+
42
+ Lower-us-west-1: &Lower-us-west-1
43
+ <<: *Lower
44
+ <<: *USWest1
45
+ AmiId: ami-cdef1234
46
+ Upper-us-west-1: &Upper-us-west-1
47
+ <<: *Upper
48
+ <<: *USWest1
49
+ AmiId: ami-34cdef12
50
+
51
+ dev:
52
+ <<: *Lower-<%= ENV['AWS_REGION'] %>
53
+ SpotPrice: 0.02
54
+ qa:
55
+ <<: *Lower-<%= ENV['AWS_REGION'] %>
56
+ SpotPrice: 0.04
57
+ demo:
58
+ <<: *Lower-<%= ENV['AWS_REGION'] %>
59
+ SpotPrice: 0.06
60
+ staging:
61
+ <<: *Upper-<%= ENV['AWS_REGION'] %>
62
+ production:
63
+ <<: *Upper-<%= ENV['AWS_REGION'] %>
64
+ ```
65
+
66
+ We use `Lower` and `Upper` to capture cross-region parameters that are dependent on the account, and
67
+ `USEast1` and `USWest` to capture cross-account parameters that are dependent on the region. The
68
+ `Lower-us-east-1` and similarly named dictionaries capture settings that are dependent on both the region
69
+ and account while inheriting from the cross-region and cross-account settings.
70
+
71
+ Finally, we use the environment variable specifying the region to which we are deploying to select the
72
+ proper account/region set of settings to import into the environment settings.
73
+
74
+ ## Template Dependencies
75
+
76
+ Most template interdependencies can be discovered by looking at the list of `Output`s and `Fn::ImportValue`s.
77
+ But sometimes, one template builds out a feature in a VPC (e.g., peering) that another template has to have
78
+ in order to finish its build (e.g., fetching Chef cookbooks through a peering connection). In these
79
+ situations, the template with the dependency should note the required templates in a `Metadata` section:
80
+
81
+ ```yaml
82
+ ---
83
+ Metadata:
84
+ DependsOn:
85
+ Templates:
86
+ - relative-path-to/template.yaml
87
+ ```
88
+
89
+ These dependencies are harmless if they replicate what can be discovered by examining the other contents of
90
+ the template, but it's best to rely on the implicit dependencies from the `Output`s and `Fn::ImportValue`s.
91
+
92
+ ## Multiple AWS Accounts
93
+
94
+ Common practice separates development and testing environments from pre-production and
95
+ production environments. The easiest way to manage templates and parameters is to ensure that
96
+ all environments across accounts have unique names. For example, rather than have a
97
+ `devops` environment in each of the accounts when there might be account-dependent
98
+ resource references, you can incorporate the account into the environment's name
99
+ (e.g., `lower-devops` and `upper-devops`).
100
+
101
+ In the parameter files, you can use YAML aliases and references to aggregate common
102
+ parameter settings for environments across accounts that share the same purpose.
103
+
104
+ If you are working with environments that share the same name but reside in different
105
+ accounts, you can use an environment variable to select the account and use YAML aliases
106
+ and references to pull in the account-specific settings:
107
+
108
+ ```yaml
109
+ ---
110
+ devops-lower: &devops-lower
111
+ ImageId: ami-abcdef12
112
+
113
+ devops-upper: &devops-upper
114
+ ImageId: ami-34cdef12
115
+
116
+ devops:
117
+ <<: *devops-<%= ENV['AWS_ACCOUNT'] || begin
118
+ raise AwsCftTools::IncompleteEnvironmentError,
119
+ 'Please rerun with `AWS_ACCOUNT=lower ...` or `AWS_ACCOUNT=upper ...`'
120
+ end
121
+ %>
122
+ ```
123
+
124
+ ## Authentication to AWS
125
+
126
+ The `aws-cft` command supports the `-p` or `--profile` option to select an AWS profile. This makes
127
+ it easy to get up and running with multiple AWS accounts. Best practice here is to make sure none
128
+ of your profiles are labeled `default`. If there isn't a default profile, then you must select a
129
+ profile each time you run the `aws-cft` command. This helps prevent accidentally running a job in
130
+ the wrong account.
131
+
132
+ Because the tools use the AWS SDK's standard authentication mechanism, you can avoid selecting a
133
+ profile by storing your account credentials in environment variables. This lets you use tools such
134
+ as [aws-vault](https://github.com/99designs/aws-vault) to manage credentials without having them
135
+ stored in cleartext in a file that might get checked into a source code repository or otherwise
136
+ leaked.
@@ -0,0 +1,38 @@
1
+ # Contributing
2
+
3
+ ## Developing in the Open
4
+
5
+ Developing in the open creates a healthier working environment, a more collaborative process,
6
+ and just better software.
7
+
8
+ We welcome contributions.
9
+
10
+ The aws-cft-tools team handles development of this project in the open. As such, we use Github
11
+ to keep track of project development. We may not accept contributions if they introduce operational
12
+ complexity or don't align with the goals of the project. All contributions are subject to the license and in no way imply compensation for contributions.
13
+
14
+ ## Feedback
15
+
16
+ To provide feedback on the code, please create an issue on GitHub. For other issues, please contact
17
+ the [Certify Help Desk](mailto:help@certify.sba.gov).
18
+
19
+ ## How to Contribute
20
+
21
+ To contribute, simple create a pull request:
22
+
23
+ 1. Fork this repository
24
+ 2. Create a feature branch on which to work (`git checkout -b my-new-feature`)
25
+ 3. Commit your work (we like commits that explain your thought process)
26
+ 4. Submit a pull request
27
+ 5. If there is an issue associated with your pull request, then link that issue.
28
+
29
+ For documentation changes, you can edit the file directly on GitHub and select the option to create a pull
30
+ request with your own branch.
31
+
32
+ ## Tests and Continuous Integration
33
+
34
+ All pull requests must pass our continuous integration (CI) tests in order to be accepted.
35
+ We use [rubocop](https://github.com/bbatsov/rubocop) with a style guide to enforce style on Ruby
36
+ projects as part of the CI tests.
37
+
38
+ The agency reserves the right to change this policy at any time.
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in aws-cft-tools.gemspec
8
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ aws-cft-tools: Tools for managing CloudFormation Templates
2
+
3
+ Copyright (c) 2017 Small Business Administration
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this software and associated documentation files except
7
+ in compliance with the License. You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
@@ -0,0 +1,118 @@
1
+ # AwsCftTools
2
+
3
+ CloudFormation and related services provide a way to manage infrastructure state in "the cloud." This
4
+ gem and its included command (`aws-cft`) build on top of this state management system to create an
5
+ infrastructure management solution native to the AWS environment.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'aws-cft-tools'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install aws-cft-tools
22
+
23
+ ## Usage
24
+
25
+ The `aws-cft` command provides access to a number of run books that manage different tasks.
26
+
27
+ - `aws-cft deploy` to deploy CloudFormation templates
28
+ - `aws-cft diff` to see differences between local and deployed CloudFormation templates
29
+ - `aws-cft hosts` to list running EC2 instances
30
+ - `aws-cft images` to list available AMIs
31
+ - `aws-cft init` to initialize a new infrastructure project
32
+ - `aws-cft retract` to remove deployed CloudFormation templates
33
+ - `aws-cft stacks` to list CloudFormation stacks
34
+
35
+ See [`USAGE.adoc`](USAGE.adoc) for more details.
36
+
37
+ ### Template organization
38
+
39
+ CloudFormation templates are managed in any number of directories that correspond to infrastructure
40
+ layers. For example, `vpcs`, `networks`, `security`, and `applications`. The layers are completely
41
+ arbitrary.
42
+
43
+ Templates also belong to a "role" based on their participation in the infrastructure. The role is defined
44
+ with metadata in the template:
45
+
46
+ ```yaml
47
+ Metadata:
48
+ Role: foo
49
+ ```
50
+
51
+ Templates are deployed or retracted based on their dependency order. The scripts try to discover this
52
+ by examining the values exported by one template and imported by another. When this fails to describe
53
+ the proper dependencies of a template, you can add an explicit dependency in the template's `Metadata`:
54
+
55
+ ```yaml
56
+ Metadata:
57
+ DependsOn:
58
+ Templates:
59
+ - relative_path_to/template.yaml
60
+ ```
61
+
62
+ This follows the pattern for listing explicit dependencies between resources in a template.
63
+
64
+ ## Development
65
+
66
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the
67
+ tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
68
+
69
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version,
70
+ update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git
71
+ tag for the version, push git commits and tags, and push the `.gem` file to
72
+ [rubygems.org](https://rubygems.org).
73
+
74
+ ## Building Gem for Local Use
75
+
76
+ ```shell
77
+ bundle install --deployment --without development test
78
+ gem build ./aws-cft-tools.gemspec
79
+ ```
80
+
81
+ ## Minimum IAM Policy to run initial script
82
+
83
+ ```json
84
+ {
85
+ "Sid": "aws-cft",
86
+ "Effect": "Allow",
87
+ "Action": [
88
+ "ec2:DescribeInstances",
89
+ "ec2:DescribeTags",
90
+ "ec2:DescribeImages",
91
+ "ec2:DescribeImageAttribute"
92
+ ],
93
+ "Resource": [ "*" ]
94
+ }
95
+ ```
96
+
97
+ ## Security Policy
98
+
99
+ Please do not submit an issue on GitHub for a security vulnerability. Please contact the development team
100
+ through the Certify Help Desk at [help@certify.sba.gov](mailto:help@certify.sba.gov).
101
+
102
+ Be sure to include all the pertinent information.
103
+
104
+ ## License
105
+
106
+ Aws-cft-tools is licensed permissively under the Apache License v2.0.
107
+ A copy of that license is distributed with this software.
108
+
109
+ ## Contributing
110
+
111
+ We welcome contributions. Please read [`CONTRIBUTING.md`](CONTRIBUTING.md) for how to contribute.
112
+
113
+ We strive for a welcoming and inclusive environment for the aws-cft-tools project.
114
+
115
+ Please follow this guidelines in all interactions:
116
+
117
+ 1. Be Respectful: use welcoming and inclusive language.
118
+ 2. Assume best intentions: seek to understand others' opinions.
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+ require 'rubycritic/rake_task'
6
+ require 'yard'
7
+
8
+ RubyCritic::RakeTask.new do |task|
9
+ # Glob pattern to match source files. Defaults to FileList['.'].
10
+ task.paths = FileList['lib/**/*.rb']
11
+ end
12
+
13
+ RSpec::Core::RakeTask.new(:spec)
14
+
15
+ YARD::Rake::YardocTask.new
16
+
17
+ task default: :spec