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

Add cluster and reader DNS names #3

Merged
merged 2 commits into from
Apr 15, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ We literally have [*hundreds of terraform modules*][terraform_modules] that are
## Usage


**IMPORTANT:** Do not pin to `master` because there may be breaking changes between releases. Instead pin to the release tag (e.g. `?ref=tags/x.y.z`) of one of our [latest releases](https://github.com/cloudposse/terraform-aws-documentdb-cluster/releases).
**IMPORTANT:** The `master` branch is used in `source` just as an example. In your code, do not pin to `master` because there may be breaking changes between releases.
Instead pin to the release tag (e.g. `?ref=tags/x.y.z`) of one of our [latest releases](https://github.com/cloudposse/terraform-aws-documentdb-cluster/releases).



For a complete example, see [examples/complete](examples/complete)

Expand All @@ -53,9 +56,9 @@ module "documentdb_cluster" {
namespace = "eg"
stage = "testing"
name = "docdb"
cluster_size = "2"
admin_user = "admin1"
admin_password = "Test123456789"
cluster_size = "3"
master_username = "admin1"
master_password = "Test123456789"
instance_class = "db.r4.large"
vpc_id = "vpc-xxxxxxxx"
subnet_ids = ["subnet-xxxxxxxx", "subnet-yyyyyyyy"]
Expand Down Expand Up @@ -87,9 +90,10 @@ Available targets:
| allowed_security_groups | List of existing Security Groups to be allowed to connect to the DocumentDB cluster | list | `<list>` | no |
| apply_immediately | Specifies whether any cluster modifications are applied immediately, or during the next maintenance window | string | `true` | no |
| attributes | Additional attributes (e.g. `1`) | list | `<list>` | no |
| cluster_dns_name | Name of the cluster CNAME record to create in the parent DNS zone specified by `zone_id`. If left empty, the name will be auto-asigned using the format `master.var.name` | string | `` | no |
| cluster_family | The family of the DocumentDB cluster parameter group. For more details, see https://docs.aws.amazon.com/documentdb/latest/developerguide/db-cluster-parameter-group-create.html | string | `docdb3.6` | no |
| cluster_parameters | List of DB parameters to apply | list | `<list>` | no |
| cluster_size | Number of DB instances to create in the cluster | string | `2` | no |
| cluster_size | Number of DB instances to create in the cluster | string | `3` | no |
| db_port | DocumentDB port | string | `27017` | no |
| delimiter | Delimiter to be used between `name`, `namespace`, `stage` and `attributes` | string | `-` | no |
| enabled | Set to false to prevent the module from creating any resources | string | `true` | no |
Expand All @@ -103,15 +107,16 @@ Available targets:
| name | Name of the application | string | - | yes |
| namespace | Namespace (e.g. `eg` or `cp`) | string | - | yes |
| preferred_backup_window | Daily time range during which the backups happen | string | `07:00-09:00` | no |
| reader_dns_name | Name of the reader endpoint CNAME record to create in the parent DNS zone specified by `zone_id`. If left empty, the name will be auto-asigned using the format `replicas.var.name` | string | `` | no |
| retention_period | Number of days to retain backups for | string | `5` | no |
| skip_final_snapshot | Determines whether a final DB snapshot is created before the DB cluster is deleted | string | `true` | no |
| snapshot_identifier | Specifies whether or not to create this cluster from a snapshot. You can use either the name or ARN when specifying a DB cluster snapshot, or the ARN when specifying a DB snapshot | string | `` | no |
| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | - | yes |
| storage_encrypted | Specifies whether the DB cluster is encrypted | string | `true` | no |
| subnet_ids | List of VPC subnet IDs | list | - | yes |
| subnet_ids | List of VPC subnet IDs to place DocumentDB instances | list | - | yes |
| tags | Additional tags (e.g. map(`BusinessUnit`,`XYZ`) | map | `<map>` | no |
| vpc_id | VPC ID to create the cluster in (e.g. `vpc-a22222ee`) | string | - | yes |
| zone_id | Route53 parent zone ID. If provided (not empty), the module will create sub-domain DNS records for the DB master and replicas | string | `` | no |
| zone_id | Route53 parent zone ID. If provided (not empty), the module will create sub-domain DNS records for the DocumentDB master and replicas | string | `` | no |

## Outputs

Expand Down
8 changes: 3 additions & 5 deletions README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ description: |-
# How to use this project
usage: |-

**IMPORTANT:** Do not pin to `master` because there may be breaking changes between releases. Instead pin to the release tag (e.g. `?ref=tags/x.y.z`) of one of our [latest releases](https://github.com/cloudposse/terraform-aws-documentdb-cluster/releases).

For a complete example, see [examples/complete](examples/complete)

```hcl
Expand All @@ -70,9 +68,9 @@ usage: |-
namespace = "eg"
stage = "testing"
name = "docdb"
cluster_size = "2"
admin_user = "admin1"
admin_password = "Test123456789"
cluster_size = "3"
master_username = "admin1"
master_password = "Test123456789"
instance_class = "db.r4.large"
vpc_id = "vpc-xxxxxxxx"
subnet_ids = ["subnet-xxxxxxxx", "subnet-yyyyyyyy"]
Expand Down
8 changes: 5 additions & 3 deletions docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
| allowed_security_groups | List of existing Security Groups to be allowed to connect to the DocumentDB cluster | list | `<list>` | no |
| apply_immediately | Specifies whether any cluster modifications are applied immediately, or during the next maintenance window | string | `true` | no |
| attributes | Additional attributes (e.g. `1`) | list | `<list>` | no |
| cluster_dns_name | Name of the cluster CNAME record to create in the parent DNS zone specified by `zone_id`. If left empty, the name will be auto-asigned using the format `master.var.name` | string | `` | no |
| cluster_family | The family of the DocumentDB cluster parameter group. For more details, see https://docs.aws.amazon.com/documentdb/latest/developerguide/db-cluster-parameter-group-create.html | string | `docdb3.6` | no |
| cluster_parameters | List of DB parameters to apply | list | `<list>` | no |
| cluster_size | Number of DB instances to create in the cluster | string | `2` | no |
| cluster_size | Number of DB instances to create in the cluster | string | `3` | no |
| db_port | DocumentDB port | string | `27017` | no |
| delimiter | Delimiter to be used between `name`, `namespace`, `stage` and `attributes` | string | `-` | no |
| enabled | Set to false to prevent the module from creating any resources | string | `true` | no |
Expand All @@ -22,15 +23,16 @@
| name | Name of the application | string | - | yes |
| namespace | Namespace (e.g. `eg` or `cp`) | string | - | yes |
| preferred_backup_window | Daily time range during which the backups happen | string | `07:00-09:00` | no |
| reader_dns_name | Name of the reader endpoint CNAME record to create in the parent DNS zone specified by `zone_id`. If left empty, the name will be auto-asigned using the format `replicas.var.name` | string | `` | no |
| retention_period | Number of days to retain backups for | string | `5` | no |
| skip_final_snapshot | Determines whether a final DB snapshot is created before the DB cluster is deleted | string | `true` | no |
| snapshot_identifier | Specifies whether or not to create this cluster from a snapshot. You can use either the name or ARN when specifying a DB cluster snapshot, or the ARN when specifying a DB snapshot | string | `` | no |
| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | - | yes |
| storage_encrypted | Specifies whether the DB cluster is encrypted | string | `true` | no |
| subnet_ids | List of VPC subnet IDs | list | - | yes |
| subnet_ids | List of VPC subnet IDs to place DocumentDB instances | list | - | yes |
| tags | Additional tags (e.g. map(`BusinessUnit`,`XYZ`) | map | `<map>` | no |
| vpc_id | VPC ID to create the cluster in (e.g. `vpc-a22222ee`) | string | - | yes |
| zone_id | Route53 parent zone ID. If provided (not empty), the module will create sub-domain DNS records for the DB master and replicas | string | `` | no |
| zone_id | Route53 parent zone ID. If provided (not empty), the module will create sub-domain DNS records for the DocumentDB master and replicas | string | `` | no |

## Outputs

Expand Down
11 changes: 9 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,18 @@ resource "aws_docdb_cluster_parameter_group" "default" {
tags = "${module.label.tags}"
}

locals {
cluster_dns_name_default = "master.${var.name}"
cluster_dns_name = "${var.cluster_dns_name != "" ? var.cluster_dns_name : local.cluster_dns_name_default}"
reader_dns_name_default = "replicas.${var.name}"
reader_dns_name = "${var.reader_dns_name != "" ? var.reader_dns_name : local.reader_dns_name_default}"
}

module "dns_master" {
source = "git::https://github.com/cloudposse/terraform-aws-route53-cluster-hostname.git?ref=tags/0.2.6"
enabled = "${var.enabled == "true" && length(var.zone_id) > 0 ? "true" : "false"}"
namespace = "${var.namespace}"
name = "master.${var.name}"
name = "${local.cluster_dns_name}"
stage = "${var.stage}"
zone_id = "${var.zone_id}"
records = ["${coalescelist(aws_docdb_cluster.default.*.endpoint, list(""))}"]
Expand All @@ -114,7 +121,7 @@ module "dns_replicas" {
source = "git::https://github.com/cloudposse/terraform-aws-route53-cluster-hostname.git?ref=tags/0.2.6"
enabled = "${var.enabled == "true" && length(var.zone_id) > 0 ? "true" : "false"}"
namespace = "${var.namespace}"
name = "replicas.${var.name}"
name = "${local.reader_dns_name}"
stage = "${var.stage}"
zone_id = "${var.zone_id}"
records = ["${coalescelist(aws_docdb_cluster.default.*.reader_endpoint, list(""))}"]
Expand Down
18 changes: 15 additions & 3 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ variable "tags" {
variable "zone_id" {
type = "string"
default = ""
description = "Route53 parent zone ID. If provided (not empty), the module will create sub-domain DNS records for the DB master and replicas"
description = "Route53 parent zone ID. If provided (not empty), the module will create sub-domain DNS records for the DocumentDB master and replicas"
}

variable "allowed_security_groups" {
Expand All @@ -61,7 +61,7 @@ variable "vpc_id" {

variable "subnet_ids" {
type = "list"
description = "List of VPC subnet IDs"
description = "List of VPC subnet IDs to place DocumentDB instances"
}

variable "instance_class" {
Expand All @@ -72,7 +72,7 @@ variable "instance_class" {

variable "cluster_size" {
type = "string"
default = "2"
default = "3"
description = "Number of DB instances to create in the cluster"
}

Expand Down Expand Up @@ -165,3 +165,15 @@ variable "enabled_cloudwatch_logs_exports" {
description = "List of log types to export to cloudwatch. The following log types are supported: audit, error, general, slowquery."
default = []
}

variable "cluster_dns_name" {
type = "string"
description = "Name of the cluster CNAME record to create in the parent DNS zone specified by `zone_id`. If left empty, the name will be auto-asigned using the format `master.var.name`"
default = ""
}

variable "reader_dns_name" {
type = "string"
description = "Name of the reader endpoint CNAME record to create in the parent DNS zone specified by `zone_id`. If left empty, the name will be auto-asigned using the format `replicas.var.name`"
default = ""
}