README.md in terraforming-0.1.0 vs README.md in terraforming-0.1.1
- old
+ new
@@ -6,12 +6,27 @@
[![Dependency Status](https://gemnasium.com/dtan4/terraforming.svg)](https://gemnasium.com/dtan4/terraforming)
[![Gem Version](https://badge.fury.io/rb/terraforming.svg)](http://badge.fury.io/rb/terraforming)
[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE)
[![Docker Repository on Quay.io](https://quay.io/repository/dtan4/terraforming/status "Docker Repository on Quay.io")](https://quay.io/repository/dtan4/terraforming)
-Import existing AWS resources into [Terraform](https://terraform.io/) style (tf, tfstate)
+Export existing AWS resources to [Terraform](https://terraform.io/) style (tf, tfstate)
+- [Supported version](#supported-version)
+- [Installation](#installation)
+- [Prerequisites](#prerequisites)
+- [Usage](#usage)
+ - [Export tf](#export-tf)
+ - [Export tfstate](#export-tfstate)
+- [Run as Docker container](#run-as-docker-container-)
+- [Development](#development)
+- [Contributing](#contributing)
+- [License](#license)
+
+## Supported version
+
+Ruby 2.x
+
## Installation
Add this line to your application's Gemfile:
```ruby
@@ -29,13 +44,13 @@
## Prerequisites
You need to set AWS credentials.
```bash
-AWS_ACCESS_KEY_ID=
-AWS_SECRET_ACCESS_KEY=
-AWS_REGION=
+export AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXXXXXXXX
+export AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+export AWS_DEFAULT_REGION=xx-yyyy-0
```
## Usage
```bash
@@ -62,12 +77,14 @@
terraforming sg # Security Group
terraforming sn # Subnet
terraforming vpc # VPC
```
-Output `.tf` style (e.g. S3 buckets):
+### Export tf
+(e.g. S3 buckets):
+
```bash
$ terraforming s3
```
```go
@@ -80,12 +97,14 @@
bucket = "fuga"
acl = "private"
}
```
-To output `.tfstate` style, specify `--tfstate` option (e.g. S3 buckets):
+### Export tfstate
+Specify `--tfstate` option (e.g. S3 buckets):
+
```bash
$ terraforming s3 --tfstate
```
```json
@@ -124,12 +143,147 @@
}
}
}
```
-(Probably you have to modify the output to add it to existing `terraforming.tfstate`)
+If you want to merge exported tfstate to existing `terraform.tfstate`, specify `--tfstate --merge=/path/to/terraform.tfstate` option.
+This option does NOT overwrite existing `terraform.tfstate`, but flush output to stdout like others.
+You should copy output in stdout by hand or `pbcopy` command, and paste it to existing `terraform.tfstate`.
+Existing `terraform.tfstate`:
+
+```bash
+# /path/to/terraform.tfstate
+
+{
+ "version": 1,
+ "serial": 88,
+ "remote": {
+ "type": "s3",
+ "config": {
+ "bucket": "terraforming-tfstate",
+ "key": "tf"
+ }
+ },
+ "modules": {
+ "path": [
+ "root"
+ ],
+ "outputs": {
+ },
+ "resources": {
+ "aws_elb.hogehoge": {
+ "type": "aws_elb",
+ "primary": {
+ "id": "hogehoge",
+ "attributes": {
+ "availability_zones.#": "2",
+ "connection_draining": "true",
+ "connection_draining_timeout": "300",
+ "cross_zone_load_balancing": "true",
+ "dns_name": "hoge-12345678.ap-northeast-1.elb.amazonaws.com",
+ "health_check.#": "1",
+ "id": "hogehoge",
+ "idle_timeout": "60",
+ "instances.#": "1",
+ "listener.#": "1",
+ "name": "hoge",
+ "security_groups.#": "2",
+ "source_security_group": "default",
+ "subnets.#": "2"
+ }
+ }
+ }
+ }
+ }
+}
+```
+
+To generate merged tfstate:
+
+```bash
+$ terraforming s3 --tfstate --merge=/path/to/tfstate
+```
+
+```json
+{
+ "version": 1,
+ "serial": 89,
+ "remote": {
+ "type": "s3",
+ "config": {
+ "bucket": "terraforming-tfstate",
+ "key": "tf"
+ }
+ },
+ "modules": {
+ "path": [
+ "root"
+ ],
+ "outputs": {
+ },
+ "resources": {
+ "aws_elb.hogehoge": {
+ "type": "aws_elb",
+ "primary": {
+ "id": "hogehoge",
+ "attributes": {
+ "availability_zones.#": "2",
+ "connection_draining": "true",
+ "connection_draining_timeout": "300",
+ "cross_zone_load_balancing": "true",
+ "dns_name": "hoge-12345678.ap-northeast-1.elb.amazonaws.com",
+ "health_check.#": "1",
+ "id": "hogehoge",
+ "idle_timeout": "60",
+ "instances.#": "1",
+ "listener.#": "1",
+ "name": "hoge",
+ "security_groups.#": "2",
+ "source_security_group": "default",
+ "subnets.#": "2"
+ }
+ }
+ },
+ "aws_s3_bucket.hoge": {
+ "type": "aws_s3_bucket",
+ "primary": {
+ "id": "hoge",
+ "attributes": {
+ "acl": "private",
+ "bucket": "hoge",
+ "id": "hoge"
+ }
+ }
+ },
+ "aws_s3_bucket.fuga": {
+ "type": "aws_s3_bucket",
+ "primary": {
+ "id": "fuga",
+ "attributes": {
+ "acl": "private",
+ "bucket": "fuga",
+ "id": "fuga"
+ }
+ }
+ }
+ }
+ }
+}
+```
+
+After writing exported tf and tfstate to files, execute `terraform plan` and check the result.
+There should be no diff.
+
+```bash
+$ terraform plan
+No changes. Infrastructure is up-to-date. This means that Terraform
+could not detect any differences between your configuration and
+the real physical resources that exist. As a result, Terraform
+doesn't need to do anything.
+```
+
## 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)
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).
Pull the Docker image:
@@ -142,11 +296,10 @@
```bash
$ docker run \
--rm \
--name terraforming \
- -v /path/to/tf-files-dir:/app \
-e AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXXXXXXXX \
-e AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
-e AWS_DEFAULT_REGION=xx-yyyy-0 \
quay.io/dtan4/terraforming:latest \
terraforming s3
@@ -164,8 +317,8 @@
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
-## LICENSE
+## License
[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE)