diff --git a/stack/generic-asg-ec2/ec2-asg.tf b/stack/generic-asg-ec2/ec2-asg.tf index 3e95c1b..baba623 100644 --- a/stack/generic-asg-ec2/ec2-asg.tf +++ b/stack/generic-asg-ec2/ec2-asg.tf @@ -4,9 +4,9 @@ resource "aws_autoscaling_group" "generic-asg" { min_size = "${var.min_size}" desired_capacity = "${var.desired_capacity}" health_check_type = "${var.hc_type}" - launch_template = { - id = "${aws_launch_template.generic_lc_template.id}" - version = "$$Latest" + launch_template = { + id = "${aws_launch_template.generic_lc_template.id}" + version = "$$Latest" } vpc_zone_identifier = ["${var.subnets}"] @@ -15,6 +15,13 @@ resource "aws_autoscaling_group" "generic-asg" { resource "aws_launch_template" "generic_lc_template" { name = "lc-${var.name}" key_name = "${var.key_name}" - image_id = "${var.image_id}" - + image_id = "${var.ami_id}" + instance_type = "${var.instance_type}" + vpc_security_group_ids = "${var.vpc_security_group_ids}" + tag_specifications { + resource_type = "instance" + tags { + Name = "${var.name}" + } + } } diff --git a/stack/generic-asg-ec2/vars_app.tf b/stack/generic-asg-ec2/vars_app.tf index 66d4024..6e7a06f 100644 --- a/stack/generic-asg-ec2/vars_app.tf +++ b/stack/generic-asg-ec2/vars_app.tf @@ -3,8 +3,8 @@ variable "name" { } variable "max_size"{ - default = 1 -} + default = 1 +} variable "min_size"{ default = 1 @@ -26,6 +26,15 @@ variable "key_name" { default = "test" } -variable "image_id"{ - default = "ami-0e4c9b46b89ddd90c" +variable "ami_id"{ + default = "ami-0e4c9b46b89ddd90c" +} + +variable "instance_type" { + default = "t2.medium" } + +variable "vpc_security_group_ids" { + default = [""] +} + diff --git a/stack/kubernetes-kubeadm/server.tf b/stack/kubernetes-kubeadm/server.tf new file mode 100644 index 0000000..7f8613b --- /dev/null +++ b/stack/kubernetes-kubeadm/server.tf @@ -0,0 +1,45 @@ +provider "aws" { + profile = "vrdev" + region = "us-east-2" +} + +data "template_file" "init" { + template = "${file("user-data.sh")}" +} +resource "aws_instance" "master" { +#ami = "ami-03c6239555bb12112" +#ami = "ami-0f65671a86f061fcd" +ami = "${var.ami-id}" +instance_type = "${var.instance-type}" +subnet_id = "${var.subnet-id}" +key_name = "${var.key-name}" +security_groups = "${var.security-groups}" + +user_data = "${data.template_file.init.rendered}" +tags { + Name = "{$var.name-master}" +} + + #provisioner "local-exec" { + # command = "echo ${aws_instance.master.private_ip} >> private_ips.txt" + # } +# provisioner "local-exec" { +# command = "sleep 60; ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -e 'ansible_python_interpreter=/usr/bin/python3' -u ubuntu --private-key /home/lazevedo/Documents/KEYS/VR-CLOUD-TEAM.ppk -i '${aws_instance.master.private_ip}', /home/lazevedo/Documents/repo/terraform-geek182/stack/kubernetes-kubeadm/playbook.yml" +# } +} + + + + +resource "aws_instance" "worker1" { +ami = "${var.ami-id}" +instance_type = "${var.instance-type}" +subnet_id = "${var.subnet-id}" +key_name = "${var.key-name}" +security_groups = "${var.security-groups}" +user_data = "${data.template_file.init.rendered}" +tags { + Name = "${var.name-worker}" +} + +} diff --git a/stack/kubernetes-kubeadm/user-data.sh b/stack/kubernetes-kubeadm/user-data.sh new file mode 100644 index 0000000..a4fbffb --- /dev/null +++ b/stack/kubernetes-kubeadm/user-data.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +sysctl -p +apt-get update +apt-get install -y docker.io + +apt-get update && apt-get install -y apt-transport-https curl +curl -4 -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - +echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list +apt-get update +apt-get install -y kubelet kubeadm kubectl +apt-mark hold kubelet kubeadm kubectl + +echo $(kubectl version) diff --git a/stack/kubernetes-kubeadm/vars.tf b/stack/kubernetes-kubeadm/vars.tf new file mode 100644 index 0000000..ca27afd --- /dev/null +++ b/stack/kubernetes-kubeadm/vars.tf @@ -0,0 +1,27 @@ +variable "ami-id" { + default = "ami-0f65671a86f061fcd" +} + +variable "instance-type" { + default = "t2.micro" +} + +variable "subnet-id" { + default = "" +} + +variable "key-name" { + default = "" +} + +variable "security-groups" { + default = ["sg,sg"] +} + +variable "name-worker" { + default = "WORKER" +} + +variable "name-master"{ + default = "MASTER" +}