Skip to content

Commit

Permalink
Merge pull request #17 from ministryofjustice/feature/default-region-…
Browse files Browse the repository at this point in the history
…eu-west-2

Feature/default region eu west 2
  • Loading branch information
mtrbls authored Mar 25, 2019
2 parents da63b58 + 278124b commit 7562472
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ The module also deploys the instance in Multi-AZ.

The outputs of this module should allow a user to connect to the database instance.


**IMPORTANT NOTE: The latest module (4.0) does not support Live-0 deployment. Be sure to use the previous one (3.1) is you need to deploy to Live-0.**

## Usage

```hcl
Expand All @@ -26,6 +29,7 @@ module "example_team_rds" {
is-production = "false"
environment-name = "development"
infrastructure-support = "[email protected]"
aws_region = "eu-west-2"
}
```
Expand All @@ -45,6 +49,8 @@ module "example_team_rds" {
| snapshot_identifier | Specifies whether or not to create this database from a snapshot. This correlates to the snapshot ID you'd find in the RDS console. | string | | no |
| cluster_name | The name of the cluster (eg.: cloud-platform-live-0) | string | - | yes |
| cluster_state_bucket | The name of the S3 bucket holding the terraform state for the cluster | string | - | yes |
| aws_region | region into which the resource will be created | string | eu-west-2 | no


### Tags

Expand Down
6 changes: 3 additions & 3 deletions example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ variable "cluster_state_bucket" {}
*
*/
module "example_team_rds" {
source = "github.com/ministryofjustice/cloud-platform-terraform-rds-instance?ref=3.1"

source = "github.com/ministryofjustice/cloud-platform-terraform-rds-instance?ref=4.0"
cluster_name = "${var.cluster_name}"
cluster_state_bucket = "${var.cluster_state_bucket}"
team_name = "example-repo"
Expand All @@ -33,6 +32,7 @@ module "example_team_rds" {
is-production = "false"
environment-name = "development"
infrastructure-support = "[email protected]"
aws_region = "eu-west-2"
}

resource "kubernetes_secret" "example_team_rds" {
Expand All @@ -46,6 +46,6 @@ resource "kubernetes_secret" "example_team_rds" {
database_name = "${module.example_team_rds.database_name}"
database_username = "${module.example_team_rds.database_username}"
database_password = "${module.example_team_rds.database_password}"
rds_instance_address = "${module.example_team_rds.rds_instance_address}"
rds_instance_address = "${module.example_team_rds.rds_instance_address}"
}
}
14 changes: 13 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
data "aws_caller_identity" "current" {}
data "aws_region" "current" {}

provider "aws" {
alias = "london"
region = "eu-west-2"
}
data "terraform_remote_state" "cluster" {
backend = "s3"

config {
bucket = "${var.cluster_state_bucket}"
region = "eu-west-1"
key = "env:/${var.cluster_name}/terraform.tfstate"
key = "cloud-platform/${var.cluster_name}/terraform.tfstate"
}
}

Expand All @@ -31,6 +35,7 @@ resource "random_string" "password" {
}

resource "aws_kms_key" "kms" {
provider = "aws.london"
description = "${local.identifier}"

tags {
Expand All @@ -44,11 +49,14 @@ resource "aws_kms_key" "kms" {
}

resource "aws_kms_alias" "alias" {
provider = "aws.london"
name = "alias/${local.identifier}"
target_key_id = "${aws_kms_key.kms.key_id}"
}

resource "aws_db_subnet_group" "db_subnet" {
provider = "aws.london"

name = "${local.identifier}"
subnet_ids = ["${data.terraform_remote_state.cluster.internal_subnets_ids}"]

Expand All @@ -63,6 +71,8 @@ resource "aws_db_subnet_group" "db_subnet" {
}

resource "aws_security_group" "rds-sg" {
provider = "aws.london"

name = "${local.identifier}"
description = "Allow all inbound traffic"
vpc_id = "${data.terraform_remote_state.cluster.vpc_id}"
Expand All @@ -87,6 +97,8 @@ resource "aws_security_group" "rds-sg" {
}

resource "aws_db_instance" "rds" {
provider = "aws.london"

identifier = "${local.identifier}"
final_snapshot_identifier = "${local.identifier}-finalsnapshot"
allocated_storage = "${var.db_allocated_storage}"
Expand Down
5 changes: 5 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,8 @@ variable "db_name" {
description = "The name of the database to be created on the instance (if empty, it will be the generated random identifier)"
default = ""
}

variable "aws_region" {
description = "Region into which the resource will be created."
default = "eu-west-2"
}

0 comments on commit 7562472

Please sign in to comment.