Commit 2192242f authored by Anton Babenko's avatar Anton Babenko Committed by GitHub

Merge branch 'master' into final_snapshot_identifier

parents 5f4ae710 d40e3a66
...@@ -39,6 +39,10 @@ module "db" { ...@@ -39,6 +39,10 @@ module "db" {
maintenance_window = "Mon:00:00-Mon:03:00" maintenance_window = "Mon:00:00-Mon:03:00"
backup_window = "03:00-06:00" backup_window = "03:00-06:00"
# Enhanced Monitoring - see example for details on how to create the role
monitoring_interval = "30"
monitoring_role_arn = "arn:aws:iam::123456789012:role/rds-monitoring-role"
tags = { tags = {
Owner = "user" Owner = "user"
Environment = "dev" Environment = "dev"
......
...@@ -30,26 +30,24 @@ module "db" { ...@@ -30,26 +30,24 @@ module "db" {
engine_version = "5.7.11" engine_version = "5.7.11"
instance_class = "db.t2.large" instance_class = "db.t2.large"
allocated_storage = 5 allocated_storage = 5
storage_encrypted = false
# kms_key_id = "arm:aws:kms:<region>:<accound id>:key/<kms key id>"
name = "demodb" name = "demodb"
username = "user" username = "user"
password = "YourPwdShouldBeLongAndSecure!" password = "YourPwdShouldBeLongAndSecure!"
port = "3306" port = "3306"
vpc_security_group_ids = ["${data.aws_security_group.default.id}"] vpc_security_group_ids = ["${data.aws_security_group.default.id}"]
maintenance_window = "Mon:00:00-Mon:03:00" maintenance_window = "Mon:00:00-Mon:03:00"
backup_window = "03:00-06:00" backup_window = "03:00-06:00"
backup_retention_period = 0 // disable backups to create DB faster backup_retention_period = 0 // disable backups to create DB faster
tags = { tags = {
Owner = "user" Owner = "user"
Environment = "dev" Environment = "dev"
} }
# DB subnet group # DB subnet group
subnet_ids = ["${data.aws_subnet_ids.all.ids}"] subnet_ids = ["${data.aws_subnet_ids.all.ids}"]
# DB parameter group # DB parameter group
family = "mysql5.7" family = "mysql5.7"
......
Enhanced Monitoring example
===========================
Configuration in this directory creates the additional resources required to use Enhanced Monitoring.
See http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_Monitoring.OS.html for details
Data sources are used to discover existing VPC resources (VPC, subnet and security group).
Usage
=====
To run this example you need to execute:
```bash
$ terraform init
$ terraform plan
$ terraform apply
```
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.
provider "aws" {
region = "eu-west-1"
}
##############################################################
# Data sources to get VPC, subnets and security group details
##############################################################
data "aws_vpc" "default" {
default = true
}
data "aws_subnet_ids" "all" {
vpc_id = "${data.aws_vpc.default.id}"
}
data "aws_security_group" "default" {
vpc_id = "${data.aws_vpc.default.id}"
name = "default"
}
##################################################
# Create an IAM role to allow enhanced monitoring
##################################################
resource "aws_iam_role" "rds_enhanced_monitoring" {
name = "rds-enhanced_monitoring-role"
assume_role_policy = "${data.aws_iam_policy_document.rds_enhanced_monitoring.json}"
}
resource "aws_iam_role_policy_attachment" "rds_enhanced_monitoring" {
role = "${aws_iam_role.rds_enhanced_monitoring.name}"
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonRDSEnhancedMonitoringRole"
}
data "aws_iam_policy_document" "rds_enhanced_monitoring" {
statement {
actions = [
"sts:AssumeRole",
]
effect = "Allow"
principals {
type = "Service"
identifiers = ["monitoring.rds.amazonaws.com"]
}
}
}
#####
# DB
#####
module "db" {
source = "../../"
identifier = "demodb"
engine = "mysql"
engine_version = "5.7.11"
instance_class = "db.t2.large"
allocated_storage = 5
storage_encrypted = false
# kms_key_id = "arm:aws:kms:<region>:<accound id>:key/<kms key id>"
name = "demodb"
username = "user"
password = "YourPwdShouldBeLongAndSecure!"
port = "3306"
vpc_security_group_ids = ["${data.aws_security_group.default.id}"]
maintenance_window = "Mon:00:00-Mon:03:00"
backup_window = "03:00-06:00"
backup_retention_period = 0 // disable backups to create DB faster
tags = {
Owner = "user"
Environment = "dev"
}
# DB subnet group
subnet_ids = ["${data.aws_subnet_ids.all.ids}"]
# DB parameter group
family = "mysql5.7"
monitoring_interval = "30"
monitoring_role_arn = "${aws_iam_role.rds_enhanced_monitoring.arn}"
}
...@@ -39,6 +39,8 @@ module "db_instance" { ...@@ -39,6 +39,8 @@ module "db_instance" {
instance_class = "${var.instance_class}" instance_class = "${var.instance_class}"
allocated_storage = "${var.allocated_storage}" allocated_storage = "${var.allocated_storage}"
storage_type = "${var.storage_type}" storage_type = "${var.storage_type}"
storage_encrypted = "${var.storage_encrypted}"
kms_key_id = "${var.kms_key_id}"
name = "${var.name}" name = "${var.name}"
username = "${var.username}" username = "${var.username}"
...@@ -64,5 +66,8 @@ module "db_instance" { ...@@ -64,5 +66,8 @@ module "db_instance" {
backup_retention_period = "${var.backup_retention_period}" backup_retention_period = "${var.backup_retention_period}"
backup_window = "${var.backup_window}" backup_window = "${var.backup_window}"
monitoring_interval = "${var.monitoring_interval}"
monitoring_role_arn = "${var.monitoring_role_arn}"
tags = "${var.tags}" tags = "${var.tags}"
} }
...@@ -9,6 +9,8 @@ resource "aws_db_instance" "this" { ...@@ -9,6 +9,8 @@ resource "aws_db_instance" "this" {
instance_class = "${var.instance_class}" instance_class = "${var.instance_class}"
allocated_storage = "${var.allocated_storage}" allocated_storage = "${var.allocated_storage}"
storage_type = "${var.storage_type}" storage_type = "${var.storage_type}"
storage_encrypted = "${var.storage_encrypted}"
kms_key_id = "${var.kms_key_id}"
name = "${var.name}" name = "${var.name}"
username = "${var.username}" username = "${var.username}"
...@@ -23,6 +25,7 @@ resource "aws_db_instance" "this" { ...@@ -23,6 +25,7 @@ resource "aws_db_instance" "this" {
iops = "${var.iops}" iops = "${var.iops}"
publicly_accessible = "${var.publicly_accessible}" publicly_accessible = "${var.publicly_accessible}"
monitoring_interval = "${var.monitoring_interval}" monitoring_interval = "${var.monitoring_interval}"
monitoring_role_arn = "${var.monitoring_role_arn}"
allow_major_version_upgrade = "${var.allow_major_version_upgrade}" allow_major_version_upgrade = "${var.allow_major_version_upgrade}"
auto_minor_version_upgrade = "${var.auto_minor_version_upgrade}" auto_minor_version_upgrade = "${var.auto_minor_version_upgrade}"
......
...@@ -11,6 +11,16 @@ variable "storage_type" { ...@@ -11,6 +11,16 @@ variable "storage_type" {
default = "gp2" default = "gp2"
} }
variable "storage_encrypted" {
description = "Specifies whether the DB instance is encrypted"
default = false
}
variable "kms_key_id" {
description = "The ARN for the KMS encryption key. If creating an encrypted replica, set this to the destination KMS ARN. If storage_encrypted is set to true and kms_key_id is not specified the default KMS key created in your account will be used"
default = ""
}
variable "engine" { variable "engine" {
description = "The database engine to use" description = "The database engine to use"
} }
...@@ -78,6 +88,11 @@ variable "monitoring_interval" { ...@@ -78,6 +88,11 @@ variable "monitoring_interval" {
default = 0 default = 0
} }
variable "monitoring_role_arn" {
description = "The ARN for the IAM role that permits RDS to send enhanced monitoring metrics to CloudWatch Logs. Must be specified if monitoring_interval is non-zero."
default = ""
}
variable "allow_major_version_upgrade" { variable "allow_major_version_upgrade" {
description = "Indicates that major version upgrades are allowed. Changing this parameter does not result in an outage and the change is asynchronously applied as soon as possible" description = "Indicates that major version upgrades are allowed. Changing this parameter does not result in an outage and the change is asynchronously applied as soon as possible"
default = false default = false
......
...@@ -11,6 +11,16 @@ variable "storage_type" { ...@@ -11,6 +11,16 @@ variable "storage_type" {
default = "gp2" default = "gp2"
} }
variable "storage_encrypted" {
description = "Specifies whether the DB instance is encrypted"
default = false
}
variable "kms_key_id" {
description = "The ARN for the KMS encryption key. If creating an encrypted replica, set this to the destination KMS ARN. If storage_encrypted is set to true and kms_key_id is not specified the default KMS key created in your account will be used"
default = ""
}
variable "engine" { variable "engine" {
description = "The database engine to use" description = "The database engine to use"
} }
...@@ -73,6 +83,16 @@ variable "publicly_accessible" { ...@@ -73,6 +83,16 @@ variable "publicly_accessible" {
default = false default = false
} }
variable "monitoring_interval" {
description = "The interval, in seconds, between points when Enhanced Monitoring metrics are collected for the DB instance. To disable collecting Enhanced Monitoring metrics, specify 0. The default is 0. Valid Values: 0, 1, 5, 10, 15, 30, 60."
default = 0
}
variable "monitoring_role_arn" {
description = "The ARN for the IAM role that permits RDS to send enhanced monitoring metrics to CloudWatch Logs. Must be specified if monitoring_interval is non-zero."
default = ""
}
variable "allow_major_version_upgrade" { variable "allow_major_version_upgrade" {
description = "Indicates that major version upgrades are allowed. Changing this parameter does not result in an outage and the change is asynchronously applied as soon as possible" description = "Indicates that major version upgrades are allowed. Changing this parameter does not result in an outage and the change is asynchronously applied as soon as possible"
default = false default = false
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment