main.tf 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. provider "aws" {
  2. region = var.region
  3. profile = var.profile
  4. }
  5. module "vpc" {
  6. source = "../tfmodule-aws-2tier-vpc"
  7. region = var.region
  8. profile = var.profile
  9. vpc-name = var.vpc-name
  10. vpc-cidr = var.vpc-cidr
  11. vpc-azs = var.vpc-azs
  12. enable-private = false
  13. common-tags = {
  14. "Owner" = "maguec"
  15. "Project" = "example_terraform"
  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. data-node-count = 3
  24. re-volume-size = 250
  25. re-instance-type = "m5.4xlarge"
  26. vpc-cidr = var.vpc-cidr
  27. vpc-azs = var.vpc-azs
  28. vpc-name = var.vpc-name
  29. vpc-id = module.vpc.vpc-id
  30. vpc-subnets = module.vpc.subnets-public
  31. enable-flash = true
  32. common-tags = {
  33. "Owner" = "maguec"
  34. "Project" = "example_terraform"
  35. }
  36. }
  37. # Start CP Redis Testernode
  38. resource "aws_instance" "re" {
  39. ami = data.aws_ami.re-ami.id
  40. instance_type = "m5.4xlarge"
  41. availability_zone = "${element(var.vpc-azs, 1)}"
  42. subnet_id = "${element(module.vpc.subnets-public, 1)}"
  43. vpc_security_group_ids = [module.nodes.re-security-group]
  44. source_dest_check = false
  45. key_name = var.vpc-name
  46. tags = merge({ Name = "Tester-${var.vpc-name}-1" }, var.common-tags)
  47. }
  48. resource "aws_eip" "re-eip" {
  49. vpc = true
  50. tags = merge({ Name = "${var.vpc-name}-node-eip-1" }, var.common-tags)
  51. }
  52. resource "aws_eip_association" "re-eip-assoc" {
  53. instance_id = "${element(aws_instance.re.*.id, 1)}"
  54. allocation_id = "${element(aws_eip.re-eip.*.id, 1)}"
  55. depends_on = ["aws_instance.re", "aws_eip.re-eip"]
  56. }
  57. resource "null_resource" "remote-config" {
  58. provisioner "remote-exec" {
  59. connection {
  60. user = "ubuntu"
  61. host = aws_eip.re-eip.public_ip
  62. private_key = "${file("~/.ssh/${var.vpc-name}.pem")}"
  63. agent = true
  64. }
  65. inline = ["sudo apt update > /dev/null && sudo apt install -y python python-pip > /dev/null"]
  66. }
  67. depends_on = ["aws_instance.re", "aws_eip_association.re-eip-assoc"]
  68. }
  69. output "node-ips" {
  70. 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)
  71. }
  72. output "tester-ips" {
  73. 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)
  74. }