From 23c3df43ad04be5fb785c683c97dd5428ed61e22 Mon Sep 17 00:00:00 2001 From: Jonathan Simon Date: Sun, 24 Nov 2019 20:47:39 -0800 Subject: [PATCH] Adding a start to control-plane infra --- terraform/aws/.gitignore | 31 +++++++++++++++++ terraform/aws/cloud_init.tf | 0 terraform/aws/control-plane.tf | 63 ++++++++++++++++++++++++++++++++++ terraform/aws/etcd.tf | 52 ++++++++++++++++++++++++++++ terraform/aws/variables.tf | 6 ++++ 5 files changed, 152 insertions(+) create mode 100644 terraform/aws/.gitignore create mode 100644 terraform/aws/cloud_init.tf create mode 100644 terraform/aws/control-plane.tf create mode 100644 terraform/aws/etcd.tf diff --git a/terraform/aws/.gitignore b/terraform/aws/.gitignore new file mode 100644 index 0000000..7506b90 --- /dev/null +++ b/terraform/aws/.gitignore @@ -0,0 +1,31 @@ +# Local .terraform directories +**/.terraform/* + +# .tfstate files +*.tfstate +*.tfstate.* + +# Crash log files +crash.log + +# Ignore any .tfvars files that are generated automatically for each Terraform run. Most +# .tfvars files are managed as part of configuration and so should be included in +# version control. +# +# example.tfvars + +# Ignore override files as they are usually used to override resources locally and so +# are not checked in +override.tf +override.tf.json +*_override.tf +*_override.tf.json + +# Include override files you do wish to add to version control using negated pattern +# +# !example_override.tf + +# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan +# example: *tfplan* + +*.tfvars diff --git a/terraform/aws/cloud_init.tf b/terraform/aws/cloud_init.tf new file mode 100644 index 0000000..e69de29 diff --git a/terraform/aws/control-plane.tf b/terraform/aws/control-plane.tf new file mode 100644 index 0000000..65b5f0b --- /dev/null +++ b/terraform/aws/control-plane.tf @@ -0,0 +1,63 @@ +data "aws_vpc" "main" { + filter { + name = "tag:Name" + values = ["${var.prefix}-${var.name}"] + } +} + +data "aws_ami" "base" { + owners = ["self"] + most_recent = true + + filter { + name = "tag:Name" + values = ["jibakurei-amzn2-base"] + } +} + +# module "asg" { +# source = "terraform-aws-modules/autoscaling/aws" +# version = "~> 3.0" +# name = "cp-leader" + +# # Launch configuration +# lc_name = "example-lc" + +# image_id = "ami-ebd02392" +# instance_type = "t2.micro" +# security_groups = ["sg-12345678"] + +# root_block_device = [ +# { +# volume_size = "8" +# volume_type = "gp2" +# }, +# ] + +# # Auto scaling group +# asg_name = "example-asg" +# vpc_zone_identifier = ["subnet-1235678", "subnet-87654321"] +# health_check_type = "EC2" +# min_size = 1 +# max_size = 1 +# desired_capacity = 1 +# wait_for_capacity_timeout = 0 + +# tags = [ +# { +# key = "Environment" +# value = "dev" +# propagate_at_launch = true +# }, +# { +# key = "Project" +# value = "megasecret" +# propagate_at_launch = true +# }, +# ] + +# tags_as_map = { +# extra_tag1 = "extra_value1" +# extra_tag2 = "extra_value2" +# } +# } diff --git a/terraform/aws/etcd.tf b/terraform/aws/etcd.tf new file mode 100644 index 0000000..32de456 --- /dev/null +++ b/terraform/aws/etcd.tf @@ -0,0 +1,52 @@ +locals { + service = "${var.prefix}-${var.name}-etcd" +} + +module "asg" { + count = "${var.etcd_member_count}" + source = "terraform-aws-modules/autoscaling/aws" + version = "~> 3.0" + + name = "${local.service}-asg" + + # Launch configuration + lc_name = "${local.service}-lc" + + image_id = "ami-ebd02392" ## need to set a up data source for this. + instance_type = "t3.micro" + security_groups = ["sg-12345678"] ## need to create this + + root_block_device = [ + { + volume_size = "20" + volume_type = "gp2" + }, + ] + + # Auto scaling group + asg_name = "${local.service}-asg" + vpc_zone_identifier = ["subnet-1235678", "subnet-87654321"] + health_check_type = "EC2" + min_size = 1 + max_size = 1 + desired_capacity = 1 + wait_for_capacity_timeout = 0 + + tags = [ + { + key = "Environment" + value = "dev" + propagate_at_launch = true + }, + { + key = "Project" + value = "megasecret" + propagate_at_launch = true + }, + ] + + tags_as_map = { + extra_tag1 = "extra_value1" + extra_tag2 = "extra_value2" + } +} diff --git a/terraform/aws/variables.tf b/terraform/aws/variables.tf index e09f35b..c77bb8a 100644 --- a/terraform/aws/variables.tf +++ b/terraform/aws/variables.tf @@ -14,3 +14,9 @@ variable "prefix" { description = "The prefix to add the name" default = "jibakurei" } + +variable "etcd_member_count" { + type = string + description = "The number of etcd instances in the cluster" + default = "1" +}