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

Enable TLS on Ingress Controller using Cert Manager / Let's Encrypt #7

Merged
merged 8 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from 7 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
22 changes: 1 addition & 21 deletions .github/workflows/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
TF_ENV: ${{ steps.set-environment.outputs.tf_env }}
run: |
terraform init -backend-config=backend.tfvars
terraform workspace select $TF_ENV || terraform workspace new $TF_ENV
terraform workspace select -or-create $TF_ENV
terraform apply -auto-approve -lock-timeout=30m \
-replace="module.shared.docker_tag.tag_for_azure[\"alerts\"]" \
-replace="module.shared.docker_tag.tag_for_azure[\"fhir-converter\"]" \
Expand All @@ -103,23 +103,3 @@ jobs:
-replace="module.shared.docker_tag.tag_for_azure[\"tabulation\"]" \
-replace="module.shared.docker_tag.tag_for_azure[\"validation\"]" \
-replace="module.shared.docker_tag.tag_for_azure[\"record-linkage\"]"

azure-cli:
name: Run Azure CLI steps
needs: terraform
runs-on: ubuntu-latest
environment: main
defaults:
run:
shell: bash
working-directory: ./terraform/implementation
steps:
- name: Check Out Changes
uses: actions/checkout@v3

- name: Azure login
uses: azure/login@v1
with:
client-id: ${{ secrets.CLIENT_ID }}
tenant-id: ${{ secrets.TENANT_ID }}
subscription-id: ${{ secrets.SUBSCRIPTION_ID }}
8 changes: 8 additions & 0 deletions terraform/implementation/backend.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ terraform {
source = "azure/azapi"
version = "= 1.8.0"
}
helm = {
source = "hashicorp/helm"
version = "= 2.10.1"
}
kubectl = {
source = "gavinbunney/kubectl"
version = ">= 1.14.0"
}
random = {
source = "hashicorp/random"
version = "= 3.5.1"
Expand Down
62 changes: 62 additions & 0 deletions terraform/implementation/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ locals {
services = toset([
"fhir-converter",
"ingestion",
"ingress",
"message-parser",
"validation",
])
Expand Down Expand Up @@ -212,6 +213,14 @@ resource "azurerm_kubernetes_cluster" "k8s" {

# Helm

provider "kubectl" {
host = azurerm_kubernetes_cluster.k8s.kube_config.0.host
client_certificate = base64decode(azurerm_kubernetes_cluster.k8s.kube_config.0.client_certificate)
client_key = base64decode(azurerm_kubernetes_cluster.k8s.kube_config.0.client_key)
cluster_ca_certificate = base64decode(azurerm_kubernetes_cluster.k8s.kube_config.0.cluster_ca_certificate)
load_config_file = false
}

provider "helm" {
kubernetes {
host = azurerm_kubernetes_cluster.k8s.kube_config.0.host
Expand Down Expand Up @@ -250,6 +259,54 @@ resource "helm_release" "agic" {
]
}

# Cert Manager

resource "helm_release" "cert_manager" {
name = "cert-manager"
repository = "https://charts.jetstack.io"
chart = "cert-manager"
namespace = "cert-manager"
create_namespace = true
depends_on = [azurerm_kubernetes_cluster.k8s]

set {
name = "installCRDs"
value = true
}
}

resource "kubectl_manifest" "cert_manager_issuer" {
depends_on = [helm_release.cert_manager]

yaml_body = <<YAML
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: letsencrypt-prod
spec:
acme:
# You must replace this email address with your own.
nickclyde marked this conversation as resolved.
Show resolved Hide resolved
# Let's Encrypt uses this to contact you about expiring
# certificates, and issues related to your account.
email: [email protected]
# ACME server URL for Let’s Encrypt’s staging environment.
# The staging environment won't issue trusted certificates but is
# used to ensure that the verification process is working properly
# before moving to production
server: https://acme-v02.api.letsencrypt.org/directory
privateKeySecretRef:
# Secret resource used to store the account's private key.
name: phdi-playground-issuer-account-key-prod
nickclyde marked this conversation as resolved.
Show resolved Hide resolved
# Enable the HTTP-01 challenge provider
# you prove ownership of a domain by ensuring that a particular
# file is present at the domain
solvers:
- http01:
ingress:
class: azure/application-gateway
YAML
}

# Helm Releases

resource "helm_release" "building_blocks" {
Expand All @@ -274,4 +331,9 @@ resource "helm_release" "building_blocks" {
name = "smartyToken"
value = var.smarty_auth_token
}

set {
name = "ingressHostname"
value = "${var.resource_group_name}-${terraform.workspace}.${var.location}.cloudapp.azure.com"
}
}