# TerraCognita

GoDoc (opens new window) Gitter chat (opens new window) AUR package (opens new window) Homebrew (opens new window)

# Overview

TerraCognita allows you to migrate your current cloud infrastructure to infrastructure-as-code. It quickly and automatically creates Terraform from all of your manually-provisioned resources, allowing them to be easily replicated by you and your cloud provider. All you have to do is connect to your cloud, and let TerraCognita take care of the rest.

  • Simplify migration to Terraform from manually provisioned infrastructures
  • “Reverse engineers” Terraform from manual infras
  • Keep configuration drift in check
  • Makes it easy to apply policies

Imports your current Cloud infrastructure to an Infrastructure As Code Terraform (opens new window) configuration (HCL) or/and to a Terraform State.

At Cycloid (opens new window), Infrastructure As Code is in the company DNA since the beginning. To help our new customers adopting this best practice, we decided to build Terracognita to convert an existing infrastructure on Cloud Infrastructure into Terraform code in an automated way, relying on Terraform providers built by the community. We focused on AWS, GCP and Azure but Alibaba, Vmware and Openstack will be the next to be integrated.

We decided to Open Source this tool as we believe that it will help people to adopt IaC in an easy way. Cycloid provides this tool to let people import their infrastructure into Cycloid's pipelines (opens new window), allow them to generate infrastructure diagram and manage all infra/application life cycle from a single interface.

If you are interested in contributing to TerraCognita or simply curious about what's next, take a look at the public roadmap (opens new window). For a high level overview, check out the What is Terracognita? (opens new window) blog post.

# Cloud providers

Terracognita currently imports AWS, GCP and AzureRM cloud provider as Terraform (0.13.5) resource/state. Please see the following versions as follow:

Providers:

  • AWS: 3.1.0
  • AzureRM: 2.34.0
  • GCP: 3.40.0

# Installation

# Binary

Visit the releases (opens new window) page to select your system, architecture and version you need. To pull the latest release:

$ curl -L https://github.com/cycloidio/terracognita/releases/latest/download/terracognita-linux-amd64.tar.gz -o terracognita-linux-amd64.tar.gz
$ tar -xf terracognita-linux-amd64.tar.gz
$ chmod u+x terracognita-linux-amd64
$ sudo mv terracognita-linux-amd64 /usr/local/bin/terracognita
1
2
3
4

# Development

You can build and install with the latest sources, you will enjoy the new features and bug fixes. It uses Go Modules, so GO 1.15+ is required.

$ git clone https://github.com/cycloidio/terracognita
$ cd terracognita
$ make install
1
2
3

# Arch Linux

There are two entries in the AUR: terracognita-git (opens new window) (targets the latest git commit) and terracognita (opens new window) (targets the latest stable release).

$ yay -Ss terracognita
aur/terracognita 1:0.3.0-1 (+0 0.00%)
    Reads from existing Cloud Providers (reverse Terraform) and generates your infrastructure as code on Terraform configuration
aur/terracognita-git 1:v0.3.0.r27.gdfc5a99-1 (+0 0.00%)
    Reads from existing Cloud Providers (reverse Terraform) and generates your infrastructure as code on Terraform configuration
1
2
3
4
5

# Install via brew

If you're macOS user and using Homebrew (opens new window), you can install via brew command:

$ brew install terracognita
1

# Usage

Using the terracognita --help you will know the basics.

$ make help
help: Makefile                   This help dialog
lint: $(GOLANGCI_LINT) $(GOLINT) Runs the linter
test:                            Runs the tests
ci: lint test                    Runs the linter and the tests
dbuild:                          Builds the docker image with same name as the binary
build:                           Bulids the binary
clean:                           Removes binary and/or docker image
1
2
3
4
5
6
7
8

asciicast (opens new window)

# Docker

You can use directly the image built (opens new window), or you can build your own. To build your Docker image just run:

$ make dbuild
1

And then depending on the image you want to use (cycloid/terracognita or your local build terracognita):

$ docker run cycloid/terracognita -h
1

Example:

$ export AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXXXXXXXX
$ export AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
$ export AWS_DEFAULT_REGION=xx-yyyy-0
$ docker run \
		-v "${PWD}"/outputs:/app/outputs \
		cycloid/terracognita aws \
		--hcl app/outputs/resources.tf
1
2
3
4
5
6
7

# Local

The local version can be used the same way as docker. You simply need to be build it locally.

# To test

To speed up the testing, you can write a small provider.tffile within the same folder you imported your resources & tfstate:

terraform {
 backend "local" {
   path = "./$TFSTATE_PATH"
 }
}

provider "aws" {
 access_key = "${var.access_key}"
 secret_key = "${var.secret_key}"
 region     = "${var.region}"
 version    = "2.12.0"
}

variable "access_key" {}
variable "secret_key" {}
variable "region" {}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

Then run the terraform init & plan commands:

$ terraform init
$ terraform plan -var access_key=$AWS_ACCESS_KEY_ID -var secret_key=$AWS_SECRET_ACCESS_KEY -var region=$AWS_DEFAULT_REGION
1
2

# License

Please see the MIT LICENSE (opens new window) file.

# Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog (opens new window), and this project adheres to Semantic Versioning (opens new window).