Browse Source

abstracted the module to be used outside from this repo

Roberto Barbosa 8 years ago
parent
commit
14a103258d
5 changed files with 71 additions and 46 deletions
  1. 13 27
      main.tf
  2. 1 2
      net/main.tf
  3. 0 8
      provider.tf
  4. 2 3
      s3/main.tf
  5. 55 6
      variables.tf

+ 13 - 27
main.tf

@@ -1,30 +1,15 @@
 /*
 * https://wiki.nuxeo.com/display/INFRA/Cloud+Provisioning
-* 1) Create Subnets for the Stack
-*     - On Public with a /24 size. 
-*     - One private Subnet to run Nuxeo 
-*     - at least 2 Private Subnets for Databases
-* 2) Create a NAT Gateway in one of the Public Subnets
-* 3) Create a Route with the Internet Gateway as default route, associate it with the Public Subnet(s)
-* 4) Create a Route with the NAT Gateway as default route, *that should be associated to all Private Subnets when they are created*
-* 5) Create a Security Group for ELBs that accepts HTTP and HTTPS from anywhere
-* 6) Create a Security Group for Bastion Hosts that accepts SSH from anywhere
-* 
-* 7) Create a Bastion Host with bastion host SG associated to ti, install NTP and Userify on it
 */
 
 ///////////////////////////////////////////////////////////////////////
 // RESOURCES
 ///////////////////////////////////////////////////////////////////////
-resource "random_id" "customer" {
-  byte_length = 8
-}
-
 module "net" {
   source = "./net/"
 
-  stack_name = "${var.stack_name}"  
-  region = "${var.aws_region}"
+  stack_name = "${var.stack_name}"
+  region = "${var.region}"
   vpc_id = "${var.vpc_id}"
 
   public_subnets = ["10.0.10.0/24"]
@@ -54,7 +39,6 @@ resource "aws_route53_record" "dns" {
 module "s3" {
   source = "./s3/"
   stack_name = "${var.stack_name}"
-  #cust_id = "${random_id.customer.b64}"
   cust_id = "${uuid()}"
 }
 
@@ -64,11 +48,11 @@ module "s3" {
 # -------------------------
 module "rds" {
   source = "./rds/"
-  region = "${var.aws_region}"
+  region = "${var.region}"
   stack_name = "${var.stack_name}"
   database_name = "nuxeo"
-  rds_allocated_storage = "10"
-  rds_engine_version = "9.4.7"
+  rds_allocated_storage = "${var.rds_allocated_storage}"
+  rds_engine_version = "${rds_engine_version}"
   security_group_ids = ["${module.net.sg_internal_id}"]
   #subnet_ids = ["${aws_subnet.db_private.0.id}", "${aws_subnet.db_private.1.id}"]
   #db_private_subnets = ["${element(module.net.db_private, 0)}", "${element(module.net.db_private, 1)}"]
@@ -83,8 +67,8 @@ module "rds" {
 module "elasticcache" {
 	source = "./elasticcache"
 	stack_name = "${var.stack_name}-redis"
-	engine_version = "3.2.4"
-	node_type = "cache.t2.micro"
+	engine_version = "${engine_version}"
+	node_type = "$${var.node_type}"
 	security_group_ids = ["${module.net.sg_internal_id}"]
 	private_subnet_ids  = ["${module.net.db_private}"]
 }
@@ -97,13 +81,17 @@ module "nuxeo" {
   # Variables for creating an instance
   stack_name = "${var.stack_name}-nuxeo"
   instance_name = "${var.stack_name}-nuxeo-instance"
-  os_release = "xenial"
-  instance_type = "t2.micro"
+  os_release = "${os_release}"
+  instance_type = "${var.instance_type}"
   public_key_path ="${var.public_key_path}"
 #  public_key_path="/path/to/my/pub_key"
   subnet_id="${element(module.net.private_subnets, 0)}"
 }
 
+
+#-------------------------
+# Bastion EC2 Instances
+#-------------------------
 module "bastion" {
   source = "bastion/"
 
@@ -111,5 +99,3 @@ module "bastion" {
   allowed_network="10.0.0.0/16"
   subnet_public="${module.net.public_subnets}"
 }
-
-

+ 1 - 2
net/main.tf

@@ -36,7 +36,7 @@ resource "aws_subnet" "public" {
  resource "aws_subnet" "private" {
   vpc_id            = "${var.vpc_id}"
   cidr_block        = "${var.private_subnets[count.index]}"
-  availability_zone = "${var.region}${var.azs[count.index]}"
+  #availability_zone = "${var.region}${var.azs[count.index]}"
   count             = "${length(var.private_subnets)}"
   tags {
     Name 		= "${var.stack_name}-subnet-private-${var.region}${element(var.azs, count.index)}"
@@ -322,4 +322,3 @@ resource "aws_elb" "elb" {
   tags {
   }
 }
-

+ 0 - 8
provider.tf

@@ -1,8 +0,0 @@
-#-------------
-# AWS Provider
-#-------------
-provider "aws" {
-  access_key = "${var.aws_access_key}"
-  secret_key = "${var.aws_secret_key}"
-  region     = "${var.aws_region}"
-}

+ 2 - 3
s3/main.tf

@@ -6,7 +6,7 @@ resource "aws_s3_bucket" "bucket" {
     acl = "private"
 
   tags {
-    Name              = "nuxeo-${var.cust_id}"
+    Name              = "nuxeo-${var.stack_name}"
     billing-category    = "customers"
     billing-subcategory = "${var.stack_name}"
     role                = "nuxeo.aws-s3"
@@ -18,10 +18,9 @@ resource "aws_s3_bucket" "bucket_backup" {
     acl = "private"
 
   tags {
-    Name              = "nuxeo-backup-${var.cust_id}"
+    Name              = "nuxeo-backup-${var.stack_name}"
     billing-category    = "customers"
     billing-subcategory = "${var.stack_name}"
     role                = "nuxeo.aws-s3"
   }
 }
-

+ 55 - 6
variables.tf

@@ -1,17 +1,66 @@
 #-------------------
 # VARIABLES
 #-------------------
+
+// Variables for providers used in this module
+/*variable "aws_access_key" {}
+variable "aws_secret_key" {}*/
+
+// Deployer SSH Pub SSH keys
+variable "public_key_path" {}
+
+
 variable "stack_name" {
 }
-variable "aws_region" {
+
+variable "region" {
 	default = "us-west-2"
 }
 
 variable "vpc_id" {}
 
-// Variables for providers used in this module
-variable "aws_access_key" {}
-variable "aws_secret_key" {}
+variable "public_subnets" {
+	type    = "list"
+}
+variable "private_subnets" {
+	type    = "list"
+}
 
-// Deployer SSH Pub SSH keys
-variable "public_key_path" {}
+variable "private_db_subnets" {
+	type    = "list"
+}
+
+/* RDS Options */
+
+variable "rds_allocated_storage" {
+  type    = "string"
+  default = "10"
+}
+
+variable "rds_engine_version" {
+  type    = "string"
+  default = "9.4.7"
+}
+
+/* REDIS/elasticcache option */
+
+variable "engine_version" {
+  type    = "string"
+  default = "3.2.4"
+}
+
+variable "node_type" {
+  type    = "string"
+  default = "cache.t2.micro"
+}
+
+/* Instance Options */
+ variable "os_release" {
+   type    = "string"
+   default = "xenial"
+ }
+
+ variable "instance_type" {
+   type    = "string"
+   default = "t2.micro"
+ }