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

Automatically create enhanced monitoring role #21

Merged
merged 1 commit into from
Nov 13, 2017
Merged

Automatically create enhanced monitoring role #21

merged 1 commit into from
Nov 13, 2017

Conversation

s7anley
Copy link
Contributor

@s7anley s7anley commented Nov 2, 2017

No description provided.

@s7anley
Copy link
Contributor Author

s7anley commented Nov 11, 2017

Hi @antonbabenko, any chance this could be merged soon? 😉

@antonbabenko
Copy link
Member

Just came back from websummit and going to review it all during today/tomorrow. Sorry for the delay.

resource "aws_iam_role" "enhanced_monitoring" {
name = "${var.monitoring_role_autocreate}"
assume_role_policy = "${file("${path.module}/policy/enhancedmonitoring.json")}"
count = "${local.create_enhanced_role ? 1 : 0}"
Copy link
Member

Choose a reason for hiding this comment

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

Put count as the first argument, add an empty line after it.

name = "${var.monitoring_role_autocreate}-enhanced-monitoring-attachment"
roles = ["${aws_iam_role.enhanced_monitoring.name}"]
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonRDSEnhancedMonitoringRole"
count = "${local.create_enhanced_role ? 1 : 0}"
Copy link
Member

Choose a reason for hiding this comment

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

Same here

README.md Outdated
monitoring_interval = "30"
monitoring_role_arn = "arn:aws:iam::123456789012:role/rds-monitoring-role"
monitoring_role_autocreate = "rds-monitoring-role"
Copy link
Member

Choose a reason for hiding this comment

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

monitoring_role_autocreate sounds like a boolean, not string.
Let's call this as monitoring_role_name, and use create_monitoring_role as the main switch - true/false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I should additional variable create_monitoring_role for the switch and set some default name for monitoring_role_name?

Copy link
Member

Choose a reason for hiding this comment

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

yes, and the defaults are:

create_monitoring_role = false
monitoring_role_name = ""

@@ -1,6 +1,24 @@
##############
# DB instance
##############

locals {
create_enhanced_role = "${var.monitoring_role_autocreate != "" && var.monitoring_role_arn == ""}"
Copy link
Member

Choose a reason for hiding this comment

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

Avoid such rules (and locals in general unless it is possible to use specific module versions in Terraform Registry). Use count = "${var.create_monitoring_role}" as the main switch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to avoid the case of misconfiguration when a user provides ARN and also configure auto-creation, which could be skipped, but sure I will remove it.

}

resource "aws_iam_policy_attachment" "enhanced_monitoring" {
name = "${var.monitoring_role_autocreate}-enhanced-monitoring-attachment"
Copy link
Member

Choose a reason for hiding this comment

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

name = "${var.monitoring_role_name}" - shorter is better usually. In this case, it is clear that it is an attachment of enhanced monitoring policy, so -enhanced-monitoring-attachment can be safely removed.

@@ -31,7 +49,7 @@ resource "aws_db_instance" "this" {
iops = "${var.iops}"
publicly_accessible = "${var.publicly_accessible}"
monitoring_interval = "${var.monitoring_interval}"
monitoring_role_arn = "${var.monitoring_role_arn}"
monitoring_role_arn = "${coalesce(var.monitoring_role_arn, join("", aws_iam_role.enhanced_monitoring.*.arn))}"
Copy link
Member

Choose a reason for hiding this comment

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

I like this hack with join 👍

variables.tf Outdated
@@ -114,6 +114,11 @@ variable "monitoring_role_arn" {
default = ""
}

variable "monitoring_role_autocreate" {
description = "Automatically create IAM role with a defined name that permits RDS to send enhanced monitoring metrics to CloudWatch Logs. Creation in skipped, when monitoring_role_arn is provided."
Copy link
Member

Choose a reason for hiding this comment

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

Creation is skipped

@s7anley
Copy link
Contributor Author

s7anley commented Nov 13, 2017

Thanks for CR, all your comments are addressed.

@antonbabenko antonbabenko merged commit 6e3527a into terraform-aws-modules:master Nov 13, 2017
@s7anley s7anley deleted the enhanced-monitoring branch November 13, 2017 19:01
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants