-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathmain.tf
103 lines (85 loc) · 2.83 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
terraform {
required_version = ">= 1.7.0"
required_providers {
flux = {
source = "fluxcd/flux"
version = ">= 1.2"
}
github = {
source = "integrations/github"
version = ">= 6.1"
}
kind = {
source = "tehcyx/kind"
version = ">= 0.4"
}
kubernetes = {
source = "hashicorp/kubernetes"
version = ">= 2.27"
}
tls = {
source = "hashicorp/tls"
version = ">= 4.0"
}
}
}
# ========================================================================
# Construct KinD cluster
# ========================================================================
resource "kind_cluster" "this" {
name = "flux-e2e"
}
# ========================================================================
# Initialise a Github project
# ========================================================================
resource "github_repository" "this" {
name = var.github_repository
description = var.github_repository
visibility = "public"
auto_init = true # This is extremely important as flux_bootstrap_git will not work without a repository that has been initialised
}
# ========================================================================
# Add deploy key to GitHub repository
# ========================================================================
resource "tls_private_key" "flux" {
algorithm = "ECDSA"
ecdsa_curve = "P256"
}
resource "github_repository_deploy_key" "this" {
title = "Flux"
repository = github_repository.this.name
key = tls_private_key.flux.public_key_openssh
read_only = "false"
}
# ========================================================================
# Manage the SSH keypair flux uses to authenticate with GitHub
# ========================================================================
resource "kubernetes_namespace" "flux_system" {
metadata {
name = "flux-system"
}
lifecycle {
ignore_changes = [metadata]
}
}
resource "kubernetes_secret" "ssh_keypair" {
metadata {
name = "flux-system"
namespace = "flux-system"
}
type = "Opaque"
data = {
"identity.pub" = tls_private_key.flux.public_key_openssh
"identity" = tls_private_key.flux.private_key_pem
"known_hosts" = "github.com ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEmKSENjQEezOmxkZMy7opKgwFB9nkt5YRrYMjNuG5N87uRgg6CLrbo5wAdT/y6v0mKV0U2w0WZ2YB/++Tpockg="
}
depends_on = [kubernetes_namespace.flux_system]
}
# ========================================================================
# Bootstrap KinD cluster
# ========================================================================
resource "flux_bootstrap_git" "this" {
depends_on = [github_repository_deploy_key.this, kubernetes_secret.ssh_keypair]
path = "clusters/my-cluster"
disable_secret_creation = true
}