-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjfrog-platform.tf
217 lines (197 loc) · 6.44 KB
/
jfrog-platform.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# Terraform script to deploy Artifactory on the AWS EKS created earlier
data "aws_eks_cluster_auth" "jfrog_cluster" {
name = module.eks.cluster_name
}
# Configure the Kubernetes provider to use the EKS cluster
provider "kubernetes" {
host = module.eks.cluster_endpoint
token = data.aws_eks_cluster_auth.jfrog_cluster.token
cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data)
}
## Until sizing specs are part of the jfrog-platform chart, we pull them from the individual charts that are inside the platform chart
# Fetch the JFrog Platform Helm chart and untar it to the current directory so we can use the sizing files to create the final values files
resource "null_resource" "fetch_platform_chart" {
provisioner "local-exec" {
command = "rm -rf jfrog-platform-*.tgz"
}
provisioner "local-exec" {
command = "helm fetch jfrog-platform --version ${var.jfrog_platform_chart_version} --repo https://charts.jfrog.io --untar"
}
}
################### Artifactory sizing
## Prepare the final values files for the JFrog Platform sizing
data "local_file" "artifactory_sizing" {
filename = "${path.module}/jfrog-platform/charts/artifactory/sizing/artifactory-${var.sizing}.yaml"
depends_on = [null_resource.fetch_platform_chart]
}
# Inject two spaces before all lines and load into a variable
locals {
indented_artifactory_sizing = join("\n", [for line in split("\n", data.local_file.artifactory_sizing.content) : " ${line}"])
}
# Create the new artifactory sizing YAML string
locals {
new_artifactory_sizing = <<-EOT
artifactory:
${local.indented_artifactory_sizing}
EOT
}
# Write the new Artifactory YAML to a file
resource "local_file" "new_artifactory_sizing" {
filename = "${path.module}/jfrog-artifactory-${var.sizing}-adjusted.yaml"
content = trimspace(local.new_artifactory_sizing)
}
################### Xray sizing
## Prepare the final values files for the JFrog Platform sizing
data "local_file" "xray_sizing" {
filename = "${path.module}/jfrog-platform/charts/xray/sizing/xray-${var.sizing}.yaml"
depends_on = [null_resource.fetch_platform_chart]
}
# Inject two spaces before all lines and load into a variable
locals {
indented_xray_sizing = join("\n", [for line in split("\n", data.local_file.xray_sizing.content) : " ${line}"])
}
# Create the new Xray sizing YAML string
locals {
new_xray_sizing = <<-EOT
xray:
${local.indented_xray_sizing}
EOT
}
# Write the new Xray YAML to a file
resource "local_file" "new_xray_sizing" {
filename = "${path.module}/jfrog-xray-${var.sizing}-adjusted.yaml"
content = trimspace(local.new_xray_sizing)
}
# Create an empty artifactory-license.yaml if missing
resource "local_file" "empty_license" {
count = fileexists("${path.module}/artifactory-license.yaml") ? 0 : 1
filename = "${path.module}/artifactory-license.yaml"
content = "## Empty file to satisfy Helm requirements"
}
# Set the cache-fs-size based on the sizing variable to 80% of the disk size
locals {
cache-fs-size = (var.sizing == "large" ? var.artifactory_disk_size_large * 0.8 :
var.sizing == "xlarge" ? var.artifactory_disk_size_large * 0.8 :
var.sizing == "2xlarge" ? var.artifactory_disk_size_large * 0.8 :
var.artifactory_disk_size_default * 0.8)
}
# Write the artifactory-custom.yaml file with the variables needed
resource "local_file" "jfrog_platform_values" {
content = <<-EOT
artifactory:
artifactory:
persistence:
maxCacheSize: "${local.cache-fs-size}000000000"
awsS3V3:
region: "${var.region}"
bucketName: "${local.artifactory_s3_bucket_name}"
database:
url: "jdbc:postgresql://${aws_db_instance.artifactory_db.endpoint}/${var.artifactory_db_name}?sslmode=require"
user: "${var.artifactory_db_username}"
password: "${var.artifactory_db_password}"
xray:
database:
url: "postgres://${aws_db_instance.xray_db.endpoint}/${var.xray_db_name}?sslmode=require"
user: "${var.xray_db_username}"
password: "${var.xray_db_password}"
EOT
filename = "${path.module}/jfrog-custom.yaml"
depends_on = [
aws_db_instance.artifactory_db,
aws_db_instance.xray_db,
aws_s3_bucket.artifactory_binarystore,
module.eks,
helm_release.metrics_server
]
}
## Create a Helm release for the JFrog Platform
## Leaving this as an example of how to deploy the JFrog Platform with Helm using multiple values files
# resource "kubernetes_namespace" "jfrog_namespace" {
# metadata {
# annotations = {
# name = var.namespace
# }
#
# labels = {
# app = "jfrog"
# }
#
# name = var.namespace
# }
# }
#
# # Create a Helm release for the JFrog Platform
# resource "helm_release" "jfrog_platform" {
# name = var.namespace
# chart = "jfrog/jfrog-platform"
# version = var.jfrog_platform_chart_version
# namespace = var.namespace
#
# depends_on = [
# aws_db_instance.artifactory_db,
# aws_s3_bucket.artifactory_binarystore,
# module.eks,
# helm_release.metrics_server
# ]
#
# values = [
# file("${path.module}/jfrog-values.yaml")
# ]
#
# set {
# name = "artifactory.artifactory.persistence.awsS3V3.region"
# value = var.region
# }
#
# set {
# name = "artifactory.artifactory.persistence.awsS3V3.bucketName"
# value = aws_s3_bucket.artifactory_binarystore.bucket
# }
#
# set {
# name = "artifactory.database.url"
# value = "jdbc:postgresql://${aws_db_instance.artifactory_db.endpoint}/${var.artifactory_db_name}"
# }
#
# set {
# name = "artifactory.database.user"
# value = var.artifactory_db_username
# }
#
# set {
# name = "artifactory.database.password"
# value = var.artifactory_db_password
# }
#
# set {
# name = "xray.database.url"
# value = "postgres://${aws_db_instance.xray_db.endpoint}/${var.xray_db_name}?sslmode="
# }
#
# set {
# name = "xray.database.user"
# value = var.xray_db_username
# }
#
# set {
# name = "xray.database.password"
# value = var.xray_db_password
# }
#
# # Wait for the release to complete deployment
# wait = true
#
# # Increase the timeout to 10 minutes for the JFrog Platform to deploy
# timeout = 600
# }
#
# data "kubernetes_resources" "nginx_service" {
# api_version = "v1"
# kind = "Service"
# namespace = var.namespace
# label_selector = "component=nginx"
#
# depends_on = [
# helm_release.jfrog_platform
# ]
# }