diff --git a/examples/single-node-asg-test/tester.tf b/examples/single-node-asg-test/tester.tf new file mode 100644 index 00000000..59885b35 --- /dev/null +++ b/examples/single-node-asg-test/tester.tf @@ -0,0 +1,65 @@ +variable "region" { + description = "The region to put resources in" + default = "us-east-1" +} + +variable "az" { + description = "The availability zone to put resources in" + default = "us-east-1c" +} + +variable "key_name" { + description = "The keypair used to ssh into the asg intances" + default = "shida-east-1" +} + +provider "aws" { + region = var.region +} + +module "vpc" { + source = "../../modules/vpc-scenario-1" + azs = [var.az] + name_prefix = "eiptest" + cidr = "192.168.0.0/16" + public_subnet_cidrs = ["192.168.0.0/16"] + region = var.region + map_on_launch = false +} + +module "snasg" { + source = "../../modules/single-node-asg" + name_prefix = "unit" + name_suffix = "eiptest" + ami = module.ubuntu-ami.id + instance_type = "t2.micro" + region = var.region + key_name = var.key_name + subnet_id = module.vpc.public_subnet_ids[0] + security_group_ids = [aws_security_group.eiptest.id] + assign_eip = true +} + +module "ubuntu-ami" { + source = "../../modules/ami-ubuntu" + release = "16.04" +} + +resource "aws_security_group" "eiptest" { + name = "eiptest" + vpc_id = module.vpc.vpc_id + + ingress { + from_port = 22 + to_port = 22 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } +} diff --git a/modules/persistent-ebs/data.tf b/modules/persistent-ebs/data.tf index 51c1b231..c10dc27c 100644 --- a/modules/persistent-ebs/data.tf +++ b/modules/persistent-ebs/data.tf @@ -22,7 +22,6 @@ data "aws_iam_policy_document" "attach_ebs_policy_doc" { } resource "aws_iam_policy" "attach_ebs_policy" { - name = "attach_ebs" - + name = "attach_ebs" policy = data.aws_iam_policy_document.attach_ebs_policy_doc.json } diff --git a/modules/single-node-asg/main.tf b/modules/single-node-asg/main.tf index 01b9b95b..e53f9c48 100644 --- a/modules/single-node-asg/main.tf +++ b/modules/single-node-asg/main.tf @@ -11,6 +11,10 @@ * */ +resource "aws_eip" "eip" { + count = var.assign_eip ? 1 : 0 +} + module "service-data" { source = "../persistent-ebs" name_prefix = "${var.name_prefix}-${var.name_suffix}-data" @@ -42,20 +46,21 @@ module "server" { ami = var.ami subnet_ids = [var.subnet_id] azs = [data.aws_subnet.server-subnet.availability_zone] - public_ip = var.public_ip key_name = var.key_name elb_names = var.load_balancers max_nodes = 1 min_nodes = 1 root_volume_type = var.root_volume_type root_volume_size = var.root_volume_size - - iam_profile = module.instance_profile.iam_profile_id + iam_profile = module.instance_profile.iam_profile_id user_data = <