Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix count logic for ebs, make variable region non-required #5

Merged
merged 3 commits into from
Jan 25, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Terraform Module for providing N general purpose EC2 hosts.

If you only need to provision a single EC2 instance, consider using the [terraform-aws-ec2-instance](https://github.com/cloudposse/terraform-aws-ec2-instance) module instead.

**IMPORTANT** This module by-design does not provision an AutoScaling group. It was designed to provision a discrete number of instances suitable for running stateful services such as databases (E.g. Kafka, Redis, etc).
**IMPORTANT** This module by-design does not provision an AutoScaling group. It was designed to provision a discrete number of instances suitable for running stateful services such as databases (E.g. Kafka, Redis, etc).


Included features:
Expand All @@ -21,7 +21,7 @@ Included features:

---

This project is part of our comprehensive ["SweetOps"](https://docs.cloudposse.com) approach towards DevOps.
This project is part of our comprehensive ["SweetOps"](https://docs.cloudposse.com) approach towards DevOps.


It's 100% Open Source and licensed under the [APACHE2](LICENSE).
Expand Down Expand Up @@ -154,7 +154,7 @@ Available targets:
| name | Name (e.g. `bastion` or `db`) - required for `terraform-terraform-label` module | string | - | yes |
| namespace | Namespace (e.g. `cp` or `cloudposse`) - required for `terraform-terraform-label` module | string | - | yes |
| private_ips | Private IP address to associate with the instances in the VPC | list | `<list>` | no |
| region | AWS Region the instance is launched in | string | - | yes |
| region | AWS Region the instance is launched in | string | - | no |
| root_iops | Amount of provisioned IOPS. This must be set if root_volume_type is set to `io1` | string | `0` | no |
| root_volume_size | Size of the root volume in gigabytes | string | `10` | no |
| root_volume_type | Type of root volume. Can be standard, gp2 or io1 | string | `gp2` | no |
Expand Down Expand Up @@ -208,7 +208,7 @@ Check out these related projects.

## References

For additional context, refer to some of these links.
For additional context, refer to some of these links.

- [terraform-aws-ec2-bastion-server](https://github.com/cloudposse/terraform-aws-ec2-bastion-server) - Terraform module to define a generic Bastion host with parameterized user_data

Expand All @@ -221,9 +221,9 @@ File a GitHub [issue](https://github.com/cloudposse/terraform-aws-ec2-instance-g

## Commercial Support

Work directly with our team of DevOps experts via email, slack, and video conferencing.
Work directly with our team of DevOps experts via email, slack, and video conferencing.

We provide [*commercial support*][commercial_support] for all of our [Open Source][github] projects. As a *Dedicated Support* customer, you have access to our team of subject matter experts at a fraction of the cost of a full-time engineer.
We provide [*commercial support*][commercial_support] for all of our [Open Source][github] projects. As a *Dedicated Support* customer, you have access to our team of subject matter experts at a fraction of the cost of a full-time engineer.

[![E-Mail](https://img.shields.io/badge/[email protected])](mailto:[email protected])

Expand All @@ -233,7 +233,7 @@ We provide [*commercial support*][commercial_support] for all of our [Open Sourc
- **Bug Fixes.** We'll rapidly work to fix any bugs in our projects.
- **Build New Terraform Modules.** We'll develop original modules to provision infrastructure.
- **Cloud Architecture.** We'll assist with your cloud strategy and design.
- **Implementation.** We'll provide hands-on support to implement our reference architectures.
- **Implementation.** We'll provide hands-on support to implement our reference architectures.


## Community Forum
Expand Down Expand Up @@ -267,9 +267,9 @@ Copyright © 2017-2018 [Cloud Posse, LLC](https://cloudposse.com)



## License
## License

[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

See [LICENSE](LICENSE) for full details.

Expand Down Expand Up @@ -310,7 +310,7 @@ This project is maintained and funded by [Cloud Posse, LLC][website]. Like it? P

We're a [DevOps Professional Services][hire] company based in Los Angeles, CA. We love [Open Source Software](https://github.com/cloudposse/)!

We offer paid support on all of our projects.
We offer paid support on all of our projects.

Check out [our other projects][github], [apply for a job][jobs], or [hire us][hire] to help with your cloud strategy and implementation.

Expand All @@ -335,5 +335,3 @@ Check out [our other projects][github], [apply for a job][jobs], or [hire us][hi
[osterman_avatar]: https://github.com/osterman.png?size=150
[Jamie-BitFlight_homepage]: https://github.com/Jamie-BitFlight
[Jamie-BitFlight_avatar]: https://github.com/Jamie-BitFlight.png?size=150


2 changes: 1 addition & 1 deletion cloud_watch_alarm.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Restart dead or hung instance

locals {
action = "arn:aws:swf:${var.region}:${data.aws_caller_identity.default.account_id}:${var.default_alarm_action}"
action = "arn:aws:swf:${local.region}:${data.aws_caller_identity.default.account_id}:${var.default_alarm_action}"
}

resource "aws_cloudwatch_metric_alarm" "default" {
Expand Down
13 changes: 8 additions & 5 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
locals {
instance_count = "${var.instance_enabled == "true" ? var.instance_count : 0}"
security_group_count = "${var.create_default_security_group == "true" ? 1 : 0}"
region = "${var.region}"
region = "${var.region != "" ? var.region : data.aws_region.default.name}"
root_iops = "${var.root_volume_type == "io1" ? var.root_iops : "0"}"
ebs_iops = "${var.ebs_volume_type == "io1" ? var.ebs_iops : "0"}"
availability_zone = "${var.availability_zone}"
Expand All @@ -10,6 +10,8 @@ locals {
ssh_key_pair_path = "${var.ssh_key_pair_path == "" ? path.cwd : var.ssh_key_pair_path }"
}

data "aws_region" "default" {}

data "aws_caller_identity" "default" {}

data "aws_iam_policy_document" "default" {
Expand Down Expand Up @@ -90,7 +92,8 @@ resource "aws_instance" "default" {
delete_on_termination = "${var.delete_on_termination}"
}

tags = "${merge(module.label.tags, map("instance_index", "${count.index}"))}"
tags = "${merge(module.label.tags, map("instance_index", "${count.index}"))}"
volume_tags = "${merge(module.label.tags, map("instance_index", "${count.index}"))}"
Copy link
Member

@aknysh aknysh Jan 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like volume_tags is not in use.
and it's the same as tags?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, isn't a same. ltmgfy :)

volume_tags - (Optional) A mapping of tags to assign to the devices created by the instance at launch time.

in case of module it's rood device i.e. /

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SweetOps
they are the same in the code, and volume_tags is not in use anywhere.
please review it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh, I don't understand what you want to hear. Why the both of them have same tags? It is necessary for consistency e.g. instance with name cp-test-kafka-1 should has the same name for root device (cp-test-kafka-1) and same tags as instance to which it assigned.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

volume_tags has been removed due hashicorp/terraform#3531 (comment)

}

##
Expand Down Expand Up @@ -124,8 +127,8 @@ resource "aws_ebs_volume" "default" {
}

resource "aws_volume_attachment" "default" {
count = "${signum(local.instance_count) == 1 ? floor(var.ebs_volume_count / max(local.instance_count, 1)) : 0 }"
device_name = "${element(var.ebs_device_names, count.index)}"
count = "${signum(local.instance_count) == 1 ? var.ebs_volume_count * local.instance_count : 0 }"
device_name = "${element(slice(var.ebs_device_names, 0, floor(var.ebs_volume_count * local.instance_count / max(local.instance_count, 1))), count.index)}"
volume_id = "${element(aws_ebs_volume.default.*.id, count.index)}"
instance_id = "${aws_instance.default.id}"
instance_id = "${element(aws_instance.default.*.id, count.index)}"
}
1 change: 1 addition & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ variable "tags" {
}

variable "region" {
default = ""
description = "AWS Region the instance is launched in"
}

Expand Down