aws-insight 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +84 -0
- data/.travis.yml +19 -0
- data/CHANGELOG.md +336 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/CONTRIBUTING.md +62 -0
- data/Gemfile +19 -0
- data/Guardfile +12 -0
- data/LICENSE +22 -0
- data/README.md +393 -0
- data/Rakefile +6 -0
- data/bin/terraforming +5 -0
- data/contrib/zsh-completion/_terraforming +65 -0
- data/lib/terraforming.rb +54 -0
- data/lib/terraforming/cli.rb +340 -0
- data/lib/terraforming/resource/alb.rb +98 -0
- data/lib/terraforming/resource/auto_scaling_group.rb +90 -0
- data/lib/terraforming/resource/cloud_watch_alarm.rb +87 -0
- data/lib/terraforming/resource/config.rb +98 -0
- data/lib/terraforming/resource/db_parameter_group.rb +58 -0
- data/lib/terraforming/resource/db_security_group.rb +57 -0
- data/lib/terraforming/resource/db_subnet_group.rb +52 -0
- data/lib/terraforming/resource/ec2.rb +130 -0
- data/lib/terraforming/resource/efs_file_system.rb +60 -0
- data/lib/terraforming/resource/eip.rb +66 -0
- data/lib/terraforming/resource/elasti_cache_cluster.rb +80 -0
- data/lib/terraforming/resource/elasti_cache_subnet_group.rb +56 -0
- data/lib/terraforming/resource/elb.rb +203 -0
- data/lib/terraforming/resource/iam_group.rb +54 -0
- data/lib/terraforming/resource/iam_group_membership.rb +63 -0
- data/lib/terraforming/resource/iam_group_policy.rb +71 -0
- data/lib/terraforming/resource/iam_instance_profile.rb +54 -0
- data/lib/terraforming/resource/iam_policy.rb +63 -0
- data/lib/terraforming/resource/iam_policy_attachment.rb +86 -0
- data/lib/terraforming/resource/iam_role.rb +56 -0
- data/lib/terraforming/resource/iam_role_policy.rb +71 -0
- data/lib/terraforming/resource/iam_user.rb +55 -0
- data/lib/terraforming/resource/iam_user_policy.rb +71 -0
- data/lib/terraforming/resource/internet_gateway.rb +54 -0
- data/lib/terraforming/resource/kms_alias.rb +55 -0
- data/lib/terraforming/resource/kms_key.rb +84 -0
- data/lib/terraforming/resource/launch_configuration.rb +106 -0
- data/lib/terraforming/resource/nat_gateway.rb +57 -0
- data/lib/terraforming/resource/network_acl.rb +83 -0
- data/lib/terraforming/resource/network_interface.rb +68 -0
- data/lib/terraforming/resource/rds.rb +74 -0
- data/lib/terraforming/resource/redshift.rb +67 -0
- data/lib/terraforming/resource/route53_record.rb +106 -0
- data/lib/terraforming/resource/route53_zone.rb +89 -0
- data/lib/terraforming/resource/route_table.rb +122 -0
- data/lib/terraforming/resource/route_table_association.rb +59 -0
- data/lib/terraforming/resource/s3.rb +69 -0
- data/lib/terraforming/resource/security_group.rb +188 -0
- data/lib/terraforming/resource/sns_topic.rb +75 -0
- data/lib/terraforming/resource/sns_topic_subscription.rb +83 -0
- data/lib/terraforming/resource/sqs.rb +70 -0
- data/lib/terraforming/resource/subnet.rb +55 -0
- data/lib/terraforming/resource/vpc.rb +67 -0
- data/lib/terraforming/resource/vpn_gateway.rb +55 -0
- data/lib/terraforming/template/tf/alb.erb +28 -0
- data/lib/terraforming/template/tf/auto_scaling_group.erb +28 -0
- data/lib/terraforming/template/tf/cloud_watch_alarm.erb +33 -0
- data/lib/terraforming/template/tf/db_parameter_group.erb +17 -0
- data/lib/terraforming/template/tf/db_security_group.erb +26 -0
- data/lib/terraforming/template/tf/db_subnet_group.erb +8 -0
- data/lib/terraforming/template/tf/ec2.erb +56 -0
- data/lib/terraforming/template/tf/eip.erb +11 -0
- data/lib/terraforming/template/tf/elasti_cache_cluster.erb +22 -0
- data/lib/terraforming/template/tf/elasti_cache_subnet_group.erb +8 -0
- data/lib/terraforming/template/tf/elastic_filesystem.erb +18 -0
- data/lib/terraforming/template/tf/elb.erb +51 -0
- data/lib/terraforming/template/tf/iam_group.erb +7 -0
- data/lib/terraforming/template/tf/iam_group_membership.erb +8 -0
- data/lib/terraforming/template/tf/iam_group_policy.erb +10 -0
- data/lib/terraforming/template/tf/iam_instance_profile.erb +8 -0
- data/lib/terraforming/template/tf/iam_policy.erb +12 -0
- data/lib/terraforming/template/tf/iam_policy_attachment.erb +10 -0
- data/lib/terraforming/template/tf/iam_role.erb +10 -0
- data/lib/terraforming/template/tf/iam_role_policy.erb +10 -0
- data/lib/terraforming/template/tf/iam_user.erb +7 -0
- data/lib/terraforming/template/tf/iam_user_policy.erb +10 -0
- data/lib/terraforming/template/tf/internet_gateway.erb +14 -0
- data/lib/terraforming/template/tf/kms_alias.erb +7 -0
- data/lib/terraforming/template/tf/kms_key.erb +13 -0
- data/lib/terraforming/template/tf/launch_configuration.erb +68 -0
- data/lib/terraforming/template/tf/nat_gateway.erb +9 -0
- data/lib/terraforming/template/tf/network_acl.erb +43 -0
- data/lib/terraforming/template/tf/network_interface.erb +22 -0
- data/lib/terraforming/template/tf/rds.erb +25 -0
- data/lib/terraforming/template/tf/redshift.erb +23 -0
- data/lib/terraforming/template/tf/route53_record.erb +52 -0
- data/lib/terraforming/template/tf/route53_zone.erb +18 -0
- data/lib/terraforming/template/tf/route_table.erb +34 -0
- data/lib/terraforming/template/tf/route_table_association.erb +9 -0
- data/lib/terraforming/template/tf/s3.erb +12 -0
- data/lib/terraforming/template/tf/security_group.erb +56 -0
- data/lib/terraforming/template/tf/sns_topic.erb +17 -0
- data/lib/terraforming/template/tf/sns_topic_subscription.erb +23 -0
- data/lib/terraforming/template/tf/sqs.erb +21 -0
- data/lib/terraforming/template/tf/subnet.erb +15 -0
- data/lib/terraforming/template/tf/vpc.erb +15 -0
- data/lib/terraforming/template/tf/vpn_gateway.erb +14 -0
- data/lib/terraforming/util.rb +30 -0
- data/lib/terraforming/version.rb +3 -0
- data/script/console +14 -0
- data/script/generate +97 -0
- data/script/setup +7 -0
- data/templates/resource.erb.erb +3 -0
- data/templates/resource.rb.erb +31 -0
- data/templates/resource_spec.rb.erb +39 -0
- data/terraforming.gemspec +31 -0
- metadata +271 -0
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
I love pull requests from everyone! By the way, I have a favor to ask you with your contribution :bow:
|
4
|
+
|
5
|
+
## Making changes
|
6
|
+
|
7
|
+
- Currently, this gem supports only __AWS__ resources. Other providers are supported as separated gems.
|
8
|
+
- Datadog: [terraforming-datadog](https://github.com/dtan4/terraforming-datadog)
|
9
|
+
- DNSimple: [terraforming-dnsimple](https://github.com/dtan4/terraforming-dnsimple)
|
10
|
+
- Do not bump gem version in your pull request.
|
11
|
+
- Please follow the coding style of _existing_ code. Most of trivial rules can be checked by [RuboCop](https://github.com/bbatsov/rubocop) ([`rubocop.yml`](https://github.com/dtan4/terraforming/blob/master/.rubocop.yml)).
|
12
|
+
- Coding style is checked automatically by [SideCI](https://sideci.com) right after creating pull request. If there is error, SideCI comments at the point error occured.
|
13
|
+
- Please write tests for your changes. All tests are written with [RSpec](http://rspec.info/).
|
14
|
+
|
15
|
+
## Adding new resource
|
16
|
+
|
17
|
+
- Class name must match to Terraforming's resource name without `aws_` prefix, and be a complete resource name.
|
18
|
+
- e.g. `aws_iam_group_membership`: `IAMGroupMembership`
|
19
|
+
- Yes, I know that some of resources I added a long ago don't follow to this rule...
|
20
|
+
- File name must also match to Terraforming's resource name without `aws_` prefix.
|
21
|
+
- e.g. `aws_iam_group_membership`: `iam_group_membership.rb`
|
22
|
+
- Command name should be abbreviation.
|
23
|
+
- e.g. `aws_iam_group_membership`: `iamgp`
|
24
|
+
- Please check generation result by executing `terraform plan` with real resources. There should be NO diff with generated `.tf` and `.tfstate`.
|
25
|
+
|
26
|
+
`script/generate` generates new resource code / test skeletons.
|
27
|
+
|
28
|
+
```bash
|
29
|
+
$ script/generate ec2
|
30
|
+
==> Generate ec2.rb
|
31
|
+
==> Generate ec2_spec.rb
|
32
|
+
==> Generate ec2.erb
|
33
|
+
|
34
|
+
Add below code by hand.
|
35
|
+
|
36
|
+
lib/terraforming.rb:
|
37
|
+
|
38
|
+
require "terraforming/resource/ec2"
|
39
|
+
|
40
|
+
lib/terraforming/cli.rb:
|
41
|
+
|
42
|
+
module Terraforming
|
43
|
+
class CLI < Thor
|
44
|
+
|
45
|
+
# Subcommand name should be acronym.
|
46
|
+
desc "ec2", "Ec2"
|
47
|
+
def ec2
|
48
|
+
execute(Terraforming::Resource::Ec2, options)
|
49
|
+
end
|
50
|
+
|
51
|
+
spec/lib/terraforming/cli_spec.rb:
|
52
|
+
|
53
|
+
module Terraforming
|
54
|
+
describe CLI do
|
55
|
+
context "resources" do
|
56
|
+
describe "ec2" do
|
57
|
+
let(:klass) { Terraforming::Resource::Ec2
|
58
|
+
let(:command) { :ec2 }
|
59
|
+
|
60
|
+
it_behaves_like "CLI examples"
|
61
|
+
end
|
62
|
+
```
|
data/Gemfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in terraforming.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
group :development do
|
7
|
+
gem "guard"
|
8
|
+
gem "guard-rspec"
|
9
|
+
|
10
|
+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.2.0")
|
11
|
+
gem "listen", "~> 3.1.0"
|
12
|
+
else
|
13
|
+
gem "listen", "< 3.1.0"
|
14
|
+
end
|
15
|
+
|
16
|
+
gem "rubocop"
|
17
|
+
|
18
|
+
gem "terminal-notifier-guard"
|
19
|
+
end
|
data/Guardfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
2
|
+
require "guard/rspec/dsl"
|
3
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
4
|
+
|
5
|
+
rspec = dsl.rspec
|
6
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
7
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
8
|
+
watch(rspec.spec_files)
|
9
|
+
|
10
|
+
ruby = dsl.ruby
|
11
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
12
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015-2016 Daisuke Fujita
|
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.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,393 @@
|
|
1
|
+
# Terraforming
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/dtan4/terraforming.svg?branch=master)](https://travis-ci.org/dtan4/terraforming)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/dtan4/terraforming/badges/gpa.svg)](https://codeclimate.com/github/dtan4/terraforming)
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/github/dtan4/terraforming/badge.svg?branch=increase-test-cov-160528)](https://coveralls.io/github/dtan4/terraforming)
|
6
|
+
[![Dependency Status](https://gemnasium.com/dtan4/terraforming.svg)](https://gemnasium.com/dtan4/terraforming)
|
7
|
+
[![Gem Version](https://badge.fury.io/rb/terraforming.svg)](http://badge.fury.io/rb/terraforming)
|
8
|
+
[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE)
|
9
|
+
[![Docker Repository on Quay.io](https://quay.io/repository/dtan4/terraforming/status "Docker Repository on Quay.io")](https://quay.io/repository/dtan4/terraforming)
|
10
|
+
[![Join the chat at https://gitter.im/dtan4/terraforming](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/dtan4/terraforming?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
11
|
+
|
12
|
+
Export existing AWS resources to [Terraform](https://terraform.io/) style (tf, tfstate)
|
13
|
+
|
14
|
+
- [Supported version](#supported-version)
|
15
|
+
- [Installation](#installation)
|
16
|
+
- [Prerequisites](#prerequisites)
|
17
|
+
- [Usage](#usage)
|
18
|
+
- [Export tf](#export-tf)
|
19
|
+
- [Export tfstate](#export-tfstate)
|
20
|
+
- [Example: Export all](#example-export-all)
|
21
|
+
- [Run as Docker container](#run-as-docker-container-)
|
22
|
+
- [Development](#development)
|
23
|
+
- [Contributing](#contributing)
|
24
|
+
- [License](#license)
|
25
|
+
|
26
|
+
## Supported version
|
27
|
+
|
28
|
+
Ruby 2.1 or higher
|
29
|
+
|
30
|
+
## Installation
|
31
|
+
|
32
|
+
Add this line to your application's Gemfile:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
gem 'terraforming'
|
36
|
+
```
|
37
|
+
|
38
|
+
And then execute:
|
39
|
+
|
40
|
+
$ bundle
|
41
|
+
|
42
|
+
Or install it yourself as:
|
43
|
+
|
44
|
+
$ gem install terraforming
|
45
|
+
|
46
|
+
## Prerequisites
|
47
|
+
|
48
|
+
You need to set AWS credentials.
|
49
|
+
|
50
|
+
```bash
|
51
|
+
export AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXXXXXXXX
|
52
|
+
export AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
53
|
+
export AWS_REGION=xx-yyyy-0
|
54
|
+
```
|
55
|
+
|
56
|
+
You can also specify credential profile in `~/.aws/credentials` by `--profile` option.
|
57
|
+
|
58
|
+
```bash
|
59
|
+
$ cat ~/.aws/credentials
|
60
|
+
[hoge]
|
61
|
+
aws_access_key_id = Hoge
|
62
|
+
aws_secret_access_key = FugaFuga
|
63
|
+
|
64
|
+
# Pass profile name by --profile option
|
65
|
+
$ terraforming s3 --profile hoge
|
66
|
+
```
|
67
|
+
|
68
|
+
You can force the AWS SDK to utilize the CA certificate that is bundled with the SDK for systems where the default OpenSSL certificate is not installed (e.g. Windows) by utilizing the `--use-bundled-cert` option.
|
69
|
+
|
70
|
+
```bash
|
71
|
+
PS C:\> terraforming ec2 --use-bundled-cert
|
72
|
+
```
|
73
|
+
|
74
|
+
## Usage
|
75
|
+
|
76
|
+
```bash
|
77
|
+
$ terraforming
|
78
|
+
Commands:
|
79
|
+
terraforming alb # ALB
|
80
|
+
terraforming asg # AutoScaling Group
|
81
|
+
terraforming cwa # CloudWatch Alarm
|
82
|
+
terraforming dbpg # Database Parameter Group
|
83
|
+
terraforming dbsg # Database Security Group
|
84
|
+
terraforming dbsn # Database Subnet Group
|
85
|
+
terraforming ec2 # EC2
|
86
|
+
terraforming ecc # ElastiCache Cluster
|
87
|
+
terraforming ecsn # ElastiCache Subnet Group
|
88
|
+
terraforming efs # EFS File System
|
89
|
+
terraforming eip # EIP
|
90
|
+
terraforming elb # ELB
|
91
|
+
terraforming help [COMMAND] # Describe available commands or one specific command
|
92
|
+
terraforming iamg # IAM Group
|
93
|
+
terraforming iamgm # IAM Group Membership
|
94
|
+
terraforming iamgp # IAM Group Policy
|
95
|
+
terraforming iamip # IAM Instance Profile
|
96
|
+
terraforming iamp # IAM Policy
|
97
|
+
terraforming iampa # IAM Policy Attachment
|
98
|
+
terraforming iamr # IAM Role
|
99
|
+
terraforming iamrp # IAM Role Policy
|
100
|
+
terraforming iamu # IAM User
|
101
|
+
terraforming iamup # IAM User Policy
|
102
|
+
terraforming igw # Internet Gateway
|
103
|
+
terraforming kmsa # KMS Key Alias
|
104
|
+
terraforming kmsk # KMS Key
|
105
|
+
terraforming lc # Launch Configuration
|
106
|
+
terraforming nacl # Network ACL
|
107
|
+
terraforming nat # NAT Gateway
|
108
|
+
terraforming nif # Network Interface
|
109
|
+
terraforming r53r # Route53 Record
|
110
|
+
terraforming r53z # Route53 Hosted Zone
|
111
|
+
terraforming rds # RDS
|
112
|
+
terraforming rs # Redshift
|
113
|
+
terraforming rt # Route Table
|
114
|
+
terraforming rta # Route Table Association
|
115
|
+
terraforming s3 # S3
|
116
|
+
terraforming sg # Security Group
|
117
|
+
terraforming sn # Subnet
|
118
|
+
terraforming snst # SNS Topic
|
119
|
+
terraforming snss # SNS Subscription
|
120
|
+
terraforming sqs # SQS
|
121
|
+
terraforming vgw # VPN Gateway
|
122
|
+
terraforming vpc # VPC
|
123
|
+
|
124
|
+
Options:
|
125
|
+
[--merge=MERGE] # tfstate file to merge
|
126
|
+
[--overwrite], [--no-overwrite] # Overwrite existng tfstate
|
127
|
+
[--tfstate], [--no-tfstate] # Generate tfstate
|
128
|
+
[--profile=PROFILE] # AWS credentials profile
|
129
|
+
[--region=REGION] # AWS region
|
130
|
+
[--use-bundled-cert], [--no-use-bundled-cert] # Use the bundled CA certificate from AWS SDK
|
131
|
+
```
|
132
|
+
|
133
|
+
### Export tf
|
134
|
+
|
135
|
+
```bash
|
136
|
+
$ terraforming <resource> [--profile PROFILE]
|
137
|
+
```
|
138
|
+
|
139
|
+
(e.g. S3 buckets):
|
140
|
+
|
141
|
+
```bash
|
142
|
+
$ terraforming s3
|
143
|
+
```
|
144
|
+
|
145
|
+
```hcl
|
146
|
+
resource "aws_s3_bucket" "hoge" {
|
147
|
+
bucket = "hoge"
|
148
|
+
acl = "private"
|
149
|
+
}
|
150
|
+
|
151
|
+
resource "aws_s3_bucket" "fuga" {
|
152
|
+
bucket = "fuga"
|
153
|
+
acl = "private"
|
154
|
+
}
|
155
|
+
```
|
156
|
+
|
157
|
+
### Export tfstate
|
158
|
+
|
159
|
+
```bash
|
160
|
+
$ terraforming <resource> --tfstate [--merge TFSTATE_PATH] [--overwrite] [--profile PROFILE]
|
161
|
+
```
|
162
|
+
|
163
|
+
(e.g. S3 buckets):
|
164
|
+
|
165
|
+
```bash
|
166
|
+
$ terraforming s3 --tfstate
|
167
|
+
```
|
168
|
+
|
169
|
+
```json
|
170
|
+
{
|
171
|
+
"version": 1,
|
172
|
+
"serial": 1,
|
173
|
+
"modules": {
|
174
|
+
"path": [
|
175
|
+
"root"
|
176
|
+
],
|
177
|
+
"outputs": {
|
178
|
+
},
|
179
|
+
"resources": {
|
180
|
+
"aws_s3_bucket.hoge": {
|
181
|
+
"type": "aws_s3_bucket",
|
182
|
+
"primary": {
|
183
|
+
"id": "hoge",
|
184
|
+
"attributes": {
|
185
|
+
"acl": "private",
|
186
|
+
"bucket": "hoge",
|
187
|
+
"id": "hoge"
|
188
|
+
}
|
189
|
+
}
|
190
|
+
},
|
191
|
+
"aws_s3_bucket.fuga": {
|
192
|
+
"type": "aws_s3_bucket",
|
193
|
+
"primary": {
|
194
|
+
"id": "fuga",
|
195
|
+
"attributes": {
|
196
|
+
"acl": "private",
|
197
|
+
"bucket": "fuga",
|
198
|
+
"id": "fuga"
|
199
|
+
}
|
200
|
+
}
|
201
|
+
}
|
202
|
+
}
|
203
|
+
}
|
204
|
+
}
|
205
|
+
```
|
206
|
+
|
207
|
+
If you want to merge exported tfstate to existing `terraform.tfstate`, specify `--tfstate --merge=/path/to/terraform.tfstate` option.
|
208
|
+
You can overwrite existing `terraform.tfstate` by specifying `--overwrite` option together.
|
209
|
+
|
210
|
+
Existing `terraform.tfstate`:
|
211
|
+
|
212
|
+
```bash
|
213
|
+
# /path/to/terraform.tfstate
|
214
|
+
|
215
|
+
{
|
216
|
+
"version": 1,
|
217
|
+
"serial": 88,
|
218
|
+
"remote": {
|
219
|
+
"type": "s3",
|
220
|
+
"config": {
|
221
|
+
"bucket": "terraforming-tfstate",
|
222
|
+
"key": "tf"
|
223
|
+
}
|
224
|
+
},
|
225
|
+
"modules": {
|
226
|
+
"path": [
|
227
|
+
"root"
|
228
|
+
],
|
229
|
+
"outputs": {
|
230
|
+
},
|
231
|
+
"resources": {
|
232
|
+
"aws_elb.hogehoge": {
|
233
|
+
"type": "aws_elb",
|
234
|
+
"primary": {
|
235
|
+
"id": "hogehoge",
|
236
|
+
"attributes": {
|
237
|
+
"availability_zones.#": "2",
|
238
|
+
"connection_draining": "true",
|
239
|
+
"connection_draining_timeout": "300",
|
240
|
+
"cross_zone_load_balancing": "true",
|
241
|
+
"dns_name": "hoge-12345678.ap-northeast-1.elb.amazonaws.com",
|
242
|
+
"health_check.#": "1",
|
243
|
+
"id": "hogehoge",
|
244
|
+
"idle_timeout": "60",
|
245
|
+
"instances.#": "1",
|
246
|
+
"listener.#": "1",
|
247
|
+
"name": "hoge",
|
248
|
+
"security_groups.#": "2",
|
249
|
+
"source_security_group": "default",
|
250
|
+
"subnets.#": "2"
|
251
|
+
}
|
252
|
+
}
|
253
|
+
}
|
254
|
+
}
|
255
|
+
}
|
256
|
+
}
|
257
|
+
```
|
258
|
+
|
259
|
+
To generate merged tfstate:
|
260
|
+
|
261
|
+
```bash
|
262
|
+
$ terraforming s3 --tfstate --merge=/path/to/tfstate
|
263
|
+
```
|
264
|
+
|
265
|
+
```json
|
266
|
+
{
|
267
|
+
"version": 1,
|
268
|
+
"serial": 89,
|
269
|
+
"remote": {
|
270
|
+
"type": "s3",
|
271
|
+
"config": {
|
272
|
+
"bucket": "terraforming-tfstate",
|
273
|
+
"key": "tf"
|
274
|
+
}
|
275
|
+
},
|
276
|
+
"modules": {
|
277
|
+
"path": [
|
278
|
+
"root"
|
279
|
+
],
|
280
|
+
"outputs": {
|
281
|
+
},
|
282
|
+
"resources": {
|
283
|
+
"aws_elb.hogehoge": {
|
284
|
+
"type": "aws_elb",
|
285
|
+
"primary": {
|
286
|
+
"id": "hogehoge",
|
287
|
+
"attributes": {
|
288
|
+
"availability_zones.#": "2",
|
289
|
+
"connection_draining": "true",
|
290
|
+
"connection_draining_timeout": "300",
|
291
|
+
"cross_zone_load_balancing": "true",
|
292
|
+
"dns_name": "hoge-12345678.ap-northeast-1.elb.amazonaws.com",
|
293
|
+
"health_check.#": "1",
|
294
|
+
"id": "hogehoge",
|
295
|
+
"idle_timeout": "60",
|
296
|
+
"instances.#": "1",
|
297
|
+
"listener.#": "1",
|
298
|
+
"name": "hoge",
|
299
|
+
"security_groups.#": "2",
|
300
|
+
"source_security_group": "default",
|
301
|
+
"subnets.#": "2"
|
302
|
+
}
|
303
|
+
}
|
304
|
+
},
|
305
|
+
"aws_s3_bucket.hoge": {
|
306
|
+
"type": "aws_s3_bucket",
|
307
|
+
"primary": {
|
308
|
+
"id": "hoge",
|
309
|
+
"attributes": {
|
310
|
+
"acl": "private",
|
311
|
+
"bucket": "hoge",
|
312
|
+
"id": "hoge"
|
313
|
+
}
|
314
|
+
}
|
315
|
+
},
|
316
|
+
"aws_s3_bucket.fuga": {
|
317
|
+
"type": "aws_s3_bucket",
|
318
|
+
"primary": {
|
319
|
+
"id": "fuga",
|
320
|
+
"attributes": {
|
321
|
+
"acl": "private",
|
322
|
+
"bucket": "fuga",
|
323
|
+
"id": "fuga"
|
324
|
+
}
|
325
|
+
}
|
326
|
+
}
|
327
|
+
}
|
328
|
+
}
|
329
|
+
}
|
330
|
+
```
|
331
|
+
|
332
|
+
After writing exported tf and tfstate to files, execute `terraform plan` and check the result.
|
333
|
+
There should be no diff.
|
334
|
+
|
335
|
+
```bash
|
336
|
+
$ terraform plan
|
337
|
+
No changes. Infrastructure is up-to-date. This means that Terraform
|
338
|
+
could not detect any differences between your configuration and
|
339
|
+
the real physical resources that exist. As a result, Terraform
|
340
|
+
doesn't need to do anything.
|
341
|
+
```
|
342
|
+
|
343
|
+
#### Example: Export all
|
344
|
+
Example assuming you want to export everything from us-west-2 and you are using ~/.aws/credentials with a `default` profile
|
345
|
+
```bash
|
346
|
+
export AWS_REGION=us-west-2
|
347
|
+
terraforming help | grep terraforming | grep -v help | awk '{print "terraforming", $2, "--profile", "default", ">", $2".tf";}' | bash
|
348
|
+
# find files that only have 1 empty line (likely nothing in AWS)
|
349
|
+
find . -type f -name '*.tf' | xargs wc -l | grep ' 1 .'
|
350
|
+
```
|
351
|
+
|
352
|
+
## Run as Docker container [![Docker Repository on Quay.io](https://quay.io/repository/dtan4/terraforming/status "Docker Repository on Quay.io")](https://quay.io/repository/dtan4/terraforming)
|
353
|
+
|
354
|
+
Terraforming Docker Image is available at [quay.io/dtan4/terraforming](https://quay.io/repository/dtan4/terraforming) and developed at [dtan4/dockerfile-terraforming](https://github.com/dtan4/dockerfile-terraforming).
|
355
|
+
|
356
|
+
Pull the Docker image:
|
357
|
+
|
358
|
+
```bash
|
359
|
+
$ docker pull quay.io/dtan4/terraforming:latest
|
360
|
+
```
|
361
|
+
|
362
|
+
And then run Terraforming as a Docker container:
|
363
|
+
|
364
|
+
```bash
|
365
|
+
$ docker run \
|
366
|
+
--rm \
|
367
|
+
--name terraforming \
|
368
|
+
-e AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXXXXXXXX \
|
369
|
+
-e AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
|
370
|
+
-e AWS_REGION=xx-yyyy-0 \
|
371
|
+
quay.io/dtan4/terraforming:latest \
|
372
|
+
terraforming s3
|
373
|
+
```
|
374
|
+
|
375
|
+
## Development
|
376
|
+
|
377
|
+
After checking out the repo, run `script/setup` to install dependencies. Then, run `script/console` for an interactive prompt that will allow you to experiment.
|
378
|
+
|
379
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
380
|
+
|
381
|
+
## Contributing
|
382
|
+
|
383
|
+
Please read [Contribution Guide](CONTRIBUTING.md) at first.
|
384
|
+
|
385
|
+
1. Fork it ( https://github.com/dtan4/terraforming/fork )
|
386
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
387
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
388
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
389
|
+
5. Create a new Pull Request
|
390
|
+
|
391
|
+
## License
|
392
|
+
|
393
|
+
[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE)
|