Skip to content

Commit 950d036

Browse files
committed
[NRL-1386] Add var to enable/disable all reporting services per env and account-wide
1 parent b25f569 commit 950d036

File tree

28 files changed

+123
-43
lines changed

28 files changed

+123
-43
lines changed

terraform/account-wide-infrastructure/dev/athena.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module "dev-athena" {
2+
count = var.enable_reporting ? 1 : 0
23
source = "../modules/athena"
34
name_prefix = "nhsd-nrlf--dev"
45
target_bucket_name = module.dev-glue.target_bucket_name

terraform/account-wide-infrastructure/dev/ec2.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module "vpc" {
2-
count = var.enable_powerbi_auto_push ? 1 : 0
2+
count = var.enable_reporting && var.enable_powerbi_auto_push ? 1 : 0
33
source = "../modules/vpc"
44
vpc_cidr_block = var.vpc_cidr_block
55
enable_dns_hostnames = var.enable_dns_hostnames
@@ -10,15 +10,15 @@ module "vpc" {
1010
}
1111

1212
module "powerbi_gw_instance" {
13-
count = var.enable_powerbi_auto_push ? 1 : 0
13+
count = var.enable_reporting && var.enable_powerbi_auto_push ? 1 : 0
1414
source = "../modules/powerbi-gw-ec2"
1515
use_custom_ami = var.use_powerbi_gw_custom_ami
1616
instance_type = var.powerbi_gw_instance_type
1717
name_prefix = "nhsd-nrlf--dev-powerbi-gw"
1818
target_bucket_arn = module.dev-glue.target_bucket_arn
1919
glue_kms_key_arn = module.dev-glue.aws_kms_key_arn
20-
athena_kms_key_arn = module.dev-athena.kms_key_arn
21-
athena_bucket_arn = module.dev-athena.bucket_arn
20+
athena_kms_key_arn = module.dev-athena[0].kms_key_arn
21+
athena_bucket_arn = module.dev-athena[0].bucket_arn
2222

2323
subnet_id = module.vpc[0].private_subnet_id
2424
security_groups = [module.vpc[0].powerbi_gw_security_group_id]

terraform/account-wide-infrastructure/dev/glue.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module "dev-glue" {
2+
is_enabled = var.enable_reporting
23
source = "../modules/glue"
34
name_prefix = "nhsd-nrlf--dev"
45
python_version = 3

terraform/account-wide-infrastructure/dev/vars.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ variable "devsandbox_api_domain_name" {
1414
default = "dev-sandbox.api.record-locator.dev.national.nhs.uk"
1515
}
1616

17+
variable "enable_reporting" {
18+
type = bool
19+
description = "Enable account-wide reporting services in the dev account"
20+
default = false
21+
}
22+
1723
variable "aws_azs" {
1824
type = string
1925
description = "AWS Availability Zones"

terraform/account-wide-infrastructure/modules/glue/glue.tf

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
# Create Glue Data Catalog Database
22
resource "aws_glue_catalog_database" "log_database" {
3+
count = var.is_enabled ? 1 : 0
4+
35
name = "${var.name_prefix}-reporting"
46
location_uri = "${aws_s3_bucket.target-data-bucket.id}/"
57
}
68

79
# Create Glue Crawler
810
resource "aws_glue_crawler" "log_crawler" {
11+
count = var.is_enabled ? 1 : 0
12+
913
name = "${var.name_prefix}-log-crawler"
10-
database_name = aws_glue_catalog_database.log_database.name
14+
database_name = aws_glue_catalog_database.log_database[0].name
1115
role = aws_iam_role.glue_service_role.name
1216
s3_target {
1317
path = "s3://${aws_s3_bucket.target-data-bucket.id}/consumer_countDocumentReference/"
@@ -53,14 +57,18 @@ resource "aws_glue_crawler" "log_crawler" {
5357
})
5458
}
5559
resource "aws_glue_trigger" "log_trigger" {
60+
count = var.is_enabled ? 1 : 0
61+
5662
name = "${var.name_prefix}-org-report-trigger"
5763
type = "ON_DEMAND"
5864
actions {
59-
crawler_name = aws_glue_crawler.log_crawler.name
65+
crawler_name = aws_glue_crawler.log_crawler[0].name
6066
}
6167
}
6268

6369
resource "aws_glue_job" "glue_job" {
70+
count = var.is_enabled ? 1 : 0
71+
6472
name = "${var.name_prefix}-glue-job"
6573
role_arn = aws_iam_role.glue_service_role.arn
6674
description = "Transfer logs from source to bucket"

terraform/account-wide-infrastructure/modules/glue/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ output "glue_crawler_name" {
2323
}
2424

2525
output "glue_database" {
26-
value = aws_glue_catalog_database.log_database.name
26+
value = var.is_enabled ? aws_glue_catalog_database.log_database[0].name : ""
2727
}

terraform/account-wide-infrastructure/modules/glue/s3.tf

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,13 @@ resource "aws_s3_bucket_lifecycle_configuration" "source-data-bucket-lifecycle"
6262
expiration {
6363
days = local.s3.expiration.days
6464
}
65-
66-
noncurrent_version_expiration {
67-
noncurrent_days = local.s3.expiration.days
68-
}
6965
}
7066
}
7167

7268
resource "aws_s3_bucket_versioning" "source-data-bucket-versioning" {
7369
bucket = aws_s3_bucket.source-data-bucket.id
7470
versioning_configuration {
75-
status = "Enabled"
71+
status = "Disabled"
7672
}
7773
}
7874

terraform/account-wide-infrastructure/modules/glue/vars.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,9 @@ variable "code_bucket" {
2222
description = "S3 bucket for Glue job scripts"
2323
default = "code-bucket"
2424
}
25+
26+
variable "is_enabled" {
27+
type = bool
28+
description = "Flag to enable or disable the Glue module"
29+
default = true
30+
}

terraform/account-wide-infrastructure/prod/athena.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module "prod-athena" {
2+
count = var.enable_reporting ? 1 : 0
23
source = "../modules/athena"
34
name_prefix = "nhsd-nrlf--prod"
45
target_bucket_name = module.prod-glue.target_bucket_name

terraform/account-wide-infrastructure/prod/ec2.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module "vpc" {
2-
count = var.enable_powerbi_auto_push ? 1 : 0
2+
count = var.enable_reporting && var.enable_powerbi_auto_push ? 1 : 0
33
source = "../modules/vpc"
44
vpc_cidr_block = var.vpc_cidr_block
55
enable_dns_hostnames = var.enable_dns_hostnames
@@ -10,15 +10,15 @@ module "vpc" {
1010
}
1111

1212
module "powerbi_gw_instance" {
13-
count = var.enable_powerbi_auto_push ? 1 : 0
13+
count = var.enable_reporting && var.enable_powerbi_auto_push ? 1 : 0
1414
source = "../modules/powerbi-gw-ec2"
1515
use_custom_ami = false
1616
instance_type = var.powerbi_gw_instance_type
1717
name_prefix = "nhsd-nrlf--test-powerbi-gw"
1818
target_bucket_arn = module.prod-glue.target_bucket_arn
1919
glue_kms_key_arn = module.prod-glue.aws_kms_key_arn
20-
athena_kms_key_arn = module.prod-athena.kms_key_arn
21-
athena_bucket_arn = module.prod-athena.bucket_arn
20+
athena_kms_key_arn = module.prod-athena[0].kms_key_arn
21+
athena_bucket_arn = module.prod-athena[0].bucket_arn
2222

2323
subnet_id = module.vpc[0].private_subnet_id
2424
security_groups = [module.vpc[0].powerbi_gw_security_group_id]

0 commit comments

Comments
 (0)