generated from NHSDigital/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
733ed34
commit 2bad940
Showing
14 changed files
with
264 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ | |
!project.code-workspace | ||
|
||
# Please, add your custom content below! | ||
*terraform.lock.hcl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
variable "project" { | ||
description = "The project code, typically reflecting a sub-project of the project owner" | ||
} | ||
|
||
variable "project_owner" { | ||
description = "The owner of the project, based on organisation and department codes" | ||
} | ||
|
||
variable "environment" { | ||
description = "The deployment environment e.g. dev, test, pre-prod, or prod" | ||
} | ||
|
||
variable "repo_name" { | ||
description = "The name of the GitHub repository associated with this project" | ||
} | ||
|
||
variable "tag_version" { | ||
description = "The version of the tagging policy in use, enabling evolution of the tagging strategy and supporting automation" | ||
type = string | ||
} | ||
|
||
variable "service" { | ||
description = "The service or program that this project is associated with" | ||
type = string | ||
} | ||
|
||
variable "cost_centre" { | ||
description = "The cost center used for consolidated billing and cost attribution to programs" | ||
type = string | ||
} | ||
|
||
variable "data_classification" { | ||
description = "The data classification according to the Cloud Risk Model, enabling quick searches e.g. Low, Medium, High" | ||
type = string | ||
} | ||
|
||
variable "data_type" { | ||
description = "The type of data handled by this project e.g. None, PCD, PII, Anonymized, UserAccount, Audit" | ||
type = string | ||
} | ||
|
||
variable "project_type" { | ||
description = "The purpose of the resources e.g PoC, Pilot, Production" | ||
type = string | ||
} | ||
|
||
variable "public_facing" { | ||
description = "Indicates if the project is accessible publicly via the internet" | ||
type = string | ||
} | ||
|
||
variable "service_category" { | ||
description = "Identifies the service category to prioritize responses" | ||
type = string | ||
} | ||
|
||
variable "on_off_pattern" { | ||
description = "Defines the automated schedule for turning resources on/off, applicable for non-production environments" | ||
type = string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
locals { | ||
account_id = data.aws_caller_identity.current.id | ||
workspace_suffix = "${terraform.workspace}" == "default" ? "" : "-${terraform.workspace}" | ||
prefix = "${var.project}-${var.environment}" | ||
|
||
deploy_databases = var.environment == terraform.workspace | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
variable "aws_region" { | ||
type = string | ||
default = "eu-west-2" | ||
} | ||
|
||
data "aws_caller_identity" "current" {} | ||
|
||
provider "aws" { | ||
region = var.aws_region | ||
|
||
skip_metadata_api_check = true | ||
skip_region_validation = true | ||
skip_credentials_validation = true | ||
skip_requesting_account_id = false | ||
|
||
default_tags { | ||
tags = { | ||
owner = var.project_owner | ||
project = var.project | ||
environment = "${var.environment}${local.workspace_suffix}" | ||
workspace = terraform.workspace | ||
terraform-base-path = replace(path.cwd, "/^.*?(${var.repo_name}\\/)/", "$1") | ||
TagVersion = var.tag_version | ||
service = var.service | ||
CostCentre = var.cost_centre | ||
data_classification = var.data_classification | ||
DataType = var.data_type | ||
ProjectType = var.project_type | ||
PublicFacing = var.public_facing | ||
ServiceCategory = var.service_category | ||
OnOffPattern = var.on_off_pattern | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
terraform { | ||
required_version = ">= 1.5.0, < 1.7.2" | ||
|
||
backend "s3" { | ||
} | ||
|
||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "5.70.0" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
terraform { | ||
required_version = ">= 1.5.0, < 1.7.2" | ||
|
||
backend "local" { | ||
} | ||
|
||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "5.70.0" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Account-Wide Infrastructure | ||
|
||
This is infrastructure that should only be deployed once per account. | ||
|
||
> **Note**: This should be deployed using the `default` workspace. | ||
Currently, the following resources are deployed: | ||
|
||
1. IAM role for GitHub Actions (via OIDC) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
data "aws_iam_policy" "power_user_iam_policy" { | ||
name = "PowerUserAccess" | ||
} | ||
|
||
resource "aws_iam_role_policy_attachment" "power_user_iam_role_policy_attachment" { | ||
role = aws_iam_role.github_runner_iam_role.name | ||
policy_arn = data.aws_iam_policy.power_user_iam_policy.arn | ||
} | ||
|
||
resource "aws_iam_policy" "read_only_user_iam_policy" { | ||
name = "${var.repo_name}-github-runner-iam-services" | ||
description = "Read-only policy for IAM permissions required by GitHub runner" | ||
policy = <<-EOF | ||
{ | ||
"Version":"2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Action": [ | ||
"iam:GenerateCredentialReport", | ||
"iam:List*", | ||
"iam:GenerateServiceLastAccessedDetails", | ||
"iam:TagRole", | ||
"iam:DeletePolicy", | ||
"iam:CreateRole", | ||
"iam:DeleteRole", | ||
"iam:AttachRolePolicy", | ||
"iam:TagPolicy", | ||
"iam:CreatePolicy", | ||
"iam:PassRole", | ||
"iam:Get*", | ||
"iam:DetachRolePolicy", | ||
"iam:SimulatePrincipalPolicy", | ||
"iam:SimulateCustomPolicy", | ||
"iam:CreatePolicyVersion", | ||
"iam:DeletePolicyVersion", | ||
"iam:TagOpenIDConnectProvider", | ||
"iam:DeleteRolePolicy", | ||
"iam:PutRolePolicy", | ||
"iam:UpdateOpenIDConnectProviderThumbprint", | ||
"iam:UntagPolicy", | ||
"iam:UntagRole" | ||
], | ||
"Effect": "Allow", | ||
"Resource": "*", | ||
"Sid": "ReadOnlyIAM" | ||
} | ||
] | ||
} | ||
EOF | ||
} | ||
|
||
resource "aws_iam_role_policy_attachment" "read_only_user_iam_role_policy_attachment" { | ||
role = aws_iam_role.github_runner_iam_role.name | ||
policy_arn = aws_iam_policy.read_only_user_iam_policy.arn | ||
} | ||
|
||
resource "aws_iam_role" "github_runner_iam_role" { | ||
name = "${var.repo_name}-github-runner" | ||
assume_role_policy = <<EOF | ||
{ | ||
"Version":"2012-10-17", | ||
"Statement":[ | ||
{ | ||
"Effect":"Allow", | ||
"Principal":{ | ||
"Federated":"arn:aws:iam::${local.account_id}:oidc-provider/token.actions.githubusercontent.com" | ||
}, | ||
"Action":"sts:AssumeRoleWithWebIdentity", | ||
"Condition":{ | ||
"ForAllValues:StringLike":{ | ||
"token.actions.githubusercontent.com:sub":"repo:${var.github_org}/${var.repo_name}:*", | ||
"token.actions.githubusercontent.com:aud":"sts.amazonaws.com" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
EOF | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
variable "github_org" { | ||
description = "The name of the GitHub organization e.g. NHSDigital" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module "terraform_lock_dynamodb" { | ||
source = "../../modules/dynamodb" | ||
table_name = var.terraform_lock_table_name | ||
|
||
hash_key = "LockID" | ||
attributes = [{ | ||
name = "LockID" | ||
type = "S" | ||
}] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module "terraform_state_bucket" { | ||
source = "../../modules/s3" | ||
bucket_name = var.terraform_state_bucket_name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
variable "terraform_lock_table_name" { | ||
description = "Name of dynamodb table that holds terraformn state locks" | ||
} | ||
|
||
variable "terraform_state_bucket_name" { | ||
description = "Name of s3 bucket that holds terraform state" | ||
} | ||
|
||
variable "s3_versioning" { | ||
description = "Whether versioning is enabled for the S3 bucket that holds the Terraform state" | ||
type = bool | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters