-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
151 lines (131 loc) · 3.62 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
terraform {
backend "gcs" {
bucket = "edmitr-tf-bucket"
prefix = "terraform/state_gke"
}
required_providers {
flux = {
source = "fluxcd/flux"
version = "1.2.1"
}
github = {
source = "integrations/github"
version = ">=5.18.0"
}
}
}
module "gke_cluster" {
source = "github.com/silhouetteUA/tf-google-gke-cluster"
GOOGLE_REGION = var.GOOGLE_REGION
GOOGLE_PROJECT = var.GOOGLE_PROJECT
GKE_NUM_NODES = var.GKE_NUM_NODES
}
provider "github" {
owner = var.github_org
token = var.github_token
}
resource "tls_private_key" "flux" {
algorithm = var.ALGORITHM
ecdsa_curve = var.ECDSA_CURVE
}
resource "github_repository_deploy_key" "this" {
title = "Flux2"
repository = var.github_repository
key = tls_private_key.flux.public_key_openssh
read_only = "false"
depends_on = [tls_private_key.flux]
}
provider "flux" {
kubernetes = {
config_path = module.gke_cluster.kubeconfig
}
git = {
url = "ssh://[email protected]/${var.github_org}/${var.github_repository}.git"
ssh = {
username = "git"
private_key = tls_private_key.flux.private_key_pem
}
}
}
resource "flux_bootstrap_git" "this" {
depends_on = [github_repository_deploy_key.this, module.gke_cluster]
path = var.TARGET_PATH
}
module "gke-workload-identity" {
source = "terraform-google-modules/kubernetes-engine/google//modules/workload-identity"
use_existing_k8s_sa = true
name = "kustomize-controller"
namespace = "flux-system"
project_id = var.GOOGLE_PROJECT
cluster_name = "main"
location = var.GOOGLE_REGION
annotate_k8s_sa = true
roles = ["roles/cloudkms.cryptoKeyEncrypterDecrypter"]
}
module "kms" {
source = "github.com/den-vasyliev/terraform-google-kms"
project_id = var.GOOGLE_PROJECT
keyring = "sops-flux"
location = "global"
keys = ["sops-keys-flux"]
prevent_destroy = false
}
################### LOCAL deployment STARTS HERE (localhost KIND cluster + FluxCD + repo reconciliation) ###################
# terraform {
# backend "gcs" {
# bucket = "edmitr-tf-bucket"
# prefix = "terraform/state"
# }
# required_providers {
# kind = {
# source = "tehcyx/kind"
# version = "0.2.1"
# }
# flux = {
# source = "fluxcd/flux"
# version = "1.2.1"
# }
# github = {
# source = "integrations/github"
# version = ">=5.18.0"
# }
# }
# }
# provider "kind" {
# }
# resource "kind_cluster" "this" {
# name = var.local_kind_cluster_name
# }
# provider "github" {
# owner = var.github_org
# token = var.github_token
# }
# resource "tls_private_key" "flux" {
# algorithm = "ECDSA"
# ecdsa_curve = "P256"
# }
# resource "github_repository_deploy_key" "this" {
# title = "Flux"
# repository = var.github_repository
# key = tls_private_key.flux.public_key_openssh
# read_only = "false"
# }
# provider "flux" {
# kubernetes = {
# host = kind_cluster.this.endpoint
# client_certificate = kind_cluster.this.client_certificate
# client_key = kind_cluster.this.client_key
# cluster_ca_certificate = kind_cluster.this.cluster_ca_certificate
# }
# git = {
# url = "ssh://[email protected]/${var.github_org}/${var.github_repository}.git"
# ssh = {
# username = "git"
# private_key = tls_private_key.flux.private_key_pem
# }
# }
# }
# resource "flux_bootstrap_git" "this" {
# depends_on = [github_repository_deploy_key.this]
# path = "cluster/fluxcd-test"
# }