From 1b187754a5d85b42cea1720d956baa2bd7f59ea2 Mon Sep 17 00:00:00 2001 From: David Shafer Date: Sun, 22 Jul 2018 19:00:52 -0500 Subject: [PATCH] Initial commit --- .gitignore | 2 + README.md | 9 +++ eks-cluster.tf | 87 ++++++++++++++++++++ eks-worker-nodes.tf | 162 +++++++++++++++++++++++++++++++++++++ outputs.tf | 59 ++++++++++++++ providers.tf | 19 +++++ variables.tf | 8 ++ vpc.tf | 57 +++++++++++++ workstation-external-ip.tf | 18 +++++ 9 files changed, 421 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 eks-cluster.tf create mode 100644 eks-worker-nodes.tf create mode 100644 outputs.tf create mode 100644 providers.tf create mode 100644 variables.tf create mode 100644 vpc.tf create mode 100644 workstation-external-ip.tf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0a08988 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.terraform/ +terraform.tfstate diff --git a/README.md b/README.md new file mode 100644 index 0000000..99d2ff9 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# EKS Getting Started Guide Configuration + +(Adapted from https://github.com/terraform-providers/terraform-provider-aws) + +This is the full configuration from https://www.terraform.io/docs/providers/aws/guides/eks-getting-started.html + +See that guide for additional information. + +NOTE: This full configuration utilizes the [Terraform http provider](https://www.terraform.io/docs/providers/http/index.html) to call out to icanhazip.com to determine your local workstation external IP for easily configuring EC2 Security Group access to the Kubernetes master servers. Feel free to replace this as necessary. diff --git a/eks-cluster.tf b/eks-cluster.tf new file mode 100644 index 0000000..58a7389 --- /dev/null +++ b/eks-cluster.tf @@ -0,0 +1,87 @@ +# +# EKS Cluster Resources +# * IAM Role to allow EKS service to manage other AWS services +# * EC2 Security Group to allow networking traffic with EKS cluster +# * EKS Cluster +# + +resource "aws_iam_role" "demo-cluster" { + name = "terraform-eks-demo-cluster" + + assume_role_policy = < $CA_CERTIFICATE_FILE_PATH +INTERNAL_IP=$(curl -s http://169.254.169.254/latest/meta-data/local-ipv4) +sed -i s,MASTER_ENDPOINT,${aws_eks_cluster.demo.endpoint},g /var/lib/kubelet/kubeconfig +sed -i s,CLUSTER_NAME,${var.cluster-name},g /var/lib/kubelet/kubeconfig +sed -i s,REGION,${data.aws_region.current.name},g /etc/systemd/system/kubelet.service +sed -i s,MAX_PODS,20,g /etc/systemd/system/kubelet.service +sed -i s,MASTER_ENDPOINT,${aws_eks_cluster.demo.endpoint},g /etc/systemd/system/kubelet.service +sed -i s,INTERNAL_IP,$INTERNAL_IP,g /etc/systemd/system/kubelet.service +DNS_CLUSTER_IP=10.100.0.10 +if [[ $INTERNAL_IP == 10.* ]] ; then DNS_CLUSTER_IP=172.20.0.10; fi +sed -i s,DNS_CLUSTER_IP,$DNS_CLUSTER_IP,g /etc/systemd/system/kubelet.service +sed -i s,CERTIFICATE_AUTHORITY_FILE,$CA_CERTIFICATE_FILE_PATH,g /var/lib/kubelet/kubeconfig +sed -i s,CLIENT_CA_FILE,$CA_CERTIFICATE_FILE_PATH,g /etc/systemd/system/kubelet.service +systemctl daemon-reload +systemctl restart kubelet +USERDATA +} + +resource "aws_launch_configuration" "demo" { + associate_public_ip_address = true + iam_instance_profile = "${aws_iam_instance_profile.demo-node.name}" + image_id = "${data.aws_ami.eks-worker.id}" + instance_type = "m4.large" + name_prefix = "terraform-eks-demo" + security_groups = ["${aws_security_group.demo-node.id}"] + user_data_base64 = "${base64encode(local.demo-node-userdata)}" + + lifecycle { + create_before_destroy = true + } +} + +resource "aws_autoscaling_group" "demo" { + desired_capacity = 2 + launch_configuration = "${aws_launch_configuration.demo.id}" + max_size = 2 + min_size = 1 + name = "terraform-eks-demo" + vpc_zone_identifier = ["${aws_subnet.demo.*.id}"] + + tag { + key = "Name" + value = "terraform-eks-demo" + propagate_at_launch = true + } + + tag { + key = "kubernetes.io/cluster/${var.cluster-name}" + value = "owned" + propagate_at_launch = true + } +} diff --git a/outputs.tf b/outputs.tf new file mode 100644 index 0000000..1492754 --- /dev/null +++ b/outputs.tf @@ -0,0 +1,59 @@ +# +# Outputs +# + +locals { + config_map_aws_auth = <