terraform-provider-edge-con.../examples/complete/main.tf
2025-11-11 14:15:52 +01:00

136 lines
3.2 KiB
HCL

terraform {
required_providers {
edge-connect = {
source = "DevFW-CICD/edge-connect"
}
}
}
provider "edge-connect" {
base_url = "https://edp.buildth.ing"
token = var.edge_connect_token
}
variable "edge_connect_token" {
description = "Edge Connect API token"
type = string
sensitive = true
}
# Create a web application
resource "edge-connect_app" "web_app" {
region = "EU"
organization = "acme-corp"
name = "web-frontend"
version = "1.0.0"
image_type = "Docker"
image_path = "nginx:alpine"
deployment = "kubernetes"
default_flavor = "EU.small"
access_ports = "tcp:80,tcp:443"
# Optional Kubernetes deployment manifest
deployment_manifest = <<-EOT
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-frontend
spec:
replicas: 2
selector:
matchLabels:
app: web-frontend
template:
metadata:
labels:
app: web-frontend
spec:
containers:
- name: nginx
image: nginx:alpine
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: web-frontend
spec:
selector:
app: web-frontend
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
EOT
annotations = "team=platform,env=production"
}
# Create an API backend application
resource "edge-connect_app" "api_backend" {
region = "EU"
organization = "acme-corp"
name = "api-backend"
version = "2.3.1"
image_type = "Docker"
image_path = "acme/api-server:2.3.1"
deployment = "kubernetes"
default_flavor = "EU.medium"
access_ports = "tcp:8080"
annotations = "team=backend,env=production"
}
# Deploy the web app to edge cloudlet
resource "edge-connect_appinst" "web_instance" {
region = "EU"
app_organization = edge-connect_app.web_app.organization
app_name = edge-connect_app.web_app.name
app_version = edge-connect_app.web_app.version
cloudlet_organization = "edge-provider"
cloudlet_name = "eu-west-1"
cluster_organization = "acme-corp"
flavor = "EU.medium"
}
# Deploy the API backend to edge cloudlet
resource "edge-connect_appinst" "api_instance" {
region = "EU"
app_organization = edge-connect_app.api_backend.organization
app_name = edge-connect_app.api_backend.name
app_version = edge-connect_app.api_backend.version
cloudlet_organization = "edge-provider"
cloudlet_name = "eu-west-1"
cluster_organization = "acme-corp"
flavor = "EU.large"
}
# Outputs
output "web_app_uri" {
description = "URI to access the web application"
value = edge-connect_appinst.web_instance.uri
}
output "web_app_state" {
description = "Current state of the web application instance"
value = edge-connect_appinst.web_instance.state
}
output "api_backend_uri" {
description = "URI to access the API backend"
value = edge-connect_appinst.api_instance.uri
}
output "api_backend_state" {
description = "Current state of the API backend instance"
value = edge-connect_appinst.api_instance.state
}