From 618bb42bc20f69930473715cbca415f9275edaad Mon Sep 17 00:00:00 2001 From: itsdalmo Date: Thu, 14 Jun 2018 18:17:26 +0200 Subject: [PATCH] Clean up descriptions and rename prefix to name_prefix. --- examples/default/example.tf | 2 +- main.tf | 21 +++++----- outputs.tf | 16 ++++---- variables.tf | 82 ++++++++++++++++++------------------- 4 files changed, 60 insertions(+), 61 deletions(-) diff --git a/examples/default/example.tf b/examples/default/example.tf index aad7ce1..8e5bc5a 100644 --- a/examples/default/example.tf +++ b/examples/default/example.tf @@ -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}"] diff --git a/main.tf b/main.tf index 7083439..279d55a 100644 --- a/main.tf +++ b/main.tf @@ -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}" } @@ -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" { @@ -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}"] @@ -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" { @@ -82,7 +82,7 @@ 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}" } @@ -90,13 +90,12 @@ 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)}" } diff --git a/outputs.tf b/outputs.tf index dd6ac5b..15c4073 100644 --- a/outputs.tf +++ b/outputs.tf @@ -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}" } diff --git a/variables.tf b/variables.tf index 5976ad8..db1abd7 100644 --- a/variables.tf +++ b/variables.tf @@ -1,32 +1,12 @@ # ------------------------------------------------------------------------------ # 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" { @@ -34,39 +14,34 @@ variable "subnet_ids" { 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 = <