From 3768cf39bb6fb36f167f68218f6f2b14a38687f8 Mon Sep 17 00:00:00 2001 From: Ignacio Van Droogenbroeck Date: Tue, 25 May 2021 16:17:38 -0300 Subject: [PATCH 1/3] updated to Terraform 0.15.4 --- .DS_Store | Bin 0 -> 6148 bytes LICENSE | 21 ----- auth.tf | 5 ++ files/init.sh | 9 --- init/.DS_Store | Bin 0 -> 6148 bytes init/data-nodes.sh | 26 +++++++ init/meta-nodes.sh | 26 +++++++ main.tf | 189 +++++++++++++++++++++------------------------ outputs.tf | 2 +- variables.tf | 68 ++++++++-------- 10 files changed, 183 insertions(+), 163 deletions(-) create mode 100644 .DS_Store delete mode 100644 LICENSE create mode 100644 auth.tf delete mode 100644 files/init.sh create mode 100644 init/.DS_Store create mode 100644 init/data-nodes.sh create mode 100644 init/meta-nodes.sh diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..02ce1ae812f96899ab2ea2d0ddfee7496b0cd5fe GIT binary patch literal 6148 zcmeHKJ8Hu~5S?*^5u{P+a!+7z?PepC6ZitbF*pGmxo~=Qxq{E*K+csn9|s9xmoAbS zn0?xrd6M=OJG(^0^~YvGR1r}L7o<-a#wL03kxe{O09oF#+b&kG?fx*TydDs4L37&D zI~|Ao?`1!?Z<}VlYuAXC(|oGV^RK62eseQ_coMqL||-Gpi$Yc7;JRJ zlhu$&{ho8R*Z?X;#sdQ$usiVu`^UU;z|d`K|pi~3kB|> FzzH1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0> /etc/fstab' >> /tmp/disks.sh +echo 'echo /dev/xvdh /mnt/influxdb/data ext4 defaults 0 2 >> /etc/fstab' >> /tmp/disks.sh + +# Mount disks at startup +sudo bash /tmp/disks.sh + +# Download, install and start InfluxDB data-nodes +sudo wget -O /tmp/influxdb-data_1.8.6-c1.8.6_amd64.deb https://dl.influxdata.com/enterprise/releases/influxdb-data_1.8.6-c1.8.6_amd64.deb +sleep 5; +sudo dpkg -i /tmp/influxdb-data_1.8.6-c1.8.6_amd64.deb +sleep 5; +sudo systemctl start influxdb \ No newline at end of file diff --git a/init/meta-nodes.sh b/init/meta-nodes.sh new file mode 100644 index 0000000..63e5041 --- /dev/null +++ b/init/meta-nodes.sh @@ -0,0 +1,26 @@ +#!/bin/sh +sudo apt-get update +sudo apt dist-upgrade -y +sudo apt-get install -y python wget +sudo sleep 10; + +# Format attached disks +sudo mkfs.ext4 /dev/xvdh + +# Create folders & mount disks +sudo mkdir -p /mnt/influxdb/meta/data +sudo mount /dev/xvdh /mnt/influxdb/meta/data + +# Create script to mount disks at startup +echo 'echo # influxdb-meta-disk >> /etc/fstab' >> /tmp/disks.sh +echo 'echo /dev/xvdh /mnt/influxdb/meta/data ext4 defaults 0 2 >> /etc/fstab' >> /tmp/disks.sh + +# Mount disks at startup +sudo bash /tmp/disks.sh + +# Download, install and start InfluxDB meta-nodes +sudo wget -O /tmp/influxdb-meta_1.8.6-c1.8.6_amd64.deb https://dl.influxdata.com/enterprise/releases/influxdb-meta_1.8.6-c1.8.6_amd64.deb +sleep 5; +sudo dpkg -i /tmp/influxdb-meta_1.8.6-c1.8.6_amd64.deb +sleep 5; +sudo systemctl start influxdb-meta \ No newline at end of file diff --git a/main.tf b/main.tf index c94f227..09f6b4a 100644 --- a/main.tf +++ b/main.tf @@ -1,126 +1,113 @@ -# Used to obtain availabilty zones when creating persistent storage. -data "aws_subnet" "selected" { - count = "${length(var.subnet_ids)}" - id = "${var.subnet_ids[count.index]}" -} - # Create data nodes, equally distrubting them across specified subnets / AVs resource "aws_instance" "data_node" { - ami = "${var.ami}" - instance_type = "${var.instance_type}" - tags = "${merge(var.tags, map("Name", "${var.name}-data${format("%02d", count.index + 1)}"), map("Role", "${replace(var.name, "-", "_")}_data"), map("Type", "data"))}" - subnet_id = "${element(var.subnet_ids, count.index)}" - key_name = "${var.key_name}" - user_data = "${var.user_data == "" ? file("${path.module}/files/init.sh") : var.user_data }" - ebs_optimized = true - vpc_security_group_ids = ["${concat(list(aws_security_group.influx_cluster.id, aws_security_group.data_node.id), var.security_groups)}"] - count = "${var.data_instances}" + ami = var.ami + instance_type = var.instance_type + subnet_id = var.subnet_id + key_name = var.key_name + user_data = var.user_data == "" ? file("${path.module}/init/data-nodes.sh") : var.user_data + ebs_optimized = true + vpc_security_group_ids = var.security_group + count = var.data_instances } resource "aws_ebs_volume" "data" { - size = "${var.data_disk_size}" - encrypted = true - type = "io1" - iops = "${var.data_disk_iops}" - availability_zone = "${element(data.aws_subnet.selected.*.availability_zone, count.index)}" - tags = "${var.tags}" - count = "${var.data_instances}" + size = var.data_disk_size + encrypted = true + type = "io1" + iops = var.data_disk_iops + availability_zone = var.availabity_zone + count = var.data_instances } resource "aws_volume_attachment" "data_attachment" { - device_name = "${var.data_disk_device_name}" - volume_id = "${aws_ebs_volume.data.*.id[count.index]}" - instance_id = "${aws_instance.data_node.*.id[count.index]}" - count = "${var.data_instances}" - force_detach = true + device_name = var.data_disk_device_name + volume_id = aws_ebs_volume.data.*.id[count.index] + instance_id = aws_instance.data_node.*.id[count.index] + count = var.data_instances + force_detach = true } - # Creates all meta nodes in the first / same subnet, this avoids splits if one AV goes offline. # Data nodes function fine without access to meta-nodes between shard creation. -resource "aws_instance" "meta_node" { - ami = "${var.ami}" - instance_type = "t2.medium" - tags = "${merge(var.tags, map("Name", "${var.name}-meta${format("%02d", count.index + 1)}"), map("Role", "${replace(var.name, "-", "_")}_meta"), map("Type", "data"))}" - subnet_id = "${element(var.subnet_ids,0)}" - key_name = "${var.key_name}" - user_data = "${var.user_data == "" ? file("${path.module}/files/init.sh") : var.user_data }" - vpc_security_group_ids = ["${concat(list(aws_security_group.influx_cluster.id), var.security_groups)}"] - count = "${var.meta_instances}" -} + resource "aws_instance" "meta_node" { + ami = var.ami + instance_type = "t2.medium" + subnet_id = var.subnet_id + key_name = var.key_name + user_data = var.user_data == "" ? file("${path.module}/init/meta-nodes.sh") : var.user_data + vpc_security_group_ids = var.security_group + count = var.meta_instances + } -resource "aws_ebs_volume" "meta" { - size = "100" - encrypted = true - type = "io1" - iops = "4000" - availability_zone = "${data.aws_subnet.selected.0.availability_zone}" - tags = "${var.tags}" - count = "${var.meta_instances}" -} + resource "aws_ebs_volume" "meta" { + size = "100" + encrypted = true + type = "io1" + iops = var.data_disk_iops + availability_zone = var.availabity_zone + count = var.meta_instances + } -resource "aws_volume_attachment" "meta" { - device_name = "${var.meta_disk_device_name}" - volume_id = "${aws_ebs_volume.meta.*.id[count.index]}" - instance_id = "${aws_instance.meta_node.*.id[count.index]}" - count = "${var.meta_instances}" - force_detach = true -} + resource "aws_volume_attachment" "meta" { + device_name = var.meta_disk_device_name + volume_id = aws_ebs_volume.meta.*.id[count.index] + instance_id = aws_instance.meta_node.*.id[count.index] + count = var.meta_instances + force_detach = true + } resource "aws_route53_record" "meta_node" { - zone_id = "${var.zone_id}" - name = "${var.name}-meta${format("%02d", count.index + 1)}" - type = "A" - ttl = "120" - records = ["${element(aws_instance.meta_node.*.private_ip, count.index)}"] - count = "${var.meta_instances}" -} + zone_id = var.zone_id + name = "${var.name}-meta${format("%02d", count.index + 1)}" + type = "A" + ttl = "120" + records = ["${element(aws_instance.meta_node.*.private_ip, count.index)}"] + count = var.meta_instances + } -resource "aws_route53_record" "data_node" { - zone_id = "${var.zone_id}" - name = "${var.name}-data${format("%02d", count.index + 1)}" - type = "A" - ttl = "120" - records = ["${element(aws_instance.data_node.*.private_ip, count.index)}"] - count = "${var.data_instances}" -} + resource "aws_route53_record" "data_node" { + zone_id = var.zone_id + name = "${var.name}-data${format("%02d", count.index + 1)}" + type = "A" + ttl = "120" + records = ["${element(aws_instance.data_node.*.private_ip, count.index)}"] + count = var.data_instances + } # Setup inter-node cluster communications. -resource "aws_security_group" "influx_cluster" { - name = "${var.name}_cluster" - description = "Rules required for an Influx Enterprise Cluster" - tags = "${merge(var.tags, map("Name", "${var.name}"), map("Role", "influx"))}" - vpc_id = "${var.vpc_id}" -} + resource "aws_security_group" "influxdb_cluster" { + name = "${var.name}_cluster" + description = "Rules required for an Influx Enterprise Cluster" + vpc_id = "${var.vpc_id}" + } -resource "aws_security_group_rule" "cluster_comms" { - type = "ingress" - from_port = 8088 - to_port = 8091 - protocol = "tcp" - cidr_blocks = ["${formatlist("%s/32", concat(aws_instance.meta_node.*.private_ip, aws_instance.data_node.*.private_ip))}"] - security_group_id = "${aws_security_group.influx_cluster.id}" -} + resource "aws_security_group_rule" "cluster_comms" { + type = "ingress" + from_port = 8088 + to_port = 8091 + protocol = "tcp" + cidr_blocks = "${formatlist("%s/32", concat(aws_instance.meta_node.*.private_ip, aws_instance.data_node.*.private_ip))}" + security_group_id = "${aws_security_group.influxdb_cluster.id}" + } resource "aws_security_group_rule" "outbound" { - type = "egress" - to_port = 0 - protocol = "-1" - from_port = 0 - cidr_blocks = ["0.0.0.0/0"] - security_group_id = "${aws_security_group.influx_cluster.id}" -} + type = "egress" + to_port = 0 + protocol = "-1" + from_port = 0 + cidr_blocks = ["0.0.0.0/0"] + security_group_id = "${aws_security_group.influxdb_cluster.id}" + } resource "aws_security_group" "data_node" { - description = "Security group for influx data node ingress" - vpc_id = "${var.vpc_id}" - tags = "${merge(var.tags, map("Name", "${var.name}"), map("Role", "influx"))}" - - ingress { - from_port = "8086" - to_port = "8086" - protocol = "tcp" - cidr_blocks = ["0.0.0.0/0"] - } -} + description = "Security group for influx data node ingress" + vpc_id = var.vpc_id + + ingress { + from_port = "8086" + to_port = "8086" + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + } \ No newline at end of file diff --git a/outputs.tf b/outputs.tf index 87581f7..a034a1e 100644 --- a/outputs.tf +++ b/outputs.tf @@ -10,5 +10,5 @@ output "data_node_ids" { output "data_node_count" { description = "Yields the data node count, this can be used in conjunction with modules that configure load balancers etc" - value = "${var.data_instances}" + value = var.data_instances } diff --git a/variables.tf b/variables.tf index be3fa89..f53e428 100644 --- a/variables.tf +++ b/variables.tf @@ -1,72 +1,78 @@ +variable "availabity_zone" { + description = "Insert the Availability Zone according to your Subnet and PVC" + default = "us-east-2b" +} + variable "name" { - description = "The prefix that will be applied to resources managed by this module" - default = "influx" + description = "The prefix that will be applied to resources managed by this module" + default = "influxdb" } variable "ami" { - description = "The AMI ID to deploy" + description = "The AMI ID to deploy" + default = "ami-0f42acddbf04bd1b6" } variable "data_instances" { - description = "The number of data nodes to run" + description = "The number of data nodes to run" + default = 2 } variable "meta_instances" { - description = "The number of meta nodes to run" -} - -variable "tags" { - description = "Tags to be applied to all resources managed by this module" - type = "map" + description = "The number of meta nodes to run" + default = 3 } -variable "subnet_ids" { - type = "list" - description = "The subnet ID for servers, data-nodes will be equally distributed accross these subnets" +variable "subnet_id" { + description = "The subnet ID for servers, data-nodes will be equally distributed accross these subnets" + default = "" } variable "instance_type" { - description = "The AWS Instance type. For example, m2.large" + description = "The AWS Instance type. For example, m2.large" + default = "m4.large" } variable "vpc_id" { - description = "VPC ID for instances and security groups" + description = "VPC ID for instances and security groups" + default = "" } variable "key_name" { - description = "Key name for new hosts" + description = "Key name for new hosts" + default = "" } variable "zone_id" { - description = "The private DNS zone to create records for hosts" + description = "The private DNS zone to create records for hosts" + default = "" } variable "data_disk_size" { - description = "The size of the data disks to provision, for data nodes only" - default = 300 + description = "The size of the data disks to provision, for data nodes only" + default = 300 } variable "data_disk_iops" { - description = "The number of IOPs for the io1 type volume" - default = 4000 + description = "The number of IOPs for the io1 type volume" + default = 4000 } -variable "security_groups" { - type = "list" - description = "Extra security groups to apply to all hosts, useful for bastion host access" - default = [] +variable "security_group" { + description = "Extra security groups to apply to all hosts, useful for bastion host access" + default = [""] } variable "user_data" { - description = "User data script for all instances" - default = "" + description = "User data script for all instances" + default = "" } variable "data_disk_device_name" { - description = "The name of the device to attach to the data-nodes" - default = "/dev/xvdh" + description = "The name of the device to attach to the data-nodes" + default = "/dev/xvdh" } variable "meta_disk_device_name" { - description = "The name of the device to attach to the meta-nodes" - default = "/dev/xvdh" + description = "The name of the device to attach to the meta-nodes" + default = "/dev/xvdh" } From 0d0ae8882ad1a33a1877cb743205a7b6c10b5f33 Mon Sep 17 00:00:00 2001 From: Ignacio Van Droogenbroeck <64545348+xe-nvdk@users.noreply.github.com> Date: Tue, 25 May 2021 16:18:33 -0300 Subject: [PATCH 2/3] Delete .DS_Store --- init/.DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 init/.DS_Store diff --git a/init/.DS_Store b/init/.DS_Store deleted file mode 100644 index 5008ddfcf53c02e82d7eee2e57c38e5672ef89f6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 Date: Tue, 25 May 2021 16:18:41 -0300 Subject: [PATCH 3/3] Delete .DS_Store --- .DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 02ce1ae812f96899ab2ea2d0ddfee7496b0cd5fe..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKJ8Hu~5S?*^5u{P+a!+7z?PepC6ZitbF*pGmxo~=Qxq{E*K+csn9|s9xmoAbS zn0?xrd6M=OJG(^0^~YvGR1r}L7o<-a#wL03kxe{O09oF#+b&kG?fx*TydDs4L37&D zI~|Ao?`1!?Z<}VlYuAXC(|oGV^RK62eseQ_coMqL||-Gpi$Yc7;JRJ zlhu$&{ho8R*Z?X;#sdQ$usiVu`^UU;z|d`K|pi~3kB|> Fzz