Code Monkey home page Code Monkey logo

terraform-aws-docker's Introduction

Terraform + AWS + Docker Swarm setup

Here is the basic setup to run up docker swarm cluster in AWS using the Terraform. Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. Terraform can manage existing and popular service providers as well as custom in-house solutions. Using Terraform helps to create the infrastructure you can change, and trace safely and efficiently. A small swarm cluster will be created during startup. One swarm manager + two swarm workers. In the app-instances.tf you will find the configuration. The swarm is initiated during provisioning. All other swarm agents (workers) will connect to the manager by a token, generated during the swarm initialisation. The trick is we should do it automatically, but we don't know the token before the initialisation. To send the token to the agents, I copy it to a file on the swarm manager and do "scp" to the master host from the agent's machines.

Installation

How to install terraform you can find here. Or you can using a Docker image to keep your environment clear. For example, this one.

Preparations

AWS account

If you don't have account, you may get a free AWS account. In the setup will be used free t2.micro instances.

SSH keys

Before to start, create ssh keys. Terraform will create key-pair in AWS, based on these keys. See how to create ssh keys Create a pem file with private ssh key you generated. Terraform will need to the pem file to connect to instances for provisioning.

Update the project file with new information

There are three file need your credentials for successing run up. First of all, update key-pair.tf set there a path to the public ssh key, generated earlier. In variables.tf update your AWS account information. In app-instances.tf update connection block for each resources, set there the path to ssh private key.

How to use

After all configuration files are ready, you can do check if there are no mistakes.

terraform plan

This command will show either syntax errors or list of resources will be created. After you can run:

terraform apply

This command will build and run all resources in the *.tf files. If you run this command many times, Terraform will destroy previous instances before creating new ones. That is it. Now you have fully functioned docker swarm cluster in AWS.

If you want to terminate instances and destroy the configuration you may call:

terraform destroy

terraform-aws-docker's People

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.