generated from cloud-native-toolkit/template-terraform-gitops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
69 lines (60 loc) · 2.23 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
locals {
name = "ubi-helm"
bin_dir = module.setup_clis.bin_dir
yaml_dir = "${path.cwd}/.tmp/${local.name}/chart/${local.name}"
service_url = "http://${local.name}.${var.namespace}"
cluster_type = var.cluster_type == "kubernetes" ? "kubernetes" : "openshift"
values_content = {
ubi-helm= {
"replicaCount": 1
"image.repository" = "registry.access.redhat.com/ubi8/ubi"
"image.tag" = "latest"
"command" = "${var.command}"
}
}
layer = "applications"
type = "base"
application_branch = "main"
namespace = var.namespace
layer_config = var.gitops_config[local.layer]
}
module setup_clis {
source = "github.com/cloud-native-toolkit/terraform-util-clis.git"
}
resource null_resource create_yaml {
provisioner "local-exec" {
command = "${path.module}/scripts/create-yaml.sh '${local.name}' '${local.yaml_dir}'"
environment = {
VALUES_CONTENT = yamlencode(local.values_content)
}
}
}
resource null_resource setup_gitops {
depends_on = [null_resource.create_yaml]
triggers = {
name = local.name
namespace = var.namespace
yaml_dir = local.yaml_dir
server_name = var.server_name
layer = local.layer
type = local.type
git_credentials = yamlencode(var.git_credentials)
gitops_config = yamlencode(var.gitops_config)
bin_dir = local.bin_dir
}
provisioner "local-exec" {
command = "${self.triggers.bin_dir}/igc gitops-module '${self.triggers.name}' -n '${self.triggers.namespace}' --contentDir '${self.triggers.yaml_dir}' --serverName '${self.triggers.server_name}' -l '${self.triggers.layer}' --type '${self.triggers.type}'"
environment = {
GIT_CREDENTIALS = nonsensitive(self.triggers.git_credentials)
GITOPS_CONFIG = self.triggers.gitops_config
}
}
provisioner "local-exec" {
when = destroy
command = "${self.triggers.bin_dir}/igc gitops-module '${self.triggers.name}' -n '${self.triggers.namespace}' --delete --contentDir '${self.triggers.yaml_dir}' --serverName '${self.triggers.server_name}' -l '${self.triggers.layer}' --type '${self.triggers.type}'"
environment = {
GIT_CREDENTIALS = nonsensitive(self.triggers.git_credentials)
GITOPS_CONFIG = self.triggers.gitops_config
}
}
}