Skip to content

Commit

Permalink
Merge pull request #22 from ministryofjustice/bugfix/providers-outsid…
Browse files Browse the repository at this point in the history
…e-module

split main and rds example, took providers out of module
  • Loading branch information
mtrbls authored May 2, 2019
2 parents d179712 + 9cb585d commit eeac8b2
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 64 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ module "example_team_rds" {
is-production = "false"
environment-name = "development"
infrastructure-support = "[email protected]"
aws_region = "eu-west-2"
providers = {
# This can be either "aws.london" or "aws.ireland:
aws = "aws.london"
}
}
```
Expand All @@ -49,8 +53,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

| providers | provider (and region) creating the resources | arrays of string | default provider | no
|

### Tags

Expand Down
55 changes: 7 additions & 48 deletions example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,15 @@ terraform {
}

provider "aws" {
region = "eu-west-1"
region = "eu-west-2"
}

/*
* When using this module through the cloud-platform-environments, the following
* two variables are automatically supplied by the pipeline.
*
*/

variable "cluster_name" {}

variable "cluster_state_bucket" {}

/*
* Make sure that you use the latest version of the module by changing the
* `ref=` value in the `source` attribute to the latest version listed on the
* releases page of this repository.
*
*/
module "example_team_rds" {
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"
business-unit = "example-bu"
application = "exampleapp"
is-production = "false"
environment-name = "development"
infrastructure-support = "[email protected]"
aws_region = "eu-west-2"
provider "aws" {
alias = "london"
region = "eu-west-2"
}

resource "kubernetes_secret" "example_team_rds" {
metadata {
name = "example-team-rds-instance-output"
namespace = "my-namespace"
}

data {
rds_instance_endpoint = "${module.example_team_rds.rds_instance_endpoint}"
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}"

/* You can replace all of the above with the following, if you prefer to
* use a single database URL value in your application code:
*
* url = "postgres://${module.example_team_rds.database_username}:${module.example_team_rds.database_password}@${module.example_team_rds.rds_instance_endpoint}/${module.example_team_rds.database_name}"
*
*/
}
provider "aws" {
alias = "ireland"
region = "eu-west-1"
}
57 changes: 57 additions & 0 deletions example/rds.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* When using this module through the cloud-platform-environments, the following
* two variables are automatically supplied by the pipeline.
*
*/

variable "cluster_name" {}

variable "cluster_state_bucket" {}

/*
* Make sure that you use the latest version of the module by changing the
* `ref=` value in the `source` attribute to the latest version listed on the
* releases page of this repository.
*
*/
module "example_team_rds" {
source = "github.com/ministryofjustice/cloud-platform-terraform-rds-instance?ref=4.2"
cluster_name = "${var.cluster_name}"
cluster_state_bucket = "${var.cluster_state_bucket}"
team_name = "example-repo"
business-unit = "example-bu"
application = "exampleapp"
is-production = "false"
environment-name = "development"
infrastructure-support = "[email protected]"

# Deprecated from the version 4.2 of this module
#aws_region = "eu-west-2"

providers = {
# Can be either "aws.london" or "aws.london"
aws = "aws.london"
}
}

resource "kubernetes_secret" "example_team_rds" {
metadata {
name = "example-team-rds-instance-output"
namespace = "my-namespace"
}

data {
rds_instance_endpoint = "${module.example_team_rds.rds_instance_endpoint}"
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}"

/* You can replace all of the above with the following, if you prefer to
* use a single database URL value in your application code:
*
* url = "postgres://${module.example_team_rds.database_username}:${module.example_team_rds.database_password}@${module.example_team_rds.rds_instance_endpoint}/${module.example_team_rds.database_name}"
*
*/
}
}
12 changes: 0 additions & 12 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
data "aws_caller_identity" "current" {}
data "aws_region" "current" {}

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

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

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

tags {
Expand All @@ -49,14 +44,11 @@ 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 @@ -71,8 +63,6 @@ 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 @@ -97,8 +87,6 @@ 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
3 changes: 2 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ variable "db_name" {
default = ""
}

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

0 comments on commit eeac8b2

Please sign in to comment.