Skip to content

Commit 790a165

Browse files
authored
feat: Byoc op project (#9)
* feat: aws byoc op module * feat: example to create byoc i project
1 parent a7d6ccf commit 790a165

26 files changed

+2296
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
data "zillizcloud_byoc_op_project_settings" "this" {
2+
project_id = var.project_id
3+
data_plane_id = var.dataplane_id
4+
}
5+
6+
7+
module "aws_byoc_op" {
8+
source = "../../modules/aws_byoc_op"
9+
aws_region = trimprefix(data.zillizcloud_byoc_op_project_settings.this.region, "aws-")
10+
11+
vpc_cidr = var.vpc_cidr
12+
enable_private_link = var.enable_private_link
13+
eks_access_cidrs = [
14+
"0.0.0.0/0"
15+
]
16+
dataplane_id = data.zillizcloud_byoc_op_project_settings.this.data_plane_id
17+
k8s_node_groups = data.zillizcloud_byoc_op_project_settings.this.node_quotas
18+
agent_config = {
19+
auth_token = data.zillizcloud_byoc_op_project_settings.this.op_config.token
20+
tag = data.zillizcloud_byoc_op_project_settings.this.op_config.agent_image_url
21+
}
22+
23+
}
24+
25+
resource "zillizcloud_byoc_op_project_agent" "this" {
26+
project_id = data.zillizcloud_byoc_op_project_settings.this.project_id
27+
data_plane_id = data.zillizcloud_byoc_op_project_settings.this.data_plane_id
28+
}
29+
30+
31+
resource "zillizcloud_byoc_op_project" "this" {
32+
33+
lifecycle {
34+
ignore_changes = [data_plane_id, project_id, aws, ext_config]
35+
36+
}
37+
38+
# required
39+
data_plane_id = data.zillizcloud_byoc_op_project_settings.this.data_plane_id
40+
# required
41+
project_id = data.zillizcloud_byoc_op_project_settings.this.project_id
42+
# required
43+
ext_config = "ext_config"
44+
45+
aws = {
46+
# option
47+
region = data.zillizcloud_byoc_op_project_settings.this.region
48+
49+
# option
50+
network = {
51+
vpc_id = module.aws_byoc_op.vpc_id
52+
subnet_ids = module.aws_byoc_op.private_subnet_ids
53+
security_group_ids = [module.aws_byoc_op.security_group_id]
54+
vpc_endpoint_id = var.enable_private_link ? module.aws_byoc_op.byoc_endpoint : null
55+
}
56+
role_arn = {
57+
storage = module.aws_byoc_op.storage_role_arn
58+
eks = module.aws_byoc_op.eks_addon_role_arn
59+
cross_account = module.aws_byoc_op.maintaince_role_arn
60+
}
61+
storage = {
62+
bucket_id = module.aws_byoc_op.s3_bucket_ids
63+
}
64+
65+
instances = {
66+
core_vm = "m6i.2xlarge"
67+
fundamental_vm = "m6i.2xlarge"
68+
search_vm = "m6i.2xlarge"
69+
}
70+
}
71+
72+
depends_on = [data.zillizcloud_byoc_op_project_settings.this, zillizcloud_byoc_op_project_agent.this, module.aws_byoc_op]
73+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
terraform {
2+
required_version = ">=1.6.0"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = "5.82.1"
8+
version = ">=5.20.0"
9+
}
10+
zillizcloud = {
11+
source = "zilliztech/zillizcloud"
12+
version = "~> 0.3.6"
13+
}
14+
}
15+
}
16+
17+
provider "aws" {
18+
region = var.aws_region
19+
}
20+
21+
provider "zillizcloud" {
22+
host_address = "https://api.cloud-uat3.zilliz.com/v2"
23+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
variable "project_id" {
2+
description = "The ID of the byoc project"
3+
type = string
4+
nullable = false
5+
}
6+
7+
8+
variable "dataplane_id" {
9+
description = "The ID of the data plane"
10+
type = string
11+
nullable = false
12+
}
13+
14+
variable "vpc_cidr" {
15+
description = "The CIDR block for the customer VPC"
16+
type = string
17+
nullable = false
18+
19+
validation {
20+
condition = var.vpc_cidr != ""
21+
error_message = "variable vpc_cidr cannot be empty."
22+
}
23+
}
24+
25+
variable "enable_private_link" {
26+
description = "Enable private link for the byoc project"
27+
type = bool
28+
default = true
29+
}
30+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: v2
2+
name: cloud-agent
3+
description: Cloud-agent for Zilliz BYOInfra
4+
5+
type: application
6+
version: 0.0.1
7+
appVersion: "0.0.1"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apiVersion: v1
2+
data:
3+
application.yml: |
4+
server:
5+
port: 9501
6+
additionalPorts: 9502,9503
7+
8+
byoc:
9+
tunnel:
10+
serverHost: {{ .Values.config.tunnel.serverHost }}
11+
authToken: "{{ .Values.config.tunnel.authToken }}"
12+
dataPlaneId: {{ .Values.config.tunnel.dataPlaneId }}
13+
14+
spring:
15+
jackson:
16+
mapper:
17+
accept-case-insensitive-properties: true
18+
19+
profiles:
20+
active: dev
21+
application:
22+
name: cloud-agent
23+
24+
kind: ConfigMap
25+
metadata:
26+
name: cloud-agent
27+
namespace: vdc
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
annotations:
5+
configmap.reloader.stakater.com/reload: cloud-agent
6+
name: cloud-agent
7+
namespace: vdc
8+
spec:
9+
replicas: 1
10+
selector:
11+
matchLabels:
12+
app.kubernetes.io/instance: vdc
13+
app.kubernetes.io/name: cloud-agent
14+
template:
15+
metadata:
16+
labels:
17+
app.kubernetes.io/instance: vdc
18+
app.kubernetes.io/name: cloud-agent
19+
spec:
20+
containers:
21+
- env:
22+
- name: SPRING_CONFIG_LOCATION
23+
value: file:///spring-config/application.yml
24+
- name: BYOC_K8S_TOKEN
25+
value: "{{ .Values.config.tunnel.k8sToken }}"
26+
- name: BYOC_K8S_KEY
27+
value: "{{ .Values.config.tunnel.authToken }}"
28+
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
29+
imagePullPolicy: Always
30+
livenessProbe:
31+
failureThreshold: 5
32+
httpGet:
33+
path: /cloud/check_healthy_db
34+
port: 9501
35+
initialDelaySeconds: 90
36+
periodSeconds: 30
37+
successThreshold: 1
38+
name: cloud-agent
39+
ports:
40+
- containerPort: 9501
41+
- containerPort: 9502
42+
- containerPort: 9503
43+
- containerPort: 9504
44+
readinessProbe:
45+
httpGet:
46+
path: /cloud/check_healthy_db
47+
port: 9501
48+
initialDelaySeconds: 10
49+
periodSeconds: 10
50+
timeoutSeconds: 5
51+
resources:
52+
limits:
53+
cpu: 2
54+
memory: 2Gi
55+
requests:
56+
cpu: 1
57+
memory: 1Gi
58+
volumeMounts:
59+
- mountPath: /spring-config
60+
name: spring-config
61+
nodeSelector:
62+
node-role/vdc: "true"
63+
tolerations:
64+
- effect: NoExecute
65+
key: node-role/vdc
66+
operator: Equal
67+
value: "true"
68+
volumes:
69+
- configMap:
70+
name: cloud-agent
71+
name: spring-config
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
image:
2+
repository: ""
3+
tag: ""
4+
5+
config:
6+
tunnel:
7+
serverHost: ""
8+
authToken: ""
9+
dataPlaneId: ""
10+
k8sToken: ""

modules/aws_byoc_op/conf.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
vpce_service_ids:
2+
us-west-2: vpce-svc-0dfdaa96b9114453c
3+
eu-central-1: vpce-svc-0d5ce1ec4decbc7df
4+
private_zone_name: byoc-uat.zillizcloud.com
5+
agent_config:
6+
server_host: zilliz-byoc-us.byoc-uat.zillizcloud.com
7+
repository: 306787409409.dkr.ecr.us-west-2.amazonaws.com/zilliz-byoc/vdc/cloud-agent

modules/aws_byoc_op/data.tf

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
data "aws_caller_identity" "current" {}
2+
3+
locals {
4+
config = yamldecode(file("${path.module}/conf.yaml"))
5+
// available zones
6+
azs = slice(data.aws_availability_zones.available.names, 0, 3)
7+
8+
// auto-generate private subnets cidr
9+
private_subnets = [for k, v in local.azs : cidrsubnet(var.vpc_cidr, 2, k)]
10+
public_subnets = [cidrsubnet(cidrsubnet(var.vpc_cidr, 2, 3), 6, 62)]
11+
// security group ingress and egress rules
12+
sg_egress_ports = [443]
13+
sg_ingress_protocol = ["tcp", "udp"]
14+
sg_egress_protocol = ["tcp", "udp"]
15+
16+
// eks output
17+
eks_oidc_url = replace(aws_eks_cluster.zilliz_byoc_cluster.identity[0].oidc[0].issuer, "https://", "")
18+
// bucket output
19+
bucket_id = module.s3_bucket["milvus"].s3_bucket_id
20+
21+
// input parameters:
22+
vpc_cidr = var.vpc_cidr
23+
region = var.aws_region
24+
25+
dataplane_id = var.dataplane_id
26+
27+
// node groups
28+
29+
k8s_node_groups = var.k8s_node_groups
30+
31+
account_id = data.aws_caller_identity.current.account_id
32+
33+
34+
}

modules/aws_byoc_op/eks.tf

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# aws_eks_cluster.my_cluster:
2+
resource "aws_eks_cluster" "zilliz_byoc_cluster" {
3+
bootstrap_self_managed_addons = false
4+
enabled_cluster_log_types = []
5+
name = local.dataplane_id
6+
7+
role_arn = aws_iam_role.eks_role.arn
8+
tags = {
9+
10+
"Vendor" = "zilliz-byoc"
11+
}
12+
tags_all = {
13+
14+
"Vendor" = "zilliz-byoc"
15+
}
16+
# version = "1.31"
17+
18+
access_config {
19+
authentication_mode = "CONFIG_MAP"
20+
bootstrap_cluster_creator_admin_permissions = true
21+
}
22+
23+
# kubernetes_network_config {
24+
# ip_family = "ipv4"
25+
# service_ipv4_cidr = "10.255.0.0/16"
26+
# }
27+
28+
upgrade_policy {
29+
support_type = "EXTENDED"
30+
}
31+
32+
vpc_config {
33+
endpoint_private_access = true
34+
endpoint_public_access = true
35+
public_access_cidrs = var.eks_access_cidrs
36+
security_group_ids = [
37+
aws_security_group.zilliz_byoc_sg.id
38+
]
39+
subnet_ids = module.vpc.private_subnets
40+
}
41+
}
42+
43+
44+
# aws_eks_addon.kube-proxy:
45+
resource "aws_eks_addon" "kube-proxy" {
46+
addon_name = "kube-proxy"
47+
# addon_version = "v1.27.6-eksbuild.2"
48+
cluster_name = local.dataplane_id
49+
50+
depends_on = [ aws_eks_cluster.zilliz_byoc_cluster ]
51+
52+
tags = {
53+
54+
"Vendor" = "zilliz-byoc"
55+
}
56+
tags_all = {
57+
58+
"Vendor" = "zilliz-byoc"
59+
}
60+
}
61+
62+
# aws_eks_addon.vpc-cni:
63+
resource "aws_eks_addon" "vpc-cni" {
64+
addon_name = "vpc-cni"
65+
# addon_version = "v1.15.3-eksbuild.1"
66+
cluster_name = local.dataplane_id
67+
68+
depends_on = [ aws_eks_cluster.zilliz_byoc_cluster ]
69+
70+
tags = {
71+
72+
"Vendor" = "zilliz-byoc"
73+
}
74+
tags_all = {
75+
76+
"Vendor" = "zilliz-byoc"
77+
}
78+
}
79+
80+
data "aws_eks_cluster_auth" "example" {
81+
name = aws_eks_cluster.zilliz_byoc_cluster.name
82+
}
83+
84+
85+
data "tls_certificate" "eks" {
86+
url = aws_eks_cluster.zilliz_byoc_cluster.identity[0].oidc[0].issuer
87+
}
88+
89+
resource "aws_iam_openid_connect_provider" "eks" {
90+
client_id_list = ["sts.amazonaws.com"]
91+
thumbprint_list = [data.tls_certificate.eks.certificates[0].sha1_fingerprint]
92+
url = aws_eks_cluster.zilliz_byoc_cluster.identity[0].oidc[0].issuer
93+
94+
tags = {
95+
"Vendor" = "zilliz-byoc"
96+
}
97+
}
98+

0 commit comments

Comments
 (0)