feat(rnd, infra): Add deployment for backend (#7612)

* Set up helm and tf for backend

* update helm charts and settings

* remove example files

* use latest tag

* delay and timeouts for probes

* env based pyro host

* default backend

* linting

* read from settings

* fix formatting

* update to use config
This commit is contained in:
Aarushi
2024-08-01 09:21:12 +01:00
committed by GitHub
parent ca7182403b
commit 3d54a9103c
28 changed files with 726 additions and 20 deletions

View File

@@ -15,7 +15,6 @@ from fastapi import (
)
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
from fastapi.staticfiles import StaticFiles
import autogpt_server.server.ws_api
from autogpt_server.data import block, db
@@ -34,7 +33,6 @@ from autogpt_server.server.model import (
SetGraphActiveVersion,
WsMessage,
)
from autogpt_server.util.data import get_frontend_path
from autogpt_server.util.lock import KeyedMutex
from autogpt_server.util.service import AppService, expose, get_service_client
from autogpt_server.util.settings import Settings
@@ -191,12 +189,6 @@ class AgentServer(AppService):
app.add_exception_handler(500, self.handle_internal_error) # type: ignore
app.mount(
path="/frontend",
app=StaticFiles(directory=get_frontend_path(), html=True),
name="example_files",
)
app.include_router(router)
@app.websocket("/ws")

View File

@@ -11,11 +11,14 @@ from tenacity import retry, stop_after_delay, wait_exponential
from autogpt_server.data import db
from autogpt_server.util.process import AppProcess
from autogpt_server.util.settings import Config
logger = logging.getLogger(__name__)
conn_retry = retry(stop=stop_after_delay(5), wait=wait_exponential(multiplier=0.1))
T = TypeVar("T")
pyro_host = Config().pyro_host
def expose(func: Callable) -> Callable:
def wrapper(*args, **kwargs):
@@ -33,7 +36,7 @@ class PyroNameServer(AppProcess):
def run(self):
try:
print("Starting NameServer loop")
nameserver.start_ns_loop()
nameserver.start_ns_loop(host=pyro_host, port=9090)
except KeyboardInterrupt:
print("Shutting down NameServer")
@@ -79,8 +82,8 @@ class AppService(AppProcess):
@conn_retry
def __start_pyro(self):
daemon = pyro.Daemon()
ns = pyro.locate_ns()
daemon = pyro.Daemon(host=pyro_host)
ns = pyro.locate_ns(host=pyro_host, port=9090)
uri = daemon.register(self)
ns.register(self.service_name, uri)
logger.warning(f"Service [{self.service_name}] Ready. Object URI = {uri}")

View File

@@ -53,6 +53,10 @@ class Config(UpdateTrackingModel["Config"], BaseSettings):
le=100,
description="Maximum number of workers to use for node execution within a single graph.",
)
pyro_host: str = Field(
default="localhost",
description="The default hostname of the Pyro server.",
)
# Add more configuration fields as needed
model_config = SettingsConfigDict(

View File

@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/

View File

@@ -0,0 +1,10 @@
apiVersion: v2
name: autogpt-server
description: A Helm chart for AutoGPT on Kubernetes
type: application
version: 0.1.0
appVersion: "1.0.0"

View File

@@ -0,0 +1,22 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "autogpt-server.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch its status by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "autogpt-server.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "autogpt-server.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "autogpt-server.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
{{- end }}

View File

@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "autogpt-server.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "autogpt-server.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "autogpt-server.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Common labels
*/}}
{{- define "autogpt-server.labels" -}}
helm.sh/chart: {{ include "autogpt-server.chart" . }}
{{ include "autogpt-server.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{/*
Selector labels
*/}}
{{- define "autogpt-server.selectorLabels" -}}
app.kubernetes.io/name: {{ include "autogpt-server.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{/*
Create the name of the service account to use
*/}}
{{- define "autogpt-server.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "autogpt-server.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

View File

@@ -0,0 +1,10 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "autogpt-server.fullname" . }}-config
labels:
{{- include "autogpt-server.labels" . | nindent 4 }}
data:
{{- range $key, $value := .Values.env }}
{{ $key }}: {{ $value | quote }}
{{- end }}

View File

@@ -0,0 +1,80 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "autogpt-server.fullname" . }}
labels:
{{- include "autogpt-server.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "autogpt-server.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "autogpt-server.labels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "autogpt-server.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
envFrom:
- configMapRef:
name: {{ include "autogpt-server.fullname" . }}-config
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: {{ .Values.service.port }}
protocol: TCP
livenessProbe:
{{- toYaml .Values.livenessProbe | nindent 12 }}
readinessProbe:
{{- toYaml .Values.readinessProbe | nindent 12 }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.volumeMounts }}
volumeMounts:
{{- toYaml . | nindent 12 }}
{{- end }}
- name: cloud-sql-proxy
image: "{{ .Values.cloudSqlProxy.image.repository }}:{{ .Values.cloudSqlProxy.image.tag }}"
args:
- "--structured-logs"
{{- if .Values.cloudSqlProxy.usePrivateIp }}
- "--private-ip"
{{- end }}
- "--port={{ .Values.cloudSqlProxy.port }}"
- "{{ .Values.cloudSqlProxy.instanceConnectionName }}"
{{- with .Values.volumes }}
volumes:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}

View File

@@ -0,0 +1,32 @@
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "autogpt-server.fullname" . }}
labels:
{{- include "autogpt-server.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "autogpt-server.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}

View File

@@ -0,0 +1,61 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "autogpt-server.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
{{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }}
{{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}}
{{- end }}
{{- end }}
{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1
{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
{{- include "autogpt-server.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}
ingressClassName: {{ .Values.ingress.className }}
{{- end }}
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ .path }}
{{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }}
pathType: {{ .pathType }}
{{- end }}
backend:
{{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }}
service:
name: {{ $fullName }}
port:
number: {{ $svcPort }}
{{- else }}
serviceName: {{ $fullName }}
servicePort: {{ $svcPort }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}

View File

@@ -0,0 +1,7 @@
apiVersion: networking.gke.io/v1
kind: ManagedCertificate
metadata:
name: {{ include "autogpt-server.fullname" . }}-cert
spec:
domains:
- {{ .Values.domain }}

View File

@@ -0,0 +1,19 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "autogpt-server.fullname" . }}
labels:
{{- include "autogpt-server.labels" . | nindent 4 }}
{{- with .Values.service.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
{{- include "autogpt-server.selectorLabels" . | nindent 4 }}

View File

@@ -0,0 +1,13 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "autogpt-server.serviceAccountName" . }}
labels:
{{- include "autogpt-server.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
automountServiceAccountToken: {{ .Values.serviceAccount.automount }}
{{- end }}

View File

@@ -0,0 +1,15 @@
apiVersion: v1
kind: Pod
metadata:
name: "{{ include "autogpt-server.fullname" . }}-test-connection"
labels:
{{- include "autogpt-server.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": test
spec:
containers:
- name: wget
image: busybox
command: ['wget']
args: ['{{ include "autogpt-server.fullname" . }}:{{ .Values.service.port }}']
restartPolicy: Never

View File

@@ -0,0 +1,83 @@
# dev values, overwrite base values as needed.
image:
repository: us-east1-docker.pkg.dev/agpt-dev/agpt-server-dev/agpt-server-dev
pullPolicy: Always
tag: "latest"
serviceAccount:
annotations:
iam.gke.io/gcp-service-account: "dev-agpt-server-sa@agpt-dev.iam.gserviceaccount.com"
name: "dev-agpt-server-sa"
service:
type: ClusterIP
port: 8000
targetPort: 8000
annotations:
cloud.google.com/neg: '{"ingress": true}'
ingress:
enabled: true
className: "gce"
annotations:
kubernetes.io/ingress.class: gce
kubernetes.io/ingress.global-static-ip-name: "agpt-dev-agpt-server-ip"
networking.gke.io/managed-certificates: "autogpt-server-cert"
kubernetes.io/ingress.allow-http: "true"
hosts:
- host: dev-server.agpt.co
paths:
- path: /
pathType: Prefix
backend:
service:
name: autogpt-server
port: 8000
defaultBackend:
service:
name: autogpt-server
port:
number: 8000
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 500m
memory: 512Mi
livenessProbe:
httpGet:
path: /docs
port: 8000
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 6
readinessProbe:
httpGet:
path: /docs
port: 8000
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 6
domain: "dev-server.agpt.co"
cloudSqlProxy:
image:
repository: gcr.io/cloud-sql-connectors/cloud-sql-proxy
tag: 2.11.4
instanceConnectionName: "agpt-dev:us-central1:agpt-server-dev"
port: 5432
resources:
requests:
memory: "2Gi"
cpu: "1"
env:
APP_ENV: "dev"
PYRO_HOST: "0.0.0.0"

View File

@@ -0,0 +1,87 @@
# base values, environment specific variables should be specified/overwritten in environment values
replicaCount: 1
image:
repository: us-east1-docker.pkg.dev/agpt-dev/agpt-server-dev/agpt-server-dev
pullPolicy: IfNotPresent
tag: "latest"
imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""
serviceAccount:
create: true
automount: true
annotations: {}
name: ""
podAnnotations: {}
podLabels: {}
podSecurityContext: {}
securityContext: {}
service:
type: ClusterIP
port: 80
ingress:
enabled: false
className: ""
annotations: {}
hosts:
- host: chart-example.local
paths:
- path: /
pathType: ImplementationSpecific
tls: []
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 500m
memory: 512Mi
livenessProbe:
httpGet:
path: /
port: http
readinessProbe:
httpGet:
path: /
port: http
autoscaling:
enabled: false
minReplicas: 1
maxReplicas: 100
targetMemoryUtilizationPercentage: 80
volumes: []
volumeMounts: []
nodeSelector: {}
tolerations: []
affinity: {}
domain: ""
cloudSqlProxy:
image:
repository: gcr.io/cloud-sql-connectors/cloud-sql-proxy
tag: 2.11.4
instanceConnectionName: ""
port: 5432
resources:
requests:
memory: "2Gi"
cpu: "1"

View File

@@ -10,3 +10,46 @@ node_pool_name = "dev-main-pool"
machine_type = "e2-medium"
disk_size_gb = 100
static_ip_names = ["agpt-server-ip", "agpt-builder-ip", "auth-ip"]
service_accounts = {
"dev-agpt-server-sa" = {
display_name = "AutoGPT Dev Server Account"
description = "Service account for agpt dev server"
}
}
workload_identity_bindings = {
"dev-agpt-server-workload-identity" = {
service_account_name = "dev-agpt-server-sa"
namespace = "dev-agpt"
ksa_name = "dev-agpt-server-sa"
}
}
role_bindings = {
"roles/container.developer" = [
"serviceAccount:dev-agpt-server-sa@agpt-dev.iam.gserviceaccount.com"
],
"roles/cloudsql.client" = [
"serviceAccount:dev-agpt-server-sa@agpt-dev.iam.gserviceaccount.com"
],
"roles/cloudsql.editor" = [
"serviceAccount:dev-agpt-server-sa@agpt-dev.iam.gserviceaccount.com"
],
"roles/cloudsql.instanceUser" = [
"serviceAccount:dev-agpt-server-sa@agpt-dev.iam.gserviceaccount.com"
],
"roles/iam.workloadIdentityUser" = [
"serviceAccount:dev-agpt-server-sa@agpt-dev.iam.gserviceaccount.com"
]
"roles/compute.networkUser" = [
"serviceAccount:dev-agpt-server-sa@agpt-dev.iam.gserviceaccount.com"
],
"roles/container.hostServiceAgentUser" = [
"serviceAccount:dev-agpt-server-sa@agpt-dev.iam.gserviceaccount.com"
]
}
pods_ip_cidr_range = "10.1.0.0/16"
services_ip_cidr_range = "10.2.0.0/20"

View File

@@ -6,10 +6,12 @@ terraform {
version = "~> 4.0"
}
}
backend "gcs" {
bucket = "agpt-dev-terraform"
prefix = "terraform/state"
}
}
provider "google" {
@@ -28,11 +30,13 @@ module "static_ips" {
module "networking" {
source = "./modules/networking"
project_id = var.project_id
region = var.region
network_name = var.network_name
subnet_name = var.subnet_name
subnet_cidr = var.subnet_cidr
project_id = var.project_id
region = var.region
network_name = var.network_name
subnet_name = var.subnet_name
subnet_cidr = var.subnet_cidr
pods_ip_cidr_range = var.pods_ip_cidr_range
services_ip_cidr_range = var.services_ip_cidr_range
}
module "gke_cluster" {
@@ -49,3 +53,12 @@ module "gke_cluster" {
subnetwork = module.networking.subnet_self_link
enable_autopilot = var.enable_autopilot
}
module "iam" {
source = "./modules/iam"
project_id = var.project_id
service_accounts = var.service_accounts
workload_identity_bindings = var.workload_identity_bindings
role_bindings = var.role_bindings
}

View File

@@ -2,6 +2,11 @@ resource "google_container_cluster" "primary" {
name = var.cluster_name
location = var.zone
workload_identity_config {
workload_pool = "${var.project_id}.svc.id.goog"
}
dynamic "node_pool" {
for_each = var.enable_autopilot ? [] : [1]
content {
@@ -11,11 +16,20 @@ resource "google_container_cluster" "primary" {
node_config {
machine_type = var.machine_type
disk_size_gb = var.disk_size_gb
workload_metadata_config {
mode = "GKE_METADATA"
}
}
}
}
network = var.network
subnetwork = var.subnetwork
ip_allocation_policy {
cluster_secondary_range_name = "pods"
services_secondary_range_name = "services"
}
}

View File

@@ -0,0 +1,26 @@
resource "google_service_account" "service_accounts" {
for_each = var.service_accounts
account_id = each.key
display_name = each.value.display_name
description = each.value.description
}
# IAM policy binding for Workload Identity
resource "google_service_account_iam_binding" "workload_identity_binding" {
for_each = var.workload_identity_bindings
service_account_id = google_service_account.service_accounts[each.value.service_account_name].name
role = "roles/iam.workloadIdentityUser"
members = [
"serviceAccount:${var.project_id}.svc.id.goog[${each.value.namespace}/${each.value.ksa_name}]"
]
}
# Role bindings grouped by role
resource "google_project_iam_binding" "role_bindings" {
for_each = var.role_bindings
project = var.project_id
role = each.key
members = each.value
}

View File

@@ -0,0 +1,4 @@
output "service_account_emails" {
description = "The emails of the created service accounts"
value = { for k, v in google_service_account.service_accounts : k => v.email }
}

View File

@@ -0,0 +1,29 @@
variable "project_id" {
description = "The ID of the project"
type = string
}
variable "service_accounts" {
description = "Map of service accounts to create"
type = map(object({
display_name = string
description = string
}))
default = {}
}
variable "workload_identity_bindings" {
description = "Map of Workload Identity bindings to create"
type = map(object({
service_account_name = string
namespace = string
ksa_name = string
}))
default = {}
}
variable "role_bindings" {
description = "Map of roles to list of members"
type = map(list(string))
default = {}
}

View File

@@ -8,5 +8,15 @@ resource "google_compute_subnetwork" "subnet" {
ip_cidr_range = var.subnet_cidr
region = var.region
network = google_compute_network.vpc_network.self_link
secondary_ip_range {
range_name = "pods"
ip_cidr_range = var.pods_ip_cidr_range
}
secondary_ip_range {
range_name = "services"
ip_cidr_range = var.services_ip_cidr_range
}
}

View File

@@ -18,4 +18,12 @@ variable "subnet_cidr" {
description = "The CIDR range for the subnet"
}
variable "pods_ip_cidr_range" {
description = "The IP address range for pods"
default = "10.1.0.0/16"
}
variable "services_ip_cidr_range" {
description = "The IP address range for services"
default = "10.2.0.0/20"
}

View File

@@ -1,6 +1,5 @@
resource "google_compute_address" "static_ip" {
resource "google_compute_global_address" "static_ip" {
count = length(var.ip_names)
name = "${var.project_id}-${var.ip_names[count.index]}"
region = var.region
address_type = "EXTERNAL"
}

View File

@@ -1,9 +1,9 @@
output "ip_addresses" {
description = "Map of created static IP addresses"
value = { for i, ip in google_compute_address.static_ip : var.ip_names[i] => ip.address }
value = { for i, ip in google_compute_global_address.static_ip : var.ip_names[i] => ip.address }
}
output "ip_names" {
description = "List of full names of the created static IP addresses"
value = google_compute_address.static_ip[*].name
value = google_compute_global_address.static_ip[*].name
}

View File

@@ -74,3 +74,40 @@ variable "static_ip_names" {
type = list(string)
default = ["ip-1", "ip-2", "ip-3"]
}
variable "service_accounts" {
description = "Map of service accounts to create"
type = map(object({
display_name = string
description = string
}))
default = {}
}
variable "workload_identity_bindings" {
description = "Map of Workload Identity bindings to create"
type = map(object({
service_account_name = string
namespace = string
ksa_name = string
}))
default = {}
}
variable "role_bindings" {
description = "Map of roles to list of members"
type = map(list(string))
default = {}
}
variable "pods_ip_cidr_range" {
description = "The IP address range for pods"
type = string
default = "10.1.0.0/16"
}
variable "services_ip_cidr_range" {
description = "The IP address range for services"
type = string
default = "10.2.0.0/20"
}