Skip to content

Commit 6b782a8

Browse files
Merge pull request #18 from NHSDigital/CCM-5156-account-subdomain-creation
CCM-5156 create subdomains for each account
2 parents 49617fa + c1c8b54 commit 6b782a8

File tree

12 files changed

+182
-0
lines changed

12 files changed

+182
-0
lines changed

infrastructure/terraform/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
# Transient backends
44
components/**/backend_tfscaffold.tf
55

6+
# Exclude all .tfvars files, which are likely to contain sensitive data, such as
7+
# password, private keys, and other secrets. These should not be part of version
8+
# control as they are data points which are potentially sensitive and subject
9+
# to change depending on the environment.
10+
*.tfvars
11+
*.tfvars.json
12+
613
# Compiled files
714
**/*.tfstate
815
**/*.tfplan

infrastructure/terraform/README

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This is an implementation of https://github.com/tfutils/tfscaffold for NHS Notify
2+
3+
Update the `etc/global.tfvars` file according to your NHS Notify Domain, and follow https://github.com/tfutils/tfscaffold?tab=readme-ov-file#bootstrapping to get your tfstate s3 bucket set up
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
latest:^1\.8\.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
README for 'acct' component - Account-level resources
2+
3+
This component is intended to be run to set up things (such as a DNS subdomain) at the account level, and this should be run for each account belonging to the Notify Domain - i.e. there should be a nonprod and prod environment .tfvars
4+
5+
Copy the `env_eu-west-2_example.tfvars` file in the `etc` directory and adjust as needed for nonprod and prod for your NHS Notify Domain.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
locals {
2+
terraform_state_bucket = format(
3+
"%s-tfscaffold-%s-%s",
4+
var.project,
5+
var.aws_account_id,
6+
var.region,
7+
)
8+
9+
csi = replace(
10+
format(
11+
"%s-%s-%s",
12+
var.project,
13+
var.environment,
14+
var.component,
15+
),
16+
"_",
17+
"",
18+
)
19+
20+
# CSI for use in resources with a global namespace, i.e. S3 Buckets
21+
csi_global = replace(
22+
format(
23+
"%s-%s-%s-%s-%s",
24+
var.project,
25+
var.aws_account_id,
26+
var.region,
27+
var.environment,
28+
var.component,
29+
),
30+
"_",
31+
"",
32+
)
33+
34+
default_tags = merge(
35+
var.default_tags,
36+
{
37+
Project = var.project
38+
Environment = var.environment
39+
Component = var.component
40+
Group = var.group
41+
NHSNotifyDomain = var.nhs_notify_domain
42+
Name = local.csi
43+
},
44+
)
45+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
output "aws_account_id" {
2+
value = var.aws_account_id
3+
}
4+
5+
output "r53_delegation_set_id" {
6+
value = aws_route53_delegation_set.main.id
7+
}
8+
9+
output "r53_delegation_set_nameservers" {
10+
value = aws_route53_delegation_set.main.name_servers
11+
}
12+
13+
output "r53_subdomain_name" {
14+
value = var.subdomain_name
15+
}
16+
17+
output "r53_subdomain_id" {
18+
value = one(aws_route53_zone.subdomain[*].id)
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
provider "aws" {
2+
region = var.region
3+
4+
allowed_account_ids = [
5+
var.aws_account_id,
6+
]
7+
8+
default_tags {
9+
tags = {
10+
Project = var.project
11+
Environment = var.environment
12+
Component = var.component
13+
Group = var.group
14+
NHSNotifyDomain = var.nhs_notify_domain
15+
Name = local.csi
16+
}
17+
}
18+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
resource "aws_route53_delegation_set" "main" {
2+
reference_name = "main"
3+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
resource "aws_route53_zone" "subdomain" {
2+
count = var.subdomain_name != "" ? 1 : 0
3+
4+
name = var.subdomain_name
5+
6+
delegation_set_id = aws_route53_delegation_set.main.id
7+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
##
2+
# Basic Required Variables for tfscaffold Components
3+
##
4+
5+
variable "project" {
6+
type = string
7+
description = "The name of the tfscaffold project"
8+
}
9+
10+
variable "environment" {
11+
type = string
12+
description = "The name of the tfscaffold environment"
13+
}
14+
15+
variable "aws_account_id" {
16+
type = string
17+
description = "The AWS Account ID (numeric)"
18+
}
19+
20+
variable "region" {
21+
type = string
22+
description = "The AWS Region"
23+
}
24+
25+
variable "group" {
26+
type = string
27+
description = "The group variables are being inherited from (often synonmous with account short-name)"
28+
}
29+
30+
##
31+
# tfscaffold variables specific to this component
32+
##
33+
34+
# This is the only primary variable to have its value defined as
35+
# a default within its declaration in this file, because the variables
36+
# purpose is as an identifier unique to this component, rather
37+
# then to the environment from where all other variables come.
38+
variable "component" {
39+
type = string
40+
description = "The variable encapsulating the name of this component"
41+
default = "acct"
42+
}
43+
44+
variable "nhs_notify_domain" {
45+
type = string
46+
description = "The name of the NHS Notify Domain that this is deploying to"
47+
}
48+
49+
variable "default_tags" {
50+
type = map(string)
51+
description = "A map of default tags to apply to all taggable resources within the component"
52+
default = {}
53+
}
54+
55+
56+
##
57+
# Variables specific to the "acct" component
58+
##
59+
60+
variable "subdomain_name" {
61+
type = string
62+
description = "The subdomain name to create a Route53 zone for"
63+
default = ""
64+
}

0 commit comments

Comments
 (0)