Skip to content

Commit

Permalink
Clean up descriptions and rename prefix to name_prefix.
Browse files Browse the repository at this point in the history
  • Loading branch information
itsdalmo committed Jun 14, 2018
1 parent 2a253a5 commit 618bb42
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 61 deletions.
2 changes: 1 addition & 1 deletion examples/default/example.tf
Expand Up @@ -12,7 +12,7 @@ data "aws_subnet_ids" "main" {

module "asg" {
source = "../../"
prefix = "your-project"
name_prefix = "your-project"
user_data = "#!bin/bash\necho hello world"
vpc_id = "${data.aws_vpc.main.id}"
subnet_ids = ["${data.aws_subnet_ids.main.ids}"]
Expand Down
21 changes: 10 additions & 11 deletions main.tf
Expand Up @@ -2,7 +2,7 @@
# Resources
# ------------------------------------------------------------------------------
resource "aws_iam_role" "main" {
name = "${var.prefix}-role"
name = "${var.name_prefix}-role"
assume_role_policy = "${data.aws_iam_policy_document.main.json}"
}

Expand All @@ -19,22 +19,22 @@ data "aws_iam_policy_document" "main" {
}

resource "aws_iam_instance_profile" "main" {
name = "${var.prefix}-profile"
name = "${var.name_prefix}-profile"
role = "${aws_iam_role.main.name}"
}

resource "aws_iam_role_policy" "main" {
name = "${var.prefix}-permissions"
name = "${var.name_prefix}-permissions"
role = "${aws_iam_role.main.id}"
policy = "${var.instance_policy}"
}

resource "aws_security_group" "main" {
name = "${var.prefix}-sg"
name = "${var.name_prefix}-sg"
description = "Terraformed security group."
vpc_id = "${var.vpc_id}"

tags = "${merge(var.tags, map("Name", "${var.prefix}-sg"))}"
tags = "${merge(var.tags, map("Name", "${var.name_prefix}-sg"))}"
}

resource "aws_security_group_rule" "egress" {
Expand All @@ -47,7 +47,7 @@ resource "aws_security_group_rule" "egress" {
}

resource "aws_launch_configuration" "main" {
name_prefix = "${var.prefix}-asg-"
name_prefix = "${var.name_prefix}-asg-"
instance_type = "${var.instance_type}"
iam_instance_profile = "${aws_iam_instance_profile.main.name}"
security_groups = ["${aws_security_group.main.id}"]
Expand All @@ -67,7 +67,7 @@ resource "aws_launch_configuration" "main" {
}

locals {
asg_tags = "${merge(var.tags, map("Name", "${var.prefix}"))}"
asg_tags = "${merge(var.tags, map("Name", "${var.name_prefix}"))}"
}

data "null_data_source" "autoscaling" {
Expand All @@ -82,21 +82,20 @@ data "null_data_source" "autoscaling" {

resource "aws_cloudformation_stack" "main" {
depends_on = ["aws_launch_configuration.main"]
name = "${var.prefix}-asg"
name = "${var.name_prefix}-asg"
template_body = "${data.template_file.main.rendered}"
}

data "template_file" "main" {
template = "${file("${path.module}/cloudformation.yml")}"

vars {
prefix = "${var.prefix}"
launch_configuration = "${aws_launch_configuration.main.name}"
health_check_type = "${var.health_check_type}"
await_signal = "${var.await_signal}"
pause_time = "${var.pause_time}"
min_size = "${var.instance_count}"
max_size = "${var.instance_count_max}"
min_size = "${var.min_size}"
max_size = "${var.max_size}"
subnets = "${jsonencode(var.subnet_ids)}"
tags = "${jsonencode(data.null_data_source.autoscaling.*.outputs)}"
}
Expand Down
16 changes: 8 additions & 8 deletions outputs.tf
Expand Up @@ -2,21 +2,21 @@
# Output
# ------------------------------------------------------------------------------
output "id" {
value = "${aws_cloudformation_stack.main.outputs["AsgName"]}"
description = "The autoscaling group id (name)."
value = "${aws_cloudformation_stack.main.outputs["AsgName"]}"
}

output "role_name" {
value = "${aws_iam_role.main.name}"
description = "The name of the instance role."
value = "${aws_iam_role.main.name}"
}

output "role_arn" {
value = "${aws_iam_role.main.arn}"
}

output "role_id" {
value = "${aws_iam_role.main.id}"
description = "The Amazon Resource Name (ARN) specifying the instance role."
value = "${aws_iam_role.main.arn}"
}

output "security_group_id" {
value = "${aws_security_group.main.id}"
description = "The ID of the security group."
value = "${aws_security_group.main.id}"
}
82 changes: 41 additions & 41 deletions variables.tf
@@ -1,72 +1,47 @@
# ------------------------------------------------------------------------------
# Variables
# ------------------------------------------------------------------------------
variable "prefix" {
variable "name_prefix" {
description = "A prefix used for naming resources."
}

variable "user_data" {
description = "User data script for the launch configuration."
default = ""
}

variable "health_check_type" {
description = "Optional: Type of health check to use - either ELB or EC2."
default = "EC2"
}

variable "await_signal" {
description = "Await signals (WaitOnResourceSignals) for the autoscaling rolling update policy."
default = "false"
}

variable "pause_time" {
description = "Pause time for the autoscaling rolling update policy."
default = "PT5M"
}

variable "vpc_id" {
description = "ID of the VPC for the subnets."
description = "The VPC ID."
}

variable "subnet_ids" {
description = "ID of subnets where instances can be provisioned."
type = "list"
}

variable "user_data" {
description = "The user data to provide when launching the instance."
default = ""
}

variable "instance_type" {
description = "Type of instance to provision."
default = "t2.micro"
}

variable "instance_volume_size" {
description = "Size of the root block device."
default = "8"
}

variable "instance_count" {
description = "Desired (and minimum) number of instances."
default = "1"
}

variable "instance_count_max" {
description = "Maximum number of instances."
default = "3"
}

variable "instance_ami" {
description = "AMI id for the launch configuration."
description = "The EC2 image ID to launch."
default = "ami-db51c2a2"
}

variable "instance_key" {
description = "Name of an EC2 key-pair for SSH access."
description = "The key name that should be used for the instance."
default = ""
}

// Workaround because we cannot use count since the instance policy can be computed in some cases.
variable "instance_volume_size" {
description = "The size of the volume in gigabytes."
default = "8"
}

// Workaround because we cannot use count since the passed policy can be computed in some cases.
variable "instance_policy" {
description = "Optional: A policy document which is applied to the instance profile."
description = "A policy document to apply to the instance profile."

default = <<EOF
{
Expand All @@ -83,6 +58,31 @@ variable "instance_policy" {
EOF
}

variable "min_size" {
description = "The minimum (and desired) size of the auto scale group. "
default = "1"
}

variable "max_size" {
description = "The maximum size of the auto scale group."
default = "3"
}

variable "health_check_type" {
description = "EC2 or ELB. Controls how health checking is done."
default = "EC2"
}

variable "await_signal" {
description = "Await signals (WaitOnResourceSignals) for the autoscaling rolling update policy."
default = "false"
}

variable "pause_time" {
description = "Pause time for the autoscaling rolling update policy."
default = "PT5M"
}

variable "tags" {
description = "A map of tags (key-value pairs) passed to resources."
type = "map"
Expand Down

0 comments on commit 618bb42

Please sign in to comment.