Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit 1f24ea7

Browse files
feat: DTOSS-9131 Terraform infrastructure creation (#30)
1 parent 9713bf5 commit 1f24ea7

35 files changed

+2660
-13
lines changed

.azuredevops/pipelines/cd-infrastructure-dev-audit.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ resources:
1414
- repository: dtos-devops-templates
1515
type: github
1616
name: NHSDigital/dtos-devops-templates
17-
ref: f8141ab50ec0f3630044fa0f531952d2dbbd1e85
17+
ref: cf5e22fe4614b7d077a22301d29883e86ac3defc
1818
endpoint: NHSDigital
1919

2020
variables:
@@ -23,7 +23,7 @@ variables:
2323
- name: TF_DIRECTORY
2424
value: $(System.DefaultWorkingDirectory)/$(System.TeamProject)/infrastructure/tf-audit
2525
- name: TF_VERSION
26-
value: 1.9.2
26+
value: 1.11.4
2727
- name: TF_PLAN_ARTIFACT
2828
value: tf_plan_audit_DEV
2929
- name: ENVIRONMENT

.azuredevops/pipelines/cd-infrastructure-dev-core.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ resources:
1414
- repository: dtos-devops-templates
1515
type: github
1616
name: NHSDigital/dtos-devops-templates
17-
ref: f8141ab50ec0f3630044fa0f531952d2dbbd1e85
17+
ref: cf5e22fe4614b7d077a22301d29883e86ac3defc
1818
endpoint: NHSDigital
1919

2020
variables:
@@ -24,7 +24,7 @@ variables:
2424
- name: TF_DIRECTORY
2525
value: $(System.DefaultWorkingDirectory)/$(System.TeamProject)/infrastructure/tf-core
2626
- name: TF_VERSION
27-
value: 1.9.2
27+
value: 1.11.4
2828
- name: TF_PLAN_ARTIFACT
2929
value: tf_plan_core_DEV
3030
- name: ENVIRONMENT

.github/workflows/cicd-1-pull-request.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ name: "CI/CD pull request"
55
on:
66
push:
77
branches:
8-
- "**"
8+
- main
99
pull_request:
10-
types: [opened, reopened]
10+
types: [opened, reopened, synchronize]
1111

1212
jobs:
1313

@@ -103,11 +103,11 @@ jobs:
103103
build-image-stage: # Recommended maximum execution time is 3 minutes
104104
name: Image build stage
105105
needs: [metadata, commit-stage, test-stage]
106-
uses: NHSDigital/dtos-devops-templates/.github/workflows/stage-3-build-images.yaml@main
106+
uses: NHSDigital/dtos-devops-templates/.github/workflows/stage-3-build.yaml@main
107107
if: needs.metadata.outputs.does_pull_request_exist == 'true' || github.ref == 'refs/heads/main' || (github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'reopened'))
108108
with:
109-
docker_compose_file: ./compose.yaml
110-
excluded_containers_csv_list: azurite,azurite-setup,sql-database,database-setup
109+
docker_compose_file_csv_list: ./compose.yaml
110+
excluded_containers_csv_list: azurite,azurite-setup,sql-database,database-setup,db
111111
environment_tag: ${{ needs.metadata.outputs.environment_tag }}
112112
function_app_source_code_path: src
113113
project_name: service-layer

compose.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
2-
api:
3-
container_name: "api"
2+
svclyr-api:
3+
container_name: "svclyr-api"
44
build:
55
context: ./src
66
dockerfile: ServiceLayer.API/Dockerfile
@@ -30,8 +30,8 @@ services:
3030
networks:
3131
- backend
3232

33-
mesh-ingest:
34-
container_name: "mesh-ingest"
33+
svclyr-mesh-ingest:
34+
container_name: "svclyr-mesh-ingest"
3535
build:
3636
context: ./src
3737
dockerfile: ServiceLayer.Mesh/Dockerfile
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module "app_insights_audit" {
2+
for_each = { for key, val in var.regions : key => val if val.is_primary_region }
3+
4+
source = "../../../dtos-devops-templates/infrastructure/modules/app-insights"
5+
6+
name = module.regions_config[each.key].names.app-insights
7+
location = each.key
8+
appinsights_type = var.app_insights.appinsights_type
9+
10+
log_analytics_workspace_id = module.log_analytics_workspace_audit[each.key].id
11+
12+
resource_group_name = azurerm_resource_group.audit[each.key].name
13+
tags = var.tags
14+
15+
}

infrastructure/tf-audit/config.tf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
resource "azurerm_resource_group" "audit" {
2+
for_each = { for key, val in var.regions : key => val if val.is_primary_region }
3+
4+
name = "${module.regions_config[each.key].names.resource-group}-audit"
5+
location = each.key
6+
7+
lifecycle {
8+
ignore_changes = [tags]
9+
}
10+
}
11+
12+
module "regions_config" {
13+
for_each = var.regions
14+
15+
source = "../../../dtos-devops-templates/infrastructure/modules/shared-config"
16+
17+
location = each.key
18+
application = var.application
19+
env = var.environment
20+
tags = var.tags
21+
}

infrastructure/tf-audit/data.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
data "azurerm_client_config" "current" {}
2+
3+
data "terraform_remote_state" "hub" {
4+
backend = "azurerm"
5+
config = {
6+
subscription_id = var.HUB_SUBSCRIPTION_ID
7+
storage_account_name = var.HUB_BACKEND_AZURE_STORAGE_ACCOUNT_NAME
8+
container_name = var.HUB_BACKEND_AZURE_STORAGE_ACCOUNT_CONTAINER_NAME
9+
key = var.HUB_BACKEND_AZURE_STORAGE_ACCOUNT_KEY
10+
resource_group_name = var.HUB_BACKEND_AZURE_RESOURCE_GROUP_NAME
11+
}
12+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
locals {
2+
#APPSERVICEPLAN
3+
monitor_diagnostic_setting_appserviceplan_metrics = ["AllMetrics"]
4+
5+
#FUNCTIONAPP
6+
monitor_diagnostic_setting_function_app_enabled_logs = ["AppServiceAuthenticationLogs", "FunctionAppLogs"]
7+
monitor_diagnostic_setting_function_app_metrics = ["AllMetrics"]
8+
9+
# KEYVAULT
10+
monitor_diagnostic_setting_keyvault_enabled_logs = ["AuditEvent", "AzurePolicyEvaluationDetails"]
11+
monitor_diagnostic_setting_keyvault_metrics = ["AllMetrics"]
12+
13+
# LOG ANALYTICS WORKSPACE
14+
monitor_diagnostic_setting_log_analytics_workspace_enabled_logs = ["SummaryLogs", "Audit"]
15+
monitor_diagnostic_setting_log_analytics_workspace_metrics = ["AllMetrics"]
16+
17+
#SQL SERVER AND DATABASE
18+
monitor_diagnostic_setting_database_enabled_logs = ["SQLSecurityAuditEvents", "SQLInsights", "QueryStoreWaitStatistics", "Errors", "DatabaseWaitStatistics", "Timeouts"]
19+
monitor_diagnostic_setting_database_metrics = ["Basic", "InstanceAndAppAdvanced", "WorkloadManagement"]
20+
monitor_diagnostic_setting_sql_server_enabled_logs = ["SQLSecurityAuditEvents"]
21+
monitor_diagnostic_setting_sql_server_metrics = ["Basic", "InstanceAndAppAdvanced", "WorkloadManagement"]
22+
23+
#STORAGE ACCOUNT
24+
monitor_diagnostic_setting_storage_account_enabled_logs = ["StorageWrite", "StorageRead", "StorageDelete"]
25+
monitor_diagnostic_setting_storage_account_metrics = ["Capacity", "Transaction"]
26+
27+
#SUBNET
28+
monitor_diagnostic_setting_network_security_group_enabled_logs = ["NetworkSecurityGroupEvent", "NetworkSecurityGroupRuleCounter"]
29+
30+
#VNET
31+
monitor_diagnostic_setting_vnet_enabled_logs = ["VMProtectionAlerts"]
32+
monitor_diagnostic_setting_vnet_metrics = ["AllMetrics"]
33+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
application = "svclyr"
2+
application_full_name = "service-layer"
3+
environment = "DEV"
4+
5+
features = {
6+
private_endpoints_enabled = true
7+
private_service_connection_is_manual = false
8+
log_analytics_data_export_rule_enabled = false
9+
public_network_access_enabled = false
10+
}
11+
12+
tags = {
13+
Project = "Service-Layer"
14+
}
15+
16+
regions = {
17+
uksouth = {
18+
is_primary_region = true
19+
address_space = "10.135.0.0/16"
20+
connect_peering = true
21+
subnets = {
22+
pep = {
23+
cidr_newbits = 8
24+
cidr_offset = 1
25+
}
26+
}
27+
}
28+
}
29+
30+
app_insights = {
31+
appinsights_type = "web"
32+
}
33+
34+
law = {
35+
law_sku = "PerGB2018"
36+
retention_days = 30
37+
export_enabled = false
38+
export_table_names = ["Alert"]
39+
}
40+
41+
storage_accounts = {
42+
sqllogs = {
43+
name_suffix = "sqllogs"
44+
account_tier = "Standard"
45+
replication_type = "LRS"
46+
public_network_access_enabled = false
47+
containers = {
48+
vulnerability-assessment = {
49+
container_name = "vulnerability-assessment"
50+
container_access_type = "private"
51+
}
52+
}
53+
}
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
application = "svclyr"
2+
application_full_name = "service-layer"
3+
environment = "INT"
4+
5+
features = {
6+
private_endpoints_enabled = true
7+
private_service_connection_is_manual = false
8+
log_analytics_data_export_rule_enabled = false
9+
public_network_access_enabled = false
10+
}
11+
12+
tags = {
13+
Project = "Service-Layer"
14+
}
15+
16+
regions = {
17+
uksouth = {
18+
is_primary_region = true
19+
address_space = "10.139.0.0/16"
20+
connect_peering = true
21+
subnets = {
22+
pep = {
23+
cidr_newbits = 8
24+
cidr_offset = 1
25+
}
26+
}
27+
}
28+
}
29+
30+
app_insights = {
31+
appinsights_type = "web"
32+
}
33+
34+
law = {
35+
law_sku = "PerGB2018"
36+
retention_days = 30
37+
export_enabled = false
38+
export_table_names = ["Alert"]
39+
}
40+
41+
storage_accounts = {
42+
sqllogs = {
43+
name_suffix = "sqllogs"
44+
account_tier = "Standard"
45+
replication_type = "LRS"
46+
public_network_access_enabled = false
47+
containers = {
48+
vulnerability-assessment = {
49+
container_name = "vulnerability-assessment"
50+
container_access_type = "private"
51+
}
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)