main.tf 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * https://wiki.nuxeo.com/display/INFRA/Cloud+Provisioning
  3. * 1) Create Subnets for the Stack
  4. * - On Public with a /24 size.
  5. * - One private Subnet to run Nuxeo
  6. * - at least 2 Private Subnets for Databases
  7. * 2) Create a NAT Gateway in one of the Public Subnets
  8. * 3) Create a Route with the Internet Gateway as default route, associate it with the Public Subnet(s)
  9. * 4) Create a Route with the NAT Gateway as default route, *that should be associated to all Private Subnets when they are created*
  10. * 5) Create a Security Group for ELBs that accepts HTTP and HTTPS from anywhere
  11. * 6) Create a Security Group for Bastion Hosts that accepts SSH from anywhere
  12. *
  13. * 7) Create a Bastion Host with bastion host SG associated to ti, install NTP and Userify on it
  14. */
  15. ///////////////////////////////////////////////////////////////////////
  16. // RESOURCES
  17. ///////////////////////////////////////////////////////////////////////
  18. resource "random_id" "customer" {
  19. byte_length = 8
  20. }
  21. module "net" {
  22. source = "./net/"
  23. stack_name = "${var.stack_name}"
  24. region = "${var.aws_region}"
  25. vpc_id = "${var.vpc_id}"
  26. public_subnets = ["10.0.10.0/24"]
  27. private_subnets = ["10.0.11.0/24"]
  28. private_db_subnets = ["10.0.100.0/24","10.0.101.0/24"]
  29. }
  30. #-------------
  31. #DNS Entry for Cloud Customer
  32. #-------------
  33. resource "aws_route53_record" "dns" {
  34. zone_id = "Z1EFT3O5K9NMCJ" // Zone ID for nuxeocloud.com
  35. name = "${name}"
  36. type = "CNAME"
  37. ttl = "300"
  38. weighted_routing_policy {
  39. weight = 90
  40. }
  41. set_identifier = "${var.stack_name}"
  42. records = ["${var.stack_name}.nuxeocloud.com"]
  43. }
  44. # -------------------------------------
  45. # S3 buckets:w for Nuxeo and for Backups
  46. # -------------------------------------
  47. module "s3" {
  48. source = "./s3/"
  49. stack_name = "${var.stack_name}"
  50. #cust_id = "${random_id.customer.b64}"
  51. cust_id = "${uuid()}"
  52. }
  53. # -------------------------
  54. # RDS Postgres Database
  55. # -------------------------
  56. module "rds" {
  57. source = "./rds/"
  58. region = "${var.aws_region}"
  59. stack_name = "${var.stack_name}"
  60. database_name = "nuxeo"
  61. rds_allocated_storage = "10"
  62. rds_engine_version = "9.4.7"
  63. security_group_ids = ["${module.net.sg_internal_id}"]
  64. #subnet_ids = ["${aws_subnet.db_private.0.id}", "${aws_subnet.db_private.1.id}"]
  65. #db_private_subnets = ["${element(module.net.db_private, 0)}", "${element(module.net.db_private, 1)}"]
  66. subnet_ids = ["${element(module.net.db_private, 0)}", "${element(module.net.db_private, 1)}"]
  67. }
  68. #-------------------------
  69. # Elastic Cache Redis
  70. #-------------------------
  71. module "elasticcache" {
  72. source = "./elasticcache"
  73. stack_name = "${var.stack_name}-redis"
  74. engine_version = "3.2.4"
  75. node_type = "cache.t2.micro"
  76. security_group_ids = ["${module.net.sg_internal_id}"]
  77. private_subnet_ids = ["${module.net.db_private}"]
  78. }
  79. #-------------------------
  80. # EC2 Instances
  81. #-------------------------
  82. module "nuxeo" {
  83. source = "./instance/"
  84. # Variables for creating an instance
  85. stack_name = "${var.stack_name}-nuxeo"
  86. instance_name = "${var.stack_name}-nuxeo-instance"
  87. os_release = "xenial"
  88. instance_type = "t2.micro"
  89. public_key_path ="${var.public_key_path}"
  90. # public_key_path="/path/to/my/pub_key"
  91. subnet_id="${element(module.net.private_subnets, 0)}"
  92. }
  93. module "bastion" {
  94. source = "bastion/"
  95. vpc_id = "${var.vpc_id}"
  96. allowed_network="10.0.0.0/16"
  97. subnet_public="${module.net.public_subnets}"
  98. }