-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
166 lines (153 loc) · 5.55 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# --------------------------------------------------------------------------
#
# Copyright 2023-Present Sonatype Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# --------------------------------------------------------------------------
################################################################################
# Load Vendor Corp Shared Infra
################################################################################
module "shared" {
source = "git::ssh://[email protected]/vendorcorp/terraform-shared-infrastructure.git?ref=v0.3.2"
environment = var.environment
default_eks_cluster_name = "vendorcorp-us-east-2-63pl3dng"
}
################################################################################
# PostgreSQL Provider
################################################################################
provider "postgresql" {
scheme = "awspostgres"
host = module.shared.pgsql_cluster_endpoint_write
port = module.shared.pgsql_cluster_port
database = "postgres"
username = module.shared.pgsql_cluster_master_username
password = var.pgsql_password
sslmode = "require"
connect_timeout = 15
superuser = false
}
################################################################################
# Connect to our k8s Cluster
################################################################################
provider "kubernetes" {
config_path = "~/.kube/config"
config_context = module.shared.eks_cluster_arn
}
################################################################################
# Create NXIQ HA Cluster
################################################################################
module "nxiq_ha_cluster" {
source = "git::ssh://[email protected]/vendorcorp/terraform-aws-eks-nxiq.git?ref=v0.1.0"
default_resource_tags = var.default_resource_tags
nxiq_name = terraform.workspace
nxiq_license_file = "${path.module}/sonatype-license.lic"
nxiq_version = "1.158.0"
pg_hostname = module.shared.pgsql_cluster_endpoint_write
pg_port = module.shared.pgsql_cluster_port
pg_admin_username = module.shared.pgsql_cluster_master_username
pg_admin_password = var.pgsql_password
replica_count = 2
}
################################################################################
# Create Ingress for NXIQ
################################################################################
resource "kubernetes_ingress_v1" "nxiq-ha" {
metadata {
name = "nxiq-ha-ingress"
namespace = module.nxiq_ha_cluster.nxiq_ha_k8s_namespace
labels = {
app = "nxiq-ha"
}
annotations = {
"kubernetes.io/ingress.class" = "alb"
"alb.ingress.kubernetes.io/group.name" = "vencorcorp-shared-core"
"alb.ingress.kubernetes.io/scheme" = "internal"
"alb.ingress.kubernetes.io/certificate-arn" = module.shared.vendorcorp_net_cert_arn
}
}
spec {
rule {
host = "iq-${terraform.workspace}.corp.${module.shared.dns_zone_public_name}"
http {
path {
path = "/*"
backend {
service {
name = module.nxiq_ha_cluster.nxiq_ha_k8s_service_name
port {
number = 8070
}
}
}
}
}
}
}
wait_for_load_balancer = true
}
resource "kubernetes_ingress_v1" "nxiq-ha-admin" {
metadata {
name = "nxiq-ha-admin-ingress"
namespace = module.nxiq_ha_cluster.nxiq_ha_k8s_namespace
labels = {
app = "nxiq-ha"
}
annotations = {
"kubernetes.io/ingress.class" = "alb"
"alb.ingress.kubernetes.io/group.name" = "vencorcorp-shared-core"
"alb.ingress.kubernetes.io/scheme" = "internal"
"alb.ingress.kubernetes.io/certificate-arn" = module.shared.vendorcorp_net_cert_arn
}
}
spec {
rule {
host = "iq-admin-${terraform.workspace}.corp.${module.shared.dns_zone_public_name}"
http {
path {
path = "/*"
backend {
service {
name = module.nxiq_ha_cluster.nxiq_ha_k8s_admin_service_name
port {
number = 8071
}
}
}
}
}
}
}
wait_for_load_balancer = true
}
################################################################################
# Add/Update DNS for Load Balancer Ingress
################################################################################
resource "aws_route53_record" "nxiq_dns" {
zone_id = module.shared.dns_zone_public_id
name = "iq-${terraform.workspace}.corp"
type = "CNAME"
ttl = "300"
records = [
kubernetes_ingress_v1.nxiq-ha.status.0.load_balancer.0.ingress.0.hostname
]
}
resource "aws_route53_record" "nxiq_admin_dns" {
zone_id = module.shared.dns_zone_public_id
name = "iq-admin-${terraform.workspace}.corp"
type = "CNAME"
ttl = "300"
records = [
kubernetes_ingress_v1.nxiq-ha-admin.status.0.load_balancer.0.ingress.0.hostname
]
}