Skip to content

Commit

Permalink
Enable azure rbac deployment on all services
Browse files Browse the repository at this point in the history
  • Loading branch information
johnake committed Jan 29, 2024
1 parent 8e8079d commit f620e4f
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 37 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/actions/database-backup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,14 @@ runs:
- uses: azure/setup-kubectl@v3

- uses: DFE-Digital/github-actions/set-kubelogin-environment@master
with:
azure-credentials: ${{ inputs.azure_credentials }}

- name: K8 setup
shell: bash
run: |
az aks get-credentials -g ${{ env.cluster_rg }} -n ${{ env.cluster_name }}
make ${{ inputs.environment }} get-cluster-credentials
make bin/konduit.sh
- name: Setup postgres client
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/actions/deploy/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ inputs:
azure-credentials:
description: Credentials for azure
required: true
arm-access-key:
required: true
pr-id:
description: PR number for the review app
required: false
Expand Down Expand Up @@ -57,11 +55,14 @@ runs:
with:
creds: ${{ inputs.azure-credentials }}

- uses: DFE-Digital/github-actions/set-kubelogin-environment@master
with:
azure-credentials: ${{ inputs.azure_credentials }}

- name: Terraform init, plan & apply
shell: bash
run: make ci ${{ inputs.environment }} terraform-apply
env:
ARM_ACCESS_KEY: ${{ inputs.arm-access-key }}
DOCKER_IMAGE: ${{ inputs.docker_image }}
pr_id: ${{ inputs.pr-id }}
TF_VAR_azure_credentials: ${{ inputs.azure-credentials }}
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ jobs:
environment: review
docker_image: ${{ needs.docker.outputs.docker_image }}
azure-credentials: ${{ secrets.AZURE_CREDENTIALS }}
arm-access-key: ${{ secrets.ARM_ACCESS_KEY }}
pr-id: ${{ github.event.pull_request.number }}

- name: Post sticky pull request comment
Expand Down Expand Up @@ -84,7 +83,6 @@ jobs:
environment: ${{ matrix.environment }}
docker_image: ${{ needs.docker.outputs.docker_image }}
azure-credentials: ${{ secrets.AZURE_CREDENTIALS }}
arm-access-key: ${{ secrets.ARM_ACCESS_KEY }}
- uses: ./.github/workflows/actions/smoke-test
id: smoke-test
with:
Expand Down Expand Up @@ -112,4 +110,3 @@ jobs:
environment: production
docker_image: ${{ needs.docker.outputs.docker_image }}
azure-credentials: ${{ secrets.AZURE_CREDENTIALS }}
arm-access-key: ${{ secrets.ARM_ACCESS_KEY }}
2 changes: 0 additions & 2 deletions .github/workflows/delete-review-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ jobs:
run: |
make ci review terraform-destroy
env:
ARM_ACCESS_KEY: ${{ steps.get_secrets.outputs.TFSTATE-CONTAINER-ACCESS-KEY }}
TF_VAR_azure_sp_credentials_json: ${{ secrets.azure_credentials }}
TF_VAR_flt_docker_image: "ghcr.io/dfe-digital/find-a-lost-trn:no-tag"
pr_id: ${{ github.event.pull_request.number }}
shell: bash
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ jobs:
environment: development
docker_image: ${{ steps.image.outputs.tag }}
azure-credentials: ${{ secrets.AZURE_CREDENTIALS }}
arm-access-key: ${{ secrets.ARM_ACCESS_KEY }}

- uses: ./.github/workflows/actions/smoke-test
id: smoke-test
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ domains-infra-apply: domains-infra-init ## terraform apply for dns core resource

get-cluster-credentials: set-azure-account ## make <config> get-cluster-credentials [ENVIRONMENT=<clusterX>]
az aks get-credentials --overwrite-existing -g ${RESOURCE_GROUP_NAME} -n ${RESOURCE_PREFIX}-tsc-${ENVIRONMENT}${CLONE_STRING}-aks
kubelogin convert-kubeconfig -l $(if ${GITHUB_ACTIONS},spn,azurecli)

######################################

Expand Down
50 changes: 36 additions & 14 deletions terraform/aks/.terraform.lock.hcl

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

17 changes: 9 additions & 8 deletions terraform/aks/provider.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
locals {
azure_credentials = try(jsondecode(var.azure_sp_credentials_json), null)
}

provider "azurerm" {
subscription_id = try(local.azure_credentials.subscriptionId, null)
client_id = try(local.azure_credentials.clientId, null)
client_secret = try(local.azure_credentials.clientSecret, null)
tenant_id = try(local.azure_credentials.tenantId, null)
skip_provider_registration = true

features {}
Expand All @@ -17,6 +9,15 @@ provider "kubernetes" {
client_certificate = module.cluster_data.kubernetes_client_certificate
client_key = module.cluster_data.kubernetes_client_key
cluster_ca_certificate = module.cluster_data.kubernetes_cluster_ca_certificate

dynamic "exec" {
for_each = module.cluster_data.azure_RBAC_enabled ? [1] : []
content {
api_version = "client.authentication.k8s.io/v1beta1"
command = "kubelogin"
args = module.cluster_data.kubelogin_args
}
}
}

provider "statuscake" {
Expand Down
5 changes: 0 additions & 5 deletions terraform/aks/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ variable "azure_resource_prefix" {
description = "Standard resource prefix. Usually s189t01 (test) or s189p01 (production)"
}

variable "azure_sp_credentials_json" {
type = string
default = null
}

variable "cluster" {
type = string
description = "AKS cluster where this app is deployed. Either 'test' or 'production'"
Expand Down

0 comments on commit f620e4f

Please sign in to comment.