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

Migrate gcp wif #3481

Merged
merged 1 commit into from
Jan 6, 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
5 changes: 5 additions & 0 deletions .github/actions/deploy-environment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ runs:
with:
azure-credentials: ${{ inputs.azure-credentials }}

- uses: google-github-actions/auth@v2
with:
project_id: claim-additional-payments
workload_identity_provider: projects/638192024625/locations/global/workloadIdentityPools/claim-additional-payments-for-te/providers/claim-additional-payments-for-te

- name: Terraform Apply
shell: bash
run: |
Expand Down
13 changes: 10 additions & 3 deletions .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ on:
type: choice
default: review
options:
- review
- test
- production
- review
- test
- production
docker-image-tag:
description: "Docker image tag to deploy (optional)"
required: true
Expand Down Expand Up @@ -59,6 +59,9 @@ jobs:
needs: [build]
environment:
name: review
permissions:
pull-requests: write
id-token: write

steps:
- name: Checkout code
Expand Down Expand Up @@ -107,6 +110,8 @@ jobs:
max-parallel: 1
matrix:
environment: [test, production]
permissions:
id-token: write

steps:
- name: Checkout code
Expand Down Expand Up @@ -160,6 +165,8 @@ jobs:
url: ${{ steps.deploy_manual.outputs.environment_url }}
outputs:
environment_url: ${{ steps.deploy_manual.outputs.environment_url }}
permissions:
id-token: write

steps:
- name: Checkout code
Expand Down
13 changes: 11 additions & 2 deletions .github/workflows/delete_review_app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ jobs:
runs-on: ubuntu-latest
if: >
github.event.action == 'closed' && contains(github.event.pull_request.labels.*.name, 'deploy') ||
(github.event.action == 'unlabeled' && github.event.label.name == 'deploy') ||
(github.event_name == 'workflow_dispatch')
(github.event.action == 'unlabeled' && github.event.label.name == 'deploy') || (github.event_name ==
'workflow_dispatch')
environment: review
permissions:
pull-requests: write
id-token: write

steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -33,6 +37,11 @@ jobs:
with:
azure-credentials: ${{ secrets.AZURE_CREDENTIALS }}

- uses: google-github-actions/auth@v2
with:
project_id: claim-additional-payments
workload_identity_provider: projects/638192024625/locations/global/workloadIdentityPools/claim-additional-payments-for-te/providers/claim-additional-payments-for-te

- name: Terraform destroy
run: |
if [ ${{ github.event_name }} == 'workflow_dispatch' ]; then
Expand Down
2 changes: 2 additions & 0 deletions config/initializers/dfe_analytics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,6 @@
# to all events we send to BigQuery.
#
# config.environment = ENV.fetch('RAILS_ENV', 'development')

config.azure_federated_auth = ENV.include? "GOOGLE_CLOUD_CREDENTIALS"
end
23 changes: 12 additions & 11 deletions terraform/application/application.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ module "application_configuration" {
config_variables = merge(
local.app_env_values,
{
ENVIRONMENT_NAME = var.environment
PGSSLMODE = local.postgres_ssl_mode
CANONICAL_HOSTNAME = local.canonical_hostname
ENVIRONMENT_NAME = var.environment
PGSSLMODE = local.postgres_ssl_mode
CANONICAL_HOSTNAME = local.canonical_hostname
BIGQUERY_DATASET = var.dataset_name
BIGQUERY_PROJECT_ID = "claim-additional-payments"
BIGQUERY_TABLE_NAME = "events"
})
secret_variables = merge(
{
DATABASE_URL = module.postgres.url
},
var.enable_monitoring ? {
HEARTBEAT_CHECK_URL = module.statuscake[0].heartbeat_check_urls[local.heartbeat_check_name]
} : {}
)
secret_variables = {
DATABASE_URL = module.postgres.url
HEARTBEAT_CHECK_URL = var.enable_monitoring ? module.statuscake[0].heartbeat_check_urls[local.heartbeat_check_name] : null
GOOGLE_CLOUD_CREDENTIALS = var.enable_dfe_analytics_federated_auth ? module.dfe_analytics[0].google_cloud_credentials : null
}
}

module "web_application" {
Expand Down Expand Up @@ -69,4 +69,5 @@ module "worker_application" {
replicas = var.worker_replicas

enable_logit = var.enable_logit
enable_gcp_wif = true
}
3 changes: 2 additions & 1 deletion terraform/application/config/production.tfvars.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
"enable_monitoring": true,
"statuscake_contact_groups": [195955, 282453],
"external_url": "https://www.claim-additional-teaching-payment.service.gov.uk/healthcheck",
"enable_logit": true
"enable_logit": true,
"dataset_name": "claim_events_production"
}
4 changes: 3 additions & 1 deletion terraform/application/config/review.tfvars.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
"enable_postgres_ssl": false,
"startup_command": ["/bin/sh", "-c", "bin/rails server -b 0.0.0.0"],
"worker_command": ["/bin/sh", "-c", "bin/bundle exec bin/delayed_job run -n 1"],
"enable_logit": true
"enable_logit": true,
"dataset_name": "claim_events_test",
"enable_dfe_analytics_federated_auth": true
}
3 changes: 2 additions & 1 deletion terraform/application/config/test.tfvars.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"statuscake_contact_groups": [195955, 282453],
"external_url": "https://test.claim-additional-teaching-payment.service.gov.uk/healthcheck",
"enable_logit": true,
"enable_postgres_backup_storage": true
"enable_postgres_backup_storage": true,
"dataset_name": "claim_events_test"
}
15 changes: 15 additions & 0 deletions terraform/application/dfe_analytics.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
provider "google" {
project = "claim-additional-payments"
}

module "dfe_analytics" {
count = var.enable_dfe_analytics_federated_auth ? 1 : 0
source = "./vendor/modules/aks//aks/dfe_analytics"

azure_resource_prefix = var.azure_resource_prefix
cluster = var.cluster
namespace = var.namespace
service_short = var.service_short
environment = var.environment
gcp_dataset = var.dataset_name
}
10 changes: 10 additions & 0 deletions terraform/application/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ variable "enable_logit" {
nullable = false
}

variable "enable_dfe_analytics_federated_auth" {
description = "Create the resources in Google cloud for federated authentication and enable in application"
default = false
}

variable "dataset_name" {
description = "dfe analytics dataset name in Google Bigquery"
default = null
}

locals {
postgres_ssl_mode = var.enable_postgres_ssl ? "require" : "disable"
canonical_hostname = var.canonical_hostname != null ? var.canonical_hostname : "${var.service_name}-${var.environment}-web.test.teacherservices.cloud"
Expand Down
Loading