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

adding config + pipeline #4

Merged
merged 186 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
186 commits
Select commit Hold shift + click to select a range
b4e3bb4
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
d58657b
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
35489c7
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
da14500
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
a101dae
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
0be0c53
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
d49b769
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
dd625db
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
51c52ce
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
41d5809
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
2c691ee
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
bb62a11
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
4ee73f8
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
65c3bf2
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
9d2ba40
Delete components/.terraform.lock.hcl
ConnorOKane-Kainos Jul 3, 2024
194d18b
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
cc5e384
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
b7dbfa5
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
9684ecf
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
0c8e04a
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
8dec89b
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
02c80f9
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
480cb61
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
edc7164
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
d95975b
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
289b1ed
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
801fde5
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
f39dffd
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
3893f35
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
973b439
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
4ab8e5b
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
e8a7d3e
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
13f49d5
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
0dc2b3f
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
4873743
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
9d33687
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
c64194d
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
e943b43
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
2b99e1d
adding config + pipeline
ConnorOKane-Kainos Jul 3, 2024
0fe8d55
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
1526b60
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
a1ecd2a
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
e14f702
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
5b67021
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
739322e
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
50fc558
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
eb77d9c
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
317125a
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
a622162
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
1cfc096
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
29eab8c
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
c8304f6
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
f219305
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
e44b485
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
d6d30c9
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
44fc5c5
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
4ffebd4
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
b722418
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
1dd44a0
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
0ba2451
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
3a29592
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
e09a65a
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
7f7583b
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
b47c4b2
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
189d1a0
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
fc15b76
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
07f1b45
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
39b3258
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
13300c2
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
b226657
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
ff1aaba
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
1a48d4b
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
729ebee
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
d02b271
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
782d647
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
3673d69
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
14018f5
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
287b614
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
5560363
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
4e6dcbe
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
d4b52e3
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
e3fa42e
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
2b4b241
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
d6e4595
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
5cc8262
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
cf4a190
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
dfc2e24
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
2cf388b
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
4697522
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
4584a3b
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
d245d3f
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
c43ca92
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
c0d3bbb
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
226a30d
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
9492425
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
d48a99f
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
e81a1f6
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
1e6a7a9
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
7846ed5
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
d349f4c
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
5782f27
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
ac2bd18
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
4a6c931
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
8ca524c
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
f09b10a
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
2dcfd14
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
43ac7ff
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
5fbde25
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
f344746
adding config + pipeline
ConnorOKane-Kainos Jul 4, 2024
a4c6db4
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
b7b06c6
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
7605960
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
ddb08c0
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
61f2eaa
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
b1cb231
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
c9d67fd
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
31882b9
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
47c395c
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
76b10a0
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
e41a0b1
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
2a27fa9
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
4af0110
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
0de8801
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
f272ff1
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
f39fee3
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
8a5de50
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
44d006f
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
f9ce920
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
5043737
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
b366ecf
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
07b5317
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
8da493d
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
bb19213
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
5121c65
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
6a27d09
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
d139f27
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
3a4b1a5
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
b88b576
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
08f30e2
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
d60ac42
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
8ce6146
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
6869a4e
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
4996a36
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
806061b
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
2dc2387
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
cb8a6d7
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
b628f74
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
16a5ba5
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
4f1fcbd
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
2383c76
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
9ee0585
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
e11ef2e
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
b2c1afe
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
bd325b2
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
ddab577
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
ba648e3
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
5d32a5b
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
b125f79
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
62e7331
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
0c802f4
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
c8188fb
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
a430dd2
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
fb8fae2
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
99c3702
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
90ef293
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
f825123
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
695f55d
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
945c719
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
d34aa89
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
3f5b854
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
4634d79
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
c9d4678
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
ff140e9
adding config + pipeline
ConnorOKane-Kainos Jul 5, 2024
ccc077f
adding config + pipeline
ConnorOKane-Kainos Jul 7, 2024
b3045b7
adding config + pipeline
ConnorOKane-Kainos Jul 7, 2024
7ad12f1
adding config + pipeline
ConnorOKane-Kainos Jul 7, 2024
21f0b36
adding config + pipeline
ConnorOKane-Kainos Jul 7, 2024
ae9dc22
adding config + pipeline
ConnorOKane-Kainos Jul 7, 2024
1a890c0
adding config + pipeline
ConnorOKane-Kainos Jul 7, 2024
696066d
adding config + pipeline
ConnorOKane-Kainos Jul 7, 2024
efad249
adding config + pipeline
ConnorOKane-Kainos Jul 7, 2024
06ff5a7
adding config + pipeline
ConnorOKane-Kainos Jul 7, 2024
3b70304
adding config + pipeline
ConnorOKane-Kainos Jul 7, 2024
5f94a84
adding config + pipeline
ConnorOKane-Kainos Jul 7, 2024
fa69b52
adding config + pipeline
ConnorOKane-Kainos Jul 7, 2024
0c5a65b
adding config + pipeline
ConnorOKane-Kainos Jul 7, 2024
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
83 changes: 83 additions & 0 deletions .github/workflows/pipeline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Push

on:
push:
branches:
- master

env:
TF_LOG: INFO

permissions:
id-token: write
contents: read

jobs:
deploy-infra:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Terraform
uses: hashicorp/setup-terraform@v2

# Log into Azure with OIDC integration
- name: 'Az CLI login'
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.DCD_CFT_SANDBOX_SUBSCRIPTION }}

- name: Install jq
run: |
sudo apt-get install jq -y

# List all the repos and branches that the rules are going to be applied on
- name: List Repositories and Branches
run: |
echo "Checking Repositories and Branches"
cat ./test-repos.json
for repo in $(jq -r '.[]' ./test-repos.json); do
echo "Checking repository: $repo"
curl -H "Authorization: token ${{ secrets.PAT_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/hmcts/$repo

for branch in main master; do
echo "Checking branch: $branch in repository: $repo"
curl -H "Authorization: token ${{ secrets.PAT_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/hmcts/$repo/branches/$branch
done
done

- name: Terraform Init
working-directory: components
env:
STORAGE_ACCOUNT: ${{ secrets.STORAGE_ACCOUNT }}
CONTAINER_NAME: ${{ secrets.CONTAINER_NAME }}
RESOURCE_GROUP_NAME: ${{ secrets.RESOURCE_GROUP_NAME }}
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
ARM_SUBSCRIPTION_ID: ${{ secrets.DCD_CFT_SANDBOX_SUBSCRIPTION }}
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
run: terraform init -backend-config="storage_account_name=$STORAGE_ACCOUNT" -backend-config="container_name=$CONTAINER_NAME" -backend-config="resource_group_name=$RESOURCE_GROUP_NAME"

- name: Terraform Plan
working-directory: components
env:
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
ARM_SUBSCRIPTION_ID: ${{ secrets.DCD_CFT_SANDBOX_SUBSCRIPTION }}
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
run: terraform plan -var="github_token=${{ secrets.PAT_TOKEN }}"

- name: Terraform Apply
working-directory: components
env:
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
ARM_SUBSCRIPTION_ID: ${{ secrets.DCD_CFT_SANDBOX_SUBSCRIPTION }}
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
run: terraform apply -var="github_token=${{ secrets.PAT_TOKEN }}" -auto-approve
93 changes: 93 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Pull Request

on:
pull_request:
branches:
- master

env:
TF_LOG: INFO

permissions:
id-token: write
issues: write
pull-requests: write
contents: read

jobs:
pr-infra-check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Terraform
uses: hashicorp/setup-terraform@v2

# Log into Azure with OIDC integration
- name: 'Az CLI login'
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.DCD_CFT_SANDBOX_SUBSCRIPTION }}

- name: Install jq
run: sudo apt-get install jq -y

# List all the repos and branches that the rules are going to be applied on
- name: List Repositories and Branches
run: |
echo "Checking Repositories and Branches"
cat ./test-repos.json
for repo in $(jq -r '.[]' ./test-repos.json); do
echo "Checking repository: $repo"
curl -H "Authorization: token ${{ secrets.PAT_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/hmcts/$repo

for branch in main master; do
echo "Checking branch: $branch in repository: $repo"
curl -H "Authorization: token ${{ secrets.PAT_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/hmcts/$repo/branches/$branch
done
done

- name: Terraform Init
working-directory: components
env:
STORAGE_ACCOUNT: ${{ secrets.STORAGE_ACCOUNT }}
CONTAINER_NAME: ${{ secrets.CONTAINER_NAME }}
RESOURCE_GROUP_NAME: ${{ secrets.RESOURCE_GROUP_NAME }}
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ${{ secrets.DCD_CFT_SANDBOX_SUBSCRIPTION }}
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
run: terraform init -backend-config="storage_account_name=$STORAGE_ACCOUNT" -backend-config="container_name=$CONTAINER_NAME" -backend-config="resource_group_name=$RESOURCE_GROUP_NAME"

- name: Terraform format
working-directory: components
id: fmt
run: terraform fmt -check

- name: Terraform validate
working-directory: components
id: validate
env:
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ${{ secrets.DCD_CFT_SANDBOX_SUBSCRIPTION }}
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
run: terraform validate

- name: Terraform plan
working-directory: components
id: plan
env:
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ${{ secrets.DCD_CFT_SANDBOX_SUBSCRIPTION }}
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
run: terraform plan -var="github_token=${{ secrets.PAT_TOKEN }}"
34 changes: 34 additions & 0 deletions components/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.log
crash.*.log

# Exclude all .tfvars files, which are likely to contain sensitive data, such as
# password, private keys, and other secrets. These should not be part of version
# control as they are data points which are potentially sensitive and subject
# to change depending on the environment.
*.tfvars
*.tfvars.json

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json

# Include override files you do wish to add to version control using negated pattern
# !example_override.tf

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*

# Ignore CLI configuration files
.terraformrc
terraform.rc
44 changes: 44 additions & 0 deletions components/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions components/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
locals {
# Read the repositories list from the JSON file
repositories_list = jsondecode(file("${path.module}/../test-repos.json"))

# Filter out excluded repositories
included_repositories = [
for repo in local.repositories_list : repo
if !contains(var.excluded_repositories, repo)
]

# Create a combination of repositories and branches
repo_branch_combinations = flatten([
for repo in local.included_repositories : [
for branch in var.branches : {
repo = repo
branch = branch
}
]
])
}

locals {
env_display_names = {
sbox = "Sandbox"
prod = "Production"
nonprod = "Non-Production"
test = "Test"
staging = "staging"
}
common_tags = {
"managedBy" = "DevOps"
"solutionOwner" = "RDO"
"activityName" = "Storage Account"
"dataClassification" = "Internal"
"automation" = ""
"costCentre" = ""
}
enforced_tags = module.tags.common_tags
}




69 changes: 69 additions & 0 deletions components/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
module "tags" {
source = "git::https://github.com/hmcts/terraform-module-common-tags.git?ref=master"
environment = var.env
product = var.product
builtFrom = var.builtFrom
}

resource "azurerm_resource_group" "rg" {
name = var.resource_group_name
location = var.location
tags = module.tags.common_tags
}

resource "azurerm_storage_account" "sa" {
name = var.storage_account_name
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
account_tier = "Standard"
account_replication_type = "LRS"
tags = module.tags.common_tags
}

resource "azurerm_storage_container" "tfstate" {
name = "tfstate"
storage_account_name = azurerm_storage_account.sa.name
container_access_type = "private"
}

# Check if repositories exist
data "github_repository" "existing_repos" {
for_each = { for repo in local.included_repositories : repo => repo }
name = each.value
}

# Check if branches exist
data "github_branch" "existing_branches" {
for_each = { for combo in local.repo_branch_combinations : "${combo.repo}:${combo.branch}" => combo if contains(keys(data.github_repository.existing_repos), combo.repo) }
repository = each.value.repo
branch = each.value.branch
}

# Apply branch protection rules only if the branch exists
resource "github_branch_protection_v3" "branch_protection" {
for_each = {
for combo in local.repo_branch_combinations : "${combo.repo}:${combo.branch}" => combo
if try(data.github_branch.existing_branches["${combo.repo}:${combo.branch}"].branch, null) != null
}

repository = each.value.repo
branch = each.value.branch
enforce_admins = false # Excludes organisation admins

required_status_checks {
strict = true
contexts = ["ci/test", "ci/lint"]
}

required_pull_request_reviews {
dismiss_stale_reviews = true
require_code_owner_reviews = false
required_approving_review_count = 1 # Ensure at least 1 reviewer
}

restrictions {
users = []
teams = []
apps = []
}
}
8 changes: 8 additions & 0 deletions components/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
output "common_tags" {
value = {
Environment = var.env
Product = var.product
BuiltFrom = var.builtFrom
}
}

Loading
Loading