From 9cb585d3d96319620be081e7649d69d491017fcb Mon Sep 17 00:00:00 2001 From: Mourad T Date: Thu, 2 May 2019 10:44:30 +0100 Subject: [PATCH] split main and rds example, took providers out of module --- README.md | 10 ++++++--- example/main.tf | 55 ++++++----------------------------------------- example/rds.tf | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ main.tf | 12 ----------- variables.tf | 3 ++- 5 files changed, 73 insertions(+), 64 deletions(-) create mode 100644 example/rds.tf diff --git a/README.md b/README.md index f0c163b..39c4f13 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,11 @@ module "example_team_rds" { is-production = "false" environment-name = "development" infrastructure-support = "example-team@digtal.justice.gov.uk" - aws_region = "eu-west-2" + + providers = { + # This can be either "aws.london" or "aws.ireland: + aws = "aws.london" + } } ``` @@ -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 diff --git a/example/main.tf b/example/main.tf index e4e45a9..e4a3040 100644 --- a/example/main.tf +++ b/example/main.tf @@ -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 = "example-team@digtal.justice.gov.uk" - 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" } diff --git a/example/rds.tf b/example/rds.tf new file mode 100644 index 0000000..d73e238 --- /dev/null +++ b/example/rds.tf @@ -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 = "example-team@digtal.justice.gov.uk" + + # 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}" + * + */ + } +} diff --git a/main.tf b/main.tf index 77df1c4..74f0349 100644 --- a/main.tf +++ b/main.tf @@ -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" @@ -35,7 +31,6 @@ resource "random_string" "password" { } resource "aws_kms_key" "kms" { - provider = "aws.london" description = "${local.identifier}" tags { @@ -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}"] @@ -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}" @@ -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}" diff --git a/variables.tf b/variables.tf index beacea2..88c7a19 100644 --- a/variables.tf +++ b/variables.tf @@ -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" -} \ No newline at end of file +}