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

MSSQL: Adding two missing arguments for aws_db_instance: timezone & character_set_name #51

Merged
merged 7 commits into from
Apr 3, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Examples
* [Complete RDS example for MySQL](https://github.com/terraform-aws-modules/terraform-aws-rds/tree/master/examples/complete-mysql)
* [Complete RDS example for PostgreSQL](https://github.com/terraform-aws-modules/terraform-aws-rds/tree/master/examples/complete-postgres)
* [Complete RDS example for Oracle](https://github.com/terraform-aws-modules/terraform-aws-rds/tree/master/examples/complete-oracle)
* [Complete RDS example for MSSQL](https://github.com/terraform-aws-modules/terraform-aws-rds/tree/master/examples/complete-mssql)
* [Enhanced monitoring example](https://github.com/terraform-aws-modules/terraform-aws-rds/tree/master/examples/enhanced-monitoring)

Notes
Expand Down
19 changes: 19 additions & 0 deletions examples/complete-mssql/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Complete RDS example for MSSQL Server
===================================

Configuration in this directory creates set of RDS resources including DB instance, DB subnet group and DB parameter group.

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.
60 changes: 60 additions & 0 deletions examples/complete-mssql/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
provider "aws" {
region = "us-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"
}

#####
# DB
#####
module "db" {
source = "../../"

identifier = "demodb"

engine = "sqlserver-se"
engine_version = "14.00.1000.169.v1"
instance_class = "db.t2.large"
allocated_storage = 5
storage_encrypted = false

username = "demouser"

password = "YourPwdShouldBeLongAndSecure!"
port = "1433"

vpc_security_group_ids = ["${data.aws_security_group.default.id}"]

maintenance_window = "Mon:00:00-Mon:03:00"
backup_window = "03:00-06:00"

# disable backups to create DB faster
backup_retention_period = 0

tags = {
Owner = "user"
Environment = "dev"
}

# DB subnet group
subnet_ids = ["${data.aws_subnet_ids.all.ids}"]

# Snapshot name upon DB deletion
final_snapshot_identifier = "demodb"

timezone = "Central Standard Time"
}
82 changes: 82 additions & 0 deletions examples/complete-mssql/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# DB instance
output "this_db_instance_address" {
description = "The address of the RDS instance"
value = "${module.db.this_db_instance_address}"
}

output "this_db_instance_arn" {
description = "The ARN of the RDS instance"
value = "${module.db.this_db_instance_arn}"
}

output "this_db_instance_availability_zone" {
description = "The availability zone of the RDS instance"
value = "${module.db.this_db_instance_availability_zone}"
}

output "this_db_instance_endpoint" {
description = "The connection endpoint"
value = "${module.db.this_db_instance_endpoint}"
}

output "this_db_instance_hosted_zone_id" {
description = "The canonical hosted zone ID of the DB instance (to be used in a Route 53 Alias record)"
value = "${module.db.this_db_instance_hosted_zone_id}"
}

output "this_db_instance_id" {
description = "The RDS instance ID"
value = "${module.db.this_db_instance_id}"
}

output "this_db_instance_resource_id" {
description = "The RDS Resource ID of this instance"
value = "${module.db.this_db_instance_resource_id}"
}

output "this_db_instance_status" {
description = "The RDS instance status"
value = "${module.db.this_db_instance_status}"
}

output "this_db_instance_name" {
description = "The database name"
value = "${module.db.this_db_instance_name}"
}

output "this_db_instance_username" {
description = "The master username for the database"
value = "${module.db.this_db_instance_username}"
}

output "this_db_instance_password" {
description = "The database password (this password may be old, because Terraform doesn't track it after initial creation)"
value = "${module.db.this_db_instance_password}"
}

output "this_db_instance_port" {
description = "The database port"
value = "${module.db.this_db_instance_port}"
}

# DB subnet group
output "this_db_subnet_group_id" {
description = "The db subnet group name"
value = "${module.db.this_db_subnet_group_id}"
}

output "this_db_subnet_group_arn" {
description = "The ARN of the db subnet group"
value = "${module.db.this_db_subnet_group_arn}"
}

# DB parameter group
output "this_db_parameter_group_id" {
description = "The db parameter group id"
value = "${module.db.this_db_parameter_group_id}"
}

output "this_db_parameter_group_arn" {
description = "The ARN of the db parameter group"
value = "${module.db.this_db_parameter_group_arn}"
}
3 changes: 3 additions & 0 deletions examples/complete-oracle/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,7 @@ module "db" {

# Snapshot name upon DB deletion
final_snapshot_identifier = "demodb"

# See here for support character sets https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Appendix.OracleCharacterSets.html
character_set_name = "AL32UTF8"
}
3 changes: 3 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,7 @@ module "db_instance" {
create_monitoring_role = "${var.create_monitoring_role}"

tags = "${var.tags}"
Copy link
Member

Choose a reason for hiding this comment

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

Keep tags as a last line.


timezone = "${var.timezone}"
character_set_name = "${var.character_set_name}"
}
3 changes: 3 additions & 0 deletions modules/db_instance/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,7 @@ resource "aws_db_instance" "this" {
backup_window = "${var.backup_window}"

tags = "${merge(var.tags, map("Name", format("%s", var.identifier)))}"

timezone = "${var.timezone}"
character_set_name = "${var.character_set_name}"
Copy link
Member

Choose a reason for hiding this comment

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

Isn't character_set_name also supported in mssql?

Copy link
Contributor Author

@aloisbarreras aloisbarreras Mar 22, 2018

Choose a reason for hiding this comment

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

@antonbabenko actually looking at the docs, character_set_name only applies to Oracle instances. I'll go ahead and remove this line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well never mind actually. It doesn't break deploying like timezone does, so it seems safe to leave it in.

}
10 changes: 10 additions & 0 deletions modules/db_instance/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,13 @@ variable "tags" {
description = "A mapping of tags to assign to all resources"
default = {}
}

variable "timezone" {
description = "(Optional) Time zone of the DB instance. timezone is currently only supported by Microsoft SQL Server. The timezone can only be set on creation. See MSSQL User Guide for more information."
default = ""
}

variable "character_set_name" {
description = "(Optional) The character set name to use for DB encoding in Oracle instances. This can't be changed. See Oracle Character Sets Supported in Amazon RDS for more information."
default = ""
}
10 changes: 10 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,13 @@ variable "create_db_instance" {
description = "Whether to create a database instance"
default = true
}

variable "timezone" {
description = "(Optional) Time zone of the DB instance. timezone is currently only supported by Microsoft SQL Server. The timezone can only be set on creation. See MSSQL User Guide for more information."
default = ""
}

variable "character_set_name" {
description = "(Optional) The character set name to use for DB encoding in Oracle instances. This can't be changed. See Oracle Character Sets Supported in Amazon RDS for more information."
default = ""
}