Giter VIP home page Giter VIP logo

rails_terraform's Introduction

Ruby on Rails deployment using Terraform, Docker, AWS Codepipeline

Resources

System Installation

Install Terraform

Install terraform using the this link https://learn.hashicorp.com/terraform/getting-started/install.html

You don't need local installation of docker as docker build will be run on AWS codepipeline server using buildspec.

Github access Token

Generate a new personal github token following the steps from this link

Paste the token genrated in modules/copepipeline/main.tf at the following line Also add owner for the repository you want to deploy along with repository namd and branch. AWS code build created using terraform will read the repository owner, name, brnach from the following to run AWS code build using this source.

configuration = {
        Owner      = "owner_of_repo"
        Repo       = "repo_name"
        Branch     = "branch_of_repo"
        OAuthToken = "***********token*********"
      }

Deploying application to AWS

In deploy.tf set access_key and secret_key for AWS account.

provider "aws" {
  region = var.region
  access_key = "**********************"
  secret_key = "**********************"
}

Switch environment to deploy to aws

In application root folder create .tfvars file for staging, production, testing environment. Define all variables in variables.tf file and specify value for each variable in .tfvars file for each environment.

For example, in variables.tf file define variables as follows

variable "region" {
  description = "Region that the instances will be created"
}

/*====
environment specific variables
======*/

variable "database_name" {
  description = "The database name for Production"
}

variable "database_username" {
  description = "The username for the Production database"
}

variable "database_password" {
  description = "The user password for the Production database"
}

variable "secret_key_base" {
  description = "The Rails secret key for production"
}

variable "domain" {
  default = "The domain of your application"
}

variable "rabbit_name" {
	description = "A random environment"
}

variable "environment" {
	description = "Environment for the application"
}

variable "availability_zones" {
	type = "list"
}

And in production.tfvars or staging.tfvars the value for each variable can be set. For example in production.tfvars

region                        = "us-east-1"
domain                        = "railsterraform.com"

/* rds */
database_name      = "railsterraform_production"
database_username  = "railsterraform"
database_password  = "myawesomepasswordproduction"

/* secret key */
secret_key_base    = "8d412aee3ceaa494fe1c276f5f7e524b9e33f649c03690e689e5b36a0cf4ce2a6f50024bc31f276c22b668e619d61a42b79f5e595759f377a8fa373e2907f41e"

rabbit_name = "Yo Yo Singh"
environment = "production"

availability_zones = ["us-east-1a", "us-east-1b"]

After this setup run the following command in project root $ terraform init

After successfully installing the terraform plugins run the plan command. When running the plan command pass --var-file argument to command with value of the .tfvars file you want to run for. For example to deploy the application to staging environment run the following command

$ terraform plan --var-file=staging.tfvars

After successfully creating the plan run the following command

$ terraform apply --var-file=staging.tfvars

This will start creating your AWS infrastructure for the application and will success with providing url for the application loadbalancer using the following command

$ terraform output alb_dns_name

rails_terraform's People

Contributors

ajaysharmalng avatar ajays1991 avatar

Watchers

James Cloos avatar  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.