Skip to content

Commit 7fe2032

Browse files
committed
add db deps
1 parent 52c53cc commit 7fe2032

File tree

19 files changed

+472
-69
lines changed

19 files changed

+472
-69
lines changed

.werft/installer-tests.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const TEST_CONFIGURATIONS: { [name: string]: TestConfig } = {
9292
PHASES: [
9393
"STANDARD_AKS_CLUSTER",
9494
"CERT_MANAGER",
95-
"AZURE_ISSUER",
95+
"CLUSTER_ISSUER",
9696
"EXTERNALDNS",
9797
"ADD_NS_RECORD",
9898
"GENERATE_KOTS_CONFIG",
@@ -108,13 +108,11 @@ const TEST_CONFIGURATIONS: { [name: string]: TestConfig } = {
108108
DESCRIPTION: "Create an EKS cluster",
109109
PHASES: [
110110
"STANDARD_GKE_CLUSTER",
111+
"STANDARD_EKS_CLUSTER", // this only creates aws dependencies for now
111112
"CERT_MANAGER",
112113
"EXTERNALDNS",
113-
// TODO phases are:
114-
// external dns with aws
115-
// 1) register domains in AWS, associate with route53
116-
// 2) add the associated ns record to gcp(since we use gitpod-self-hsoted.com domain)
117-
// 3) create cluster issuer with route53 as solver
114+
"CLUSTER_ISSUER",
115+
"ADD_NS_RECORD",
118116
"GENERATE_KOTS_CONFIG",
119117
"INSTALL_GITPOD",
120118
// "CHECK_INSTALLATION",
@@ -171,18 +169,18 @@ const INFRA_PHASES: { [name: string]: InfraConfig } = {
171169
)} db=${randomize("db", cloud)}`,
172170
description: `Generate KOTS Config file`,
173171
},
174-
AZURE_ISSUER: {
175-
phase: "setup-azure-cluster-issuer",
172+
CLUSTER_ISSUER: {
173+
phase: `setup-azure-cluster-issuer cloud=${cloud}`,
176174
makeTarget: "azure-issuer",
177175
description: "Deploys ClusterIssuer for azure",
178176
},
179177
EXTERNALDNS: {
180178
phase: "external-dns",
181-
makeTarget: `external-dns provider=${cloud}`,
179+
makeTarget: `external-dns cloud=${cloud}`,
182180
description: `Deploys external-dns with ${cloud} provider`,
183181
},
184182
ADD_NS_RECORD: {
185-
phase: "add-ns-record",
183+
phase: `add-ns-record cloud=${cloud}`,
186184
makeTarget: "add-ns-record",
187185
description: "Adds NS record for subdomain under gitpod-self-hosted.com",
188186
},
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
resource "aws_db_subnet_group" "gitpod_subnets" {
2+
subnet_ids = data.aws_subnet_ids.subnet_ids.ids
3+
}
4+
5+
resource "aws_security_group" "rdssg" {
6+
name = "rdssg"
7+
vpc_id = module.vpc.vpc_id
8+
9+
ingress {
10+
from_port = 0
11+
to_port = 3306
12+
protocol = "tcp"
13+
cidr_blocks = ["0.0.0.0/0"]
14+
}
15+
16+
egress {
17+
from_port = 0
18+
to_port = 0
19+
protocol = "-1"
20+
cidr_blocks = ["0.0.0.0/0"]
21+
}
22+
}
23+
24+
resource "aws_db_instance" "gitpod" {
25+
allocated_storage = 10
26+
max_allocated_storage = 100
27+
engine = "mysql"
28+
engine_version = "5.7"
29+
instance_class = "db.t3.micro"
30+
vpc_security_group_ids = [ aws_security_group.rdssg.id ]
31+
identifier = "db-${var.cluster_name}"
32+
name = "gitpod"
33+
username = "gitpod"
34+
password = "gitpod-qwat" # we can replace this with https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/secretsmanager_secret_version
35+
parameter_group_name = "default.mysql5.7"
36+
skip_final_snapshot = true
37+
db_subnet_group_name = aws_db_subnet_group.gitpod_subnets.name
38+
publicly_accessible = true
39+
}

install/infra/terraform/eks/dns.tf

Lines changed: 63 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,51 @@
1-
variable "domain_name" {}
2-
variable "cluster_name" {}
1+
resource "aws_route53_zone" "gitpod" {
2+
force_destroy = true
3+
name = var.domain_name
34

4-
terraform {
5-
required_providers {
6-
aws = {
7-
version = " ~> 3.0"
8-
source = "registry.terraform.io/hashicorp/aws"
9-
}
5+
tags = {
6+
Environment = "test"
107
}
118
}
129

13-
provider "aws" {
14-
region = "eu-west-1"
10+
# This creates an SSL certificate
11+
resource "aws_acm_certificate" "gitpod" {
12+
domain_name = var.domain_name
13+
subject_alternative_names = ["*.ws.${var.domain_name}", "ws.${var.domain_name}"]
14+
validation_method = "DNS"
1515
}
1616

17-
resource "aws_route53_zone" "gitpod" {
18-
name = var.domain_name
17+
# This is a DNS record for the ACM certificate validation to prove we own the domain
18+
#
19+
# This example, we make an assumption that the certificate is for a single domain name so can just use the first value of the
20+
# domain_validation_options. It allows the terraform to apply without having to be targeted.
21+
# This is somewhat less complex than the example at https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/acm_certificate_validation
22+
# - that above example, won't apply without targeting
1923

20-
tags = {
21-
Environment = "test"
22-
}
24+
resource "aws_route53_record" "cert_validation" {
25+
allow_overwrite = true
26+
name = tolist(aws_acm_certificate.gitpod.domain_validation_options)[0].resource_record_name
27+
type = tolist(aws_acm_certificate.gitpod.domain_validation_options)[0].resource_record_type
28+
zone_id = "${resource.aws_route53_zone.gitpod.zone_id}"
29+
records = [tolist(aws_acm_certificate.gitpod.domain_validation_options)[0].resource_record_value]
30+
ttl = 60
31+
}
32+
33+
resource "aws_route53_record" "cert_validation_1" {
34+
allow_overwrite = true
35+
name = tolist(aws_acm_certificate.gitpod.domain_validation_options)[1].resource_record_name
36+
type = tolist(aws_acm_certificate.gitpod.domain_validation_options)[1].resource_record_type
37+
zone_id = "${resource.aws_route53_zone.gitpod.zone_id}"
38+
records = [tolist(aws_acm_certificate.gitpod.domain_validation_options)[1].resource_record_value]
39+
ttl = 60
40+
}
41+
42+
resource "aws_route53_record" "cert_validation_2" {
43+
allow_overwrite = true
44+
name = tolist(aws_acm_certificate.gitpod.domain_validation_options)[2].resource_record_name
45+
type = tolist(aws_acm_certificate.gitpod.domain_validation_options)[2].resource_record_type
46+
zone_id = "${resource.aws_route53_zone.gitpod.zone_id}"
47+
records = [tolist(aws_acm_certificate.gitpod.domain_validation_options)[2].resource_record_value]
48+
ttl = 60
2349
}
2450

2551
resource "aws_iam_policy" "gitpod" {
@@ -39,6 +65,15 @@ resource "aws_iam_policy" "gitpod" {
3965
"arn:aws:route53:::hostedzone/*"
4066
]
4167
},
68+
{
69+
Effect = "Allow",
70+
Action = [
71+
"route53:GetChange",
72+
],
73+
Resource = [
74+
"arn:aws:route53:::change/*"
75+
]
76+
},
4277
{
4378
Effect = "Allow",
4479
Action = [
@@ -51,26 +86,20 @@ resource "aws_iam_policy" "gitpod" {
5186
})
5287
}
5388

54-
resource "aws_iam_role" "gitpod" {
55-
name = "iam-route53-${var.cluster_name}"
56-
57-
assume_role_policy = <<POLICY
58-
{
59-
"Version": "2012-10-17",
60-
"Statement": [
61-
{
62-
"Effect": "Allow",
63-
"Principal": {
64-
"Service": "ec2.amazonaws.com"
65-
},
66-
"Action": "sts:AssumeRole"
67-
}
68-
]
89+
resource "aws_iam_user_policy_attachment" "test-attach" {
90+
user = aws_iam_user.edns.name
91+
policy_arn = aws_iam_policy.gitpod.arn
6992
}
70-
POLICY
93+
94+
resource "aws_iam_user" "edns" {
95+
name = "${var.cluster_name}-external-dns"
96+
force_destroy = true
97+
98+
tags = {
99+
env = "test"
100+
}
71101
}
72102

73-
resource "aws_iam_role_policy_attachment" "route53" {
74-
policy_arn = resource.aws_iam_policy.gitpod.arn
75-
role = aws_iam_role.gitpod.name
103+
resource "aws_iam_access_key" "edns" {
104+
user = aws_iam_user.edns.name
76105
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# get all available AZs in our region
2+
data "aws_availability_zones" "available_azs" {
3+
state = "available"
4+
}
5+
6+
# reserve Elastic IP to be used in our NAT gateway
7+
resource "aws_eip" "nat_gw_elastic_ip" {
8+
vpc = true
9+
10+
tags = {
11+
Name = "${var.cluster_name}-nat-eip"
12+
}
13+
}
14+
15+
# create VPC using the official AWS module
16+
module "vpc" {
17+
source = "terraform-aws-modules/vpc/aws"
18+
version = "3.14.0"
19+
20+
name = "${var.cluster_name}-vpc"
21+
cidr = var.main_network_block
22+
azs = data.aws_availability_zones.available_azs.names
23+
24+
private_subnets = [
25+
# this loop will create a one-line list as ["10.0.0.0/20", "10.0.16.0/20", "10.0.32.0/20", ...]
26+
# with a length depending on how many Zones are available
27+
for zone_id in data.aws_availability_zones.available_azs.zone_ids :
28+
cidrsubnet(var.main_network_block, var.subnet_prefix_extension, tonumber(substr(zone_id, length(zone_id) - 1, 1)) - 1)
29+
]
30+
31+
public_subnets = [
32+
# this loop will create a one-line list as ["10.0.128.0/20", "10.0.144.0/20", "10.0.160.0/20", ...]
33+
# with a length depending on how many Zones are available
34+
# there is a zone Offset variable, to make sure no collisions are present with private subnet blocks
35+
for zone_id in data.aws_availability_zones.available_azs.zone_ids :
36+
cidrsubnet(var.main_network_block, var.subnet_prefix_extension, tonumber(substr(zone_id, length(zone_id) - 1, 1)) + var.zone_offset - 1)
37+
]
38+
39+
# enable single NAT Gateway to save some money
40+
# WARNING: this could create a single point of failure, since we are creating a NAT Gateway in one AZ only
41+
# feel free to change these options if you need to ensure full Availability without the need of running 'terraform apply'
42+
# reference: https://registry.terraform.io/modules/terraform-aws-modules/vpc/aws/2.44.0#nat-gateway-scenarios
43+
enable_nat_gateway = true
44+
single_nat_gateway = true
45+
one_nat_gateway_per_az = false
46+
enable_dns_hostnames = true
47+
reuse_nat_ips = true
48+
external_nat_ip_ids = [aws_eip.nat_gw_elastic_ip.id]
49+
50+
# add VPC/Subnet tags required by EKS
51+
tags = {
52+
"kubernetes.io/cluster/${var.cluster_name}" = "shared"
53+
}
54+
public_subnet_tags = {
55+
"kubernetes.io/cluster/${var.cluster_name}" = "shared"
56+
"kubernetes.io/role/elb" = "1"
57+
}
58+
private_subnet_tags = {
59+
"kubernetes.io/cluster/${var.cluster_name}" = "shared"
60+
"kubernetes.io/role/internal-elb" = "1"
61+
}
62+
}
63+
64+
# create security group to be used later by the ingress ALB
65+
resource "aws_security_group" "alb" {
66+
name = "${var.cluster_name}-alb"
67+
vpc_id = module.vpc.vpc_id
68+
69+
ingress {
70+
description = "http"
71+
from_port = 80
72+
to_port = 80
73+
protocol = "tcp"
74+
cidr_blocks = ["0.0.0.0/0"]
75+
ipv6_cidr_blocks = ["::/0"]
76+
}
77+
78+
ingress {
79+
description = "https"
80+
from_port = 443
81+
to_port = 443
82+
protocol = "tcp"
83+
cidr_blocks = ["0.0.0.0/0"]
84+
ipv6_cidr_blocks = ["::/0"]
85+
}
86+
87+
egress {
88+
from_port = 0
89+
to_port = 0
90+
protocol = "-1"
91+
cidr_blocks = ["0.0.0.0/0"]
92+
ipv6_cidr_blocks = ["::/0"]
93+
}
94+
95+
tags = {
96+
"Name" = "${var.cluster_name}-alb"
97+
}
98+
}
99+
100+
data "aws_subnet_ids" "subnet_ids" {
101+
depends_on = [module.vpc]
102+
vpc_id = module.vpc.vpc_id
103+
104+
}

install/infra/terraform/eks/output.tf

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
data "aws_caller_identity" "current" {}
2-
31
output "external_dns_settings" {
42
value = [
53
{
@@ -11,20 +9,63 @@ output "external_dns_settings" {
119
"value" = "eu-west-1"
1210
},
1311
{
14-
"name" = "aws.roleArn",
15-
"value" = resource.aws_iam_role.gitpod.arn
12+
"name" = "aws.credentials.secretKey",
13+
"value" = aws_iam_access_key.edns.secret
14+
},
15+
{
16+
"name" = "aws.credentials.accessKey",
17+
"value" = aws_iam_access_key.edns.id
1618
}
1719
]
1820
}
1921

22+
output "secretAccessKey" {
23+
value = try("${aws_iam_access_key.edns.secret}", "")
24+
}
25+
2026
output "cert_manager_issuer" {
2127
value = try({
2228
region = "eu-west-1"
23-
role = resource.aws_iam_role.gitpod.arn
24-
hostedZoneID = resource.aws_route53_zone.gitpod.zone_id
29+
secretAccessKeySecretRef = {
30+
name = "route53-credentials"
31+
key = "secret-access-key"
32+
}
33+
34+
hostedZoneID = aws_route53_zone.gitpod.zone_id
35+
accessKeyID = aws_iam_access_key.edns.id
2536
}, {})
2637
}
2738

2839
output "domain_nameservers" {
29-
value = resource.aws_route53_zone.gitpod.name_servers
40+
value = formatlist("%s.", resource.aws_route53_zone.gitpod.name_servers)
41+
}
42+
43+
output "database" {
44+
sensitive = true
45+
value = try({
46+
host = "${aws_db_instance.gitpod.address}"
47+
password = "gitpod-qwat" # FIXME hardcoded at this point
48+
port = 3306
49+
username = "${aws_db_instance.gitpod.username}"
50+
}, {})
51+
}
52+
53+
output "registry" {
54+
sensitive = true
55+
value = try({
56+
server = data.aws_ecr_authorization_token.gitpod.proxy_endpoint
57+
username = data.aws_ecr_authorization_token.gitpod.user_name
58+
password = data.aws_ecr_authorization_token.gitpod.password
59+
}, {})
60+
}
61+
62+
output "storage" {
63+
sensitive = true
64+
value = try({
65+
access_key_id = aws_iam_access_key.bucket_storage_user.id
66+
secret_access_key = aws_iam_access_key.bucket_storage_user.secret
67+
region = aws_s3_bucket.gitpod-storage.region
68+
bucket_name = aws_s3_bucket.gitpod-storage.id
69+
endpoint = "s3.amazonaws.com"
70+
}, {})
3071
}

0 commit comments

Comments
 (0)