Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PRC-429: Create a new DEV namespace for organisations #29221

Merged
merged 2 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: Namespace
metadata:
name: "hmpps-organisations-dev"
labels:
cloud-platform.justice.gov.uk/is-production: "false"
cloud-platform.justice.gov.uk/environment-name: "development"
pod-security.kubernetes.io/enforce: restricted
annotations:
cloud-platform.justice.gov.uk/business-unit: "HMPPS"
cloud-platform.justice.gov.uk/slack-channel: "public_move-and-improve"
cloud-platform.justice.gov.uk/application: "HMPPS organisations"
cloud-platform.justice.gov.uk/owner: "Move and Improve: [email protected]"
cloud-platform.justice.gov.uk/source-code: "https://github.com/ministryofjustice/hmpps-organisations-api"
cloud-platform.justice.gov.uk/team-name: "move-and-improve"
cloud-platform.justice.gov.uk/review-after: ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: hmpps-organisations-dev-admin
namespace: hmpps-organisations-dev
subjects:
- kind: Group
name: "github:hmpps-sre"
apiGroup: rbac.authorization.k8s.io
- kind: Group
name: "github:hmpps-move-and-improve"
apiGroup: rbac.authorization.k8s.io
- kind: Group
name: "github:syscon-devs"
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: ClusterRole
name: admin
apiGroup: rbac.authorization.k8s.io
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: LimitRange
metadata:
name: limitrange
namespace: hmpps-organisations-dev
spec:
limits:
- default:
cpu: 1000m
memory: 1000Mi
defaultRequest:
cpu: 10m
memory: 100Mi
type: Container
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: ResourceQuota
metadata:
name: namespace-quota
namespace: hmpps-organisations-dev
spec:
hard:
pods: "50"
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default
namespace: hmpps-organisations-dev
spec:
podSelector: {}
policyTypes:
- Ingress
ingress:
- from:
- podSelector: {}
---
kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
name: allow-ingress-controllers
namespace: hmpps-organisations-dev
spec:
podSelector: {}
policyTypes:
- Ingress
ingress:
- from:
- namespaceSelector:
matchLabels:
component: ingress-controllers
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: hmpps-organisations-api-cert
namespace: hmpps-organisations-dev
spec:
secretName: hmpps-organisations-api-cert
issuerRef:
name: letsencrypt-production
kind: ClusterIssuer
dnsNames:
- organisations-api-dev.hmpps.service.justice.gov.uk
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: hmpps-haar-client-admin-team
namespace: hmpps-organisations-dev
rules:
- apiGroups: ["extensions", "apps"]
resources: ["deployments"]
verbs: ["get", "list", "watch", "create", "update", "patch"]
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get", "list", "watch", "create", "update", "patch"]
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "list", "watch", "create", "update", "patch"]
- apiGroups: ["cert-manager.io"]
resources: ["certificates", "issuers"]
verbs: ["get", "list", "watch", "create", "update", "patch"]
- apiGroups: [ "", "extensions" ]
resources: [ "services", "ingresses", "configmaps", "pods/log" ]
verbs: [ "get", "list", "watch" ]
- apiGroups: [""]
resources: ["events"]
verbs: [ "get", "list", "watch", "create", "update", "patch"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: hmpps-haar-client-admin-team
namespace: hmpps-organisations-dev
subjects:
- kind: Group
name: "github:hmpps-haar-client-admin"
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: hmpps-haar-client-admin-team
apiGroup: rbac.authorization.k8s.io
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
resource "kubernetes_secret" "hmpps_domain_events_topic" {
metadata {
name = "hmpps-domain-events-topic"
namespace = var.namespace
}

data = {
topic_arn = data.aws_ssm_parameter.hmpps-domain-events-topic-arn.value
}
}

data "aws_ssm_parameter" "hmpps-domain-events-topic-arn" {
name = "/hmpps-domain-events-dev/topic-arn"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Add the names of the SQS queues & SNS topics which the app needs permissions to access.
# The value of each item should be the namespace where the queue or topic was created.
# This information is used to collect the IAM policies which are used by the IRSA module.
locals {
# The names of the SNS topics used and the namespace which created them
sns_topics = {
"cloud-platform-Digital-Prison-Services-e29fb030a51b3576dd645aa5e460e573" = "hmpps-domain-events-dev"
}

sns_policies = { for item in data.aws_ssm_parameter.irsa_policy_arns_sns : item.name => item.value }
}

module "irsa" {
source = "github.com/ministryofjustice/cloud-platform-terraform-irsa?ref=2.0.0" # use the latest release

# EKS configuration
eks_cluster_name = var.eks_cluster_name

# IRSA configuration
service_account_name = "hmpps-organisations-api"
role_policy_arns = merge(local.sns_policies)

# Tags
business_unit = var.business_unit
application = var.application
is_production = var.is_production
team_name = var.team_name
namespace = var.namespace # this is also used to attach your service account to your namespace
environment_name = var.environment
infrastructure_support = var.infrastructure_support
}

data "aws_ssm_parameter" "irsa_policy_arns_sns" {
for_each = local.sns_topics
name = "/${each.value}/sns/${each.key}/irsa-policy-arn"
}

resource "kubernetes_secret" "irsa" {
metadata {
name = "irsa-output"
namespace = var.namespace
}
data = {
role = module.irsa.role_name
serviceaccount = module.irsa.service_account.name
rolearn = module.irsa.role_arn
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
terraform {
backend "s3" {
}
}

provider "aws" {
alias = "london"
region = "eu-west-2"

default_tags {
tags = {
source-code = "github.com/ministryofjustice/cloud-platform-environments"
slack-channel = var.slack_channel
GithubTeam = "hmpps-move-and-improve"
}
}
}

provider "aws" {
alias = "ireland"
region = "eu-west-1"

default_tags {
tags = {
source-code = "github.com/ministryofjustice/cloud-platform-environments"
slack-channel = var.slack_channel
GithubTeam = "hmpps-move-and-improve"
}
}
}

provider "github" {
token = var.github_token
owner = var.github_owner
}

provider "kubernetes" {}

locals {
default_tags = {
business_unit = var.business_unit
application = var.application
is_production = var.is_production
team_name = var.team_name
environment_name = var.environment
infrastructure_support = var.infrastructure_support
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Make sure that you use the latest version of the module by changing the
* `ref=` value in the `source` attribute to the latest version listed on the
* releases page of this repository.
*
*/
module "rds" {
source = "github.com/ministryofjustice/cloud-platform-terraform-rds-instance?ref=8.0.1"

# VPC configuration
vpc_name = var.vpc_name

# RDS configuration
allow_minor_version_upgrade = true
allow_major_version_upgrade = false
performance_insights_enabled = false
db_max_allocated_storage = "500"
enable_rds_auto_start_stop = true # Uncomment to turn off your database overnight between 10PM and 6AM UTC / 11PM and 7AM BST.
# db_password_rotated_date = "2023-04-17" # Uncomment to rotate your database password.

# PostgreSQL specifics
db_engine = "postgres"
db_engine_version = "16"
rds_family = "postgres16"
db_instance_class = "db.t4g.micro"

# Tags
application = var.application
business_unit = var.business_unit
environment_name = var.environment
infrastructure_support = var.infrastructure_support
is_production = var.is_production
namespace = var.namespace
team_name = var.team_name
}

resource "kubernetes_secret" "rds" {
metadata {
name = "rds-postgresql-instance-output"
namespace = var.namespace
}

data = {
rds_instance_endpoint = module.rds.rds_instance_endpoint
database_name = module.rds.database_name
database_username = module.rds.database_username
database_password = module.rds.database_password
rds_instance_address = module.rds.rds_instance_address
}
}

resource "kubernetes_config_map" "rds" {
metadata {
name = "rds-postgresql-instance-output"
namespace = var.namespace
}

data = {
database_name = module.rds.database_name
db_identifier = module.rds.db_identifier
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
locals {
sa_rules = [
{
api_groups = [""]
resources = [
"pods/portforward",
"deployment",
"secrets",
"services",
"configmaps",
"pods",
]
verbs = [
"patch",
"get",
"create",
"update",
"delete",
"list",
"watch",
]
},
{
api_groups = [
"extensions",
"apps",
"batch",
"networking.k8s.io",
"policy",
]
resources = [
"deployments",
"ingresses",
"cronjobs",
"jobs",
"replicasets",
"poddisruptionbudgets",
"networkpolicies"
]
verbs = [
"get",
"update",
"delete",
"create",
"patch",
"list",
"watch",
]
},
{
api_groups = [
"monitoring.coreos.com",
]
resources = [
"prometheusrules",
"servicemonitors"
]
verbs = [
"*",
]
},
]
}

module "serviceaccount" {
source = "github.com/ministryofjustice/cloud-platform-terraform-serviceaccount?ref=1.1.0"
namespace = var.namespace
kubernetes_cluster = var.kubernetes_cluster
serviceaccount_name = "circleci"
role_name = "circleci"
serviceaccount_rules = local.sa_rules
rolebinding_name = "circleci"
}
Loading
Loading