From 01b4edfe0aaef73fe9688038877dfad903311f6b Mon Sep 17 00:00:00 2001 From: Mourad T Date: Mon, 25 Mar 2019 15:27:28 +0000 Subject: [PATCH 1/4] add aws_region variable, and edit terraform live-1 state access --- README.md | 6 ++++++ example/main.tf | 10 +++++----- main.tf | 14 +++++++++++++- variables.tf | 7 +++++++ 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0d60a13..1751bb6 100644 --- a/README.md +++ b/README.md @@ -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 @@ -26,6 +29,7 @@ module "example_team_rds" { is-production = "false" environment-name = "development" infrastructure-support = "example-team@digtal.justice.gov.uk" + aws_region = "eu-west-2" } ``` @@ -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 diff --git a/example/main.tf b/example/main.tf index a7612a5..4904068 100644 --- a/example/main.tf +++ b/example/main.tf @@ -23,16 +23,16 @@ variable "cluster_state_bucket" {} * */ module "example_team_rds" { - source = "github.com/ministryofjustice/cloud-platform-terraform-rds-instance?ref=3.1" - - cluster_name = "${var.cluster_name}" - cluster_state_bucket = "${var.cluster_state_bucket}" + source = "github.com/ministryofjustice/cloud-platform-terraform-rds-instance?ref=4.0" + cluster_name = "live-1" + cluster_state_bucket = "cloud-platform-terraform-state" 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" } resource "kubernetes_secret" "example_team_rds" { @@ -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}" } } diff --git a/main.tf b/main.tf index 5443bcd..612b8ea 100644 --- a/main.tf +++ b/main.tf @@ -1,13 +1,17 @@ data "aws_caller_identity" "current" {} data "aws_region" "current" {} +provider "aws" { + alias = "destination" + 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" } } @@ -31,6 +35,7 @@ resource "random_string" "password" { } resource "aws_kms_key" "kms" { + provider = "aws.destination" description = "${local.identifier}" tags { @@ -44,11 +49,14 @@ resource "aws_kms_key" "kms" { } resource "aws_kms_alias" "alias" { + provider = "aws.destination" name = "alias/${local.identifier}" target_key_id = "${aws_kms_key.kms.key_id}" } resource "aws_db_subnet_group" "db_subnet" { + provider = "aws.destination" + name = "${local.identifier}" subnet_ids = ["${data.terraform_remote_state.cluster.internal_subnets_ids}"] @@ -63,6 +71,8 @@ resource "aws_db_subnet_group" "db_subnet" { } resource "aws_security_group" "rds-sg" { + provider = "aws.destination" + name = "${local.identifier}" description = "Allow all inbound traffic" vpc_id = "${data.terraform_remote_state.cluster.vpc_id}" @@ -87,6 +97,8 @@ resource "aws_security_group" "rds-sg" { } resource "aws_db_instance" "rds" { + provider = "aws.destination" + identifier = "${local.identifier}" final_snapshot_identifier = "${local.identifier}-finalsnapshot" allocated_storage = "${var.db_allocated_storage}" diff --git a/variables.tf b/variables.tf index 4e8de35..2d9d5b9 100644 --- a/variables.tf +++ b/variables.tf @@ -1,9 +1,11 @@ variable "cluster_name" { description = "The name of the cluster (eg.: cloud-platform-live-0)" + default = "live-1" } variable "cluster_state_bucket" { description = "The name of the S3 bucket holding the terraform state for the cluster" + default = "cloud-platform-terraform-state" } variable "team_name" {} @@ -64,3 +66,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" +} \ No newline at end of file From b98b962cc16d9f8744232d23d0b026f32f62fea8 Mon Sep 17 00:00:00 2001 From: Mourad T Date: Mon, 25 Mar 2019 15:41:10 +0000 Subject: [PATCH 2/4] use 'example' --- example/main.tf | 4 ++-- variables.tf | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/example/main.tf b/example/main.tf index 4904068..7d15713 100644 --- a/example/main.tf +++ b/example/main.tf @@ -24,8 +24,8 @@ variable "cluster_state_bucket" {} */ module "example_team_rds" { source = "github.com/ministryofjustice/cloud-platform-terraform-rds-instance?ref=4.0" - cluster_name = "live-1" - cluster_state_bucket = "cloud-platform-terraform-state" + cluster_name = "example-cluster-0" + cluster_state_bucket = "example-state" team_name = "example-repo" business-unit = "example-bu" application = "exampleapp" diff --git a/variables.tf b/variables.tf index 2d9d5b9..beacea2 100644 --- a/variables.tf +++ b/variables.tf @@ -1,11 +1,9 @@ variable "cluster_name" { description = "The name of the cluster (eg.: cloud-platform-live-0)" - default = "live-1" } variable "cluster_state_bucket" { description = "The name of the S3 bucket holding the terraform state for the cluster" - default = "cloud-platform-terraform-state" } variable "team_name" {} From 5bc154e348d737cc014fb2c98a7c575fe70a3f5d Mon Sep 17 00:00:00 2001 From: Mourad T Date: Mon, 25 Mar 2019 15:42:21 +0000 Subject: [PATCH 3/4] add variable for pipeline --- example/main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/main.tf b/example/main.tf index 7d15713..c47b7e8 100644 --- a/example/main.tf +++ b/example/main.tf @@ -24,8 +24,8 @@ variable "cluster_state_bucket" {} */ module "example_team_rds" { source = "github.com/ministryofjustice/cloud-platform-terraform-rds-instance?ref=4.0" - cluster_name = "example-cluster-0" - cluster_state_bucket = "example-state" + cluster_name = "${var.cluster_name}" + cluster_state_bucket = "${var.cluster_state_bucket}" team_name = "example-repo" business-unit = "example-bu" application = "exampleapp" From 278124b6ca026a9ed276cc39597c96df4709b2b1 Mon Sep 17 00:00:00 2001 From: Mourad T Date: Mon, 25 Mar 2019 15:50:54 +0000 Subject: [PATCH 4/4] renamed aws provider from destiation to london --- main.tf | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/main.tf b/main.tf index 612b8ea..ab00547 100644 --- a/main.tf +++ b/main.tf @@ -2,7 +2,7 @@ data "aws_caller_identity" "current" {} data "aws_region" "current" {} provider "aws" { - alias = "destination" + alias = "london" region = "eu-west-2" } data "terraform_remote_state" "cluster" { @@ -35,7 +35,7 @@ resource "random_string" "password" { } resource "aws_kms_key" "kms" { - provider = "aws.destination" + provider = "aws.london" description = "${local.identifier}" tags { @@ -49,13 +49,13 @@ resource "aws_kms_key" "kms" { } resource "aws_kms_alias" "alias" { - provider = "aws.destination" + 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.destination" + provider = "aws.london" name = "${local.identifier}" subnet_ids = ["${data.terraform_remote_state.cluster.internal_subnets_ids}"] @@ -71,7 +71,7 @@ resource "aws_db_subnet_group" "db_subnet" { } resource "aws_security_group" "rds-sg" { - provider = "aws.destination" + provider = "aws.london" name = "${local.identifier}" description = "Allow all inbound traffic" @@ -97,7 +97,7 @@ resource "aws_security_group" "rds-sg" { } resource "aws_db_instance" "rds" { - provider = "aws.destination" + provider = "aws.london" identifier = "${local.identifier}" final_snapshot_identifier = "${local.identifier}-finalsnapshot"