Skip to content

Commit

Permalink
Refactor provider.tf to add kubectl provider
Browse files Browse the repository at this point in the history
  • Loading branch information
adamlahbib committed Nov 17, 2024
1 parent e54764c commit 68f85b4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 29 deletions.
11 changes: 11 additions & 0 deletions terraform/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ terraform {
source = "cloudflare/cloudflare"
version = "~> 4.0"
}
kubectl = {
source = "gavinbunney/kubectl"
version = ">= 1.7.0"
}
}
}

Expand All @@ -40,3 +44,10 @@ provider "kubernetes" {
provider "cloudflare" {
api_token = var.CLOUDFLARE_TOKEN
}

provider "kubectl" {
host = aws_eks_cluster.eks_cluster.endpoint
cluster_ca_certificate = base64decode(aws_eks_cluster.eks_cluster.certificate_authority.0.data)
token = data.aws_eks_cluster_auth.cluster_auth.token
load_config_file = false
}
48 changes: 19 additions & 29 deletions terraform/tls.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,24 @@ resource "helm_release" "cert_manager" {
}
}

resource "kubernetes_manifest" "cluster_issuer" {
manifest = {
apiVersion = "cert-manager.io/v1"
kind = "ClusterIssuer"
metadata = {
name = "letsencrypt-prod"
namespace = "cert-manager"
}
spec = {
acme = {
email = var.CLOUDFLARE_EMAIL
server = "https://acme-v02.api.letsencrypt.org/directory"
privateKeySecretRef = {
name = "letsencrypt-prod-key"
}
solvers = [
{
dns01 = {
cloudflare = {
email = var.CLOUDFLARE_EMAIL
apiToken = var.CLOUDFLARE_TOKEN
}
}
}
]
}
}
}
skip_kind_check = true # because it depends on the cert-manager CRDs being installed
resource "kubectl_manifest" "cluster_issuer" {
yaml_body = <<YAML
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: letsencrypt-prod
namespace: cert-manager
spec:
acme:
email: ${var.CLOUDFLARE_EMAIL}
server: https://acme-v02.api.letsencrypt.org/directory
privateKeySecretRef:
name: letsencrypt-prod-key
solvers:
- dns01:
cloudflare:
email: ${var.CLOUDFLARE_EMAIL}
apiToken: ${var.CLOUDFLARE_TOKEN}
YAML
depends_on = [helm_release.cert_manager]
}

0 comments on commit 68f85b4

Please sign in to comment.