main.tf 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. provider "aws" {
  2. region = var.region
  3. profile = var.profile
  4. version = "~> 2.67"
  5. }
  6. module "vpc" {
  7. source = "../tfmodule-aws-2tier-vpc"
  8. region = var.region
  9. profile = var.profile
  10. vpc-name = var.vpc-name
  11. vpc-cidr = var.vpc-cidr
  12. vpc-azs = var.vpc-azs
  13. enable-private = false
  14. common-tags = {
  15. "Owner" = "maguec"
  16. }
  17. }
  18. module "nodes" {
  19. source = "../tfmodule-aws-redis-enterprise"
  20. region = var.region
  21. profile = var.profile
  22. open-nets = ["76.14.80.208/32"]
  23. <<<<<<< HEAD
  24. data-node-count = 3
  25. re-volume-size = 500
  26. re-instance-type = "m5.xlarge"
  27. =======
  28. data-node-count = 5
  29. re-volume-size = 250
  30. re-instance-type = "m5.4xlarge"
  31. >>>>>>> 650c625a384961385a2361e14ba70eeeceb21a30
  32. vpc-cidr = var.vpc-cidr
  33. vpc-azs = var.vpc-azs
  34. vpc-name = var.vpc-name
  35. vpc-id = module.vpc.vpc-id
  36. vpc-subnets = module.vpc.subnets-public
  37. allow-public-ssh = 1
  38. enable-flash = true
  39. common-tags = {
  40. "Owner" = "maguec"
  41. "Project" = "AWS Testing Environment"
  42. }
  43. }
  44. <<<<<<< HEAD
  45. module "tmuxer" {
  46. source = "../tfmodule-cloud-tmux"
  47. ssh-key = "${var.vpc-name}.pem"
  48. user = "ubuntu"
  49. nodes = module.nodes.node-ips
  50. outpath = "."
  51. }
  52. module "dns-lb" {
  53. source = "../tfmodule-aws-dns-lb"
  54. profile = var.profile
  55. region = var.region
  56. vpc-subnets = module.vpc.subnets-public
  57. vpc-id = module.vpc.vpc-id
  58. node-ids = module.nodes.node-ids
  59. cluster-name = "maguetest.redisdemo.com"
  60. common-tags = {
  61. "Owner" = "maguec"
  62. "Project" = "AWS Testing Environment"
  63. }
  64. =======
  65. module "tmux" {
  66. source = "../tfmodule-cloud-tmux"
  67. session-name = "cpredis"
  68. ssh-key = "${var.vpc-name}.pem"
  69. user = "ubuntu"
  70. nodes = concat(module.nodes.node-ips, [aws_eip.re-eip.public_ip])
  71. outpath = "${path.module}"
  72. }
  73. # Start CP Redis Testernode
  74. resource "aws_instance" "re" {
  75. ami = data.aws_ami.re-ami.id
  76. instance_type = "m5.4xlarge"
  77. availability_zone = "${element(var.vpc-azs, 1)}"
  78. subnet_id = "${element(module.vpc.subnets-public, 1)}"
  79. vpc_security_group_ids = [module.nodes.re-security-group]
  80. source_dest_check = false
  81. key_name = var.vpc-name
  82. tags = merge({ Name = "Tester-${var.vpc-name}-1" }, var.common-tags)
  83. }
  84. resource "aws_eip" "re-eip" {
  85. vpc = true
  86. tags = merge({ Name = "${var.vpc-name}-node-eip-1" }, var.common-tags)
  87. }
  88. resource "aws_eip_association" "re-eip-assoc" {
  89. instance_id = "${element(aws_instance.re.*.id, 1)}"
  90. allocation_id = "${element(aws_eip.re-eip.*.id, 1)}"
  91. depends_on = ["aws_instance.re", "aws_eip.re-eip"]
  92. }
  93. resource "null_resource" "remote-config" {
  94. provisioner "remote-exec" {
  95. connection {
  96. user = "ubuntu"
  97. host = aws_eip.re-eip.public_ip
  98. private_key = "${file("~/.ssh/${var.vpc-name}.pem")}"
  99. agent = true
  100. }
  101. inline = ["sudo apt update > /dev/null && sudo apt install -y python python-pip > /dev/null"]
  102. }
  103. depends_on = ["aws_instance.re", "aws_eip_association.re-eip-assoc"]
  104. }
  105. output "node-ips" {
  106. value = formatlist("ssh -i ~/.ssh/${var.vpc-name}.pem -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ubuntu@%s", module.nodes.node-ips)
  107. }
  108. output "tester-ips" {
  109. value = formatlist("ssh -i ~/.ssh/${var.vpc-name}.pem -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ubuntu@%s", aws_eip.re-eip.public_ip)
  110. }
  111. output "tmux" {
  112. value = "run ./cloud-tmux to enable tmux connections"
  113. }
  114. data "template_file" "raft_group_setup" {
  115. template = "${file("${path.module}/raft_group_setup.tpl")}"
  116. vars = {
  117. node1 = module.nodes.node-internal-ips[0]
  118. node2 = module.nodes.node-internal-ips[1]
  119. node3 = module.nodes.node-internal-ips[2]
  120. node4 = module.nodes.node-internal-ips[3]
  121. node5 = module.nodes.node-internal-ips[4]
  122. }
  123. }
  124. resource "null_resource" "raft_group_setup" {
  125. provisioner "local-exec" {
  126. command = "echo \"${data.template_file.raft_group_setup.rendered}\" > ${path.module}/ansible/raft_group_setup"
  127. }
  128. depends_on = ["data.template_file.raft_group_setup"]
  129. >>>>>>> 650c625a384961385a2361e14ba70eeeceb21a30
  130. }