Skip to content

Commit

Permalink
chore: add extended example
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasZeissner committed Sep 16, 2024
1 parent c699d34 commit 46e18c3
Show file tree
Hide file tree
Showing 22 changed files with 1,319 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ EXAMPLES = examples
TEST ?= $$(go list ./... | grep -v 'vendor')
HOSTNAME ?= terraform.local

COSMO_API_URL ?= http://localhost:3001
COSMO_API_KEY ?= cosmo_669b576aaadc10ee1ae81d9193425705

default: testacc

.PHONY: testacc
Expand Down Expand Up @@ -93,6 +96,17 @@ e2e-destroy-cosmo-monograph:
e2e-clean-cosmo-monograph:
FEATURE=examples/resources/comso_monograph make e2e-clean

e2e-apply-cosmo-local-module:
rm -rf modules/cosmo-local/.terraform.lock.hcl
FEATURE=modules/cosmo-local make e2e-init
FEATURE=modules/cosmo-local make e2e-apply

e2e-destroy-cosmo-local-module:
FEATURE=modules/cosmo-local make e2e-destroy

e2e-clean-cosmo-local-module:
FEATURE=modules/cosmo-local make e2e-clean

## Convenience targets to run specific e2e tests

e2e-cd: e2e-apply-cd e2e-destroy-cd
Expand Down
23 changes: 23 additions & 0 deletions modules/charts/release/chart.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
resource "helm_release" "this" {
name = var.release_name
namespace = var.chart.namespace
repository = var.chart.repository
version = var.chart.version
chart = var.chart.name
values = concat([file(var.chart.init_values)], var.chart.values)

wait = true
wait_for_jobs = true

cleanup_on_fail = false
atomic = false
verify = false

dynamic "set" {
for_each = var.chart.set
content {
name = set.key
value = set.value
}
}
}
8 changes: 8 additions & 0 deletions modules/charts/release/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
required_providers {
helm = {
source = "hashicorp/helm"
version = "2.15.0"
}
}
}
25 changes: 25 additions & 0 deletions modules/charts/release/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
variable "chart" {
type = object({
name = string
version = string
namespace = string
repository = string
values = list(string)
init_values = string
set = map(string)
})
default = {
name = "cosmo"
version = "0.11.1"
namespace = "cosmo"
repository = "oci://ghcr.io/wundergraph/cosmo/helm-charts"
values = ["ingress"]
init_values = ""
set = {}
}
}

variable "release_name" {
type = string
default = "cosmo"
}
16 changes: 16 additions & 0 deletions modules/charts/template/chart.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
data "helm_template" "this" {
name = var.chart.name
namespace = var.chart.namespace
repository = var.chart.repository
chart = var.chart.name
version = var.chart.version
values = concat([file(var.chart.init_values)], var.chart.values)

dynamic "set" {
for_each = var.chart.set
content {
name = set.key
value = set.value
}
}
}
11 changes: 11 additions & 0 deletions modules/charts/template/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
output "manifests" {
value = data.helm_template.this.manifests
}

output "manifest" {
value = data.helm_template.this.manifest
}

output "notes" {
value = data.helm_template.this.notes
}
12 changes: 12 additions & 0 deletions modules/charts/template/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
terraform {
required_providers {
carvel = {
source = "carvel-dev/carvel"
version = "0.11.2"
}
helm = {
source = "hashicorp/helm"
version = "2.15.0"
}
}
}
20 changes: 20 additions & 0 deletions modules/charts/template/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
variable "chart" {
type = object({
name = string
version = string
namespace = string
repository = string
values = list(string)
init_values = string
set = map(string)
})
default = {
name = "cosmo"
version = "0.11.1"
namespace = "cosmo"
repository = "oci://ghcr.io/wundergraph/cosmo/helm-charts"
values = []
init_values = ""
set = {}
}
}
2 changes: 2 additions & 0 deletions modules/cosmo-federated-graph/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ resource "cosmo_subgraph" "subgraph" {
namespace = cosmo_namespace.namespace.name
routing_url = each.value.routing_url
schema = each.value.schema
labels = each.value.labels
readme = each.value.readme
}

resource "cosmo_router_token" "router_token" {
Expand Down
1 change: 1 addition & 0 deletions modules/cosmo-federated-graph/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ variable "subgraphs" {
routing_url = string
labels = map(string)
schema = string
readme = string
}))
description = "The subgraphs to be added to the federated graph"
}
Expand Down
8 changes: 8 additions & 0 deletions modules/cosmo-local/debug.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
resource "local_file" "deployment" {
for_each = var.write_deployment_yaml ? {
"deployment" = module.cosmo_charts.manifest
} : {}

content = module.cosmo_charts.manifest
filename = "${path.module}/${var.stage}-deployment.yaml"
}
150 changes: 150 additions & 0 deletions modules/cosmo-local/graphs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
resource "random_string" "module_prefix" {
length = 6
special = false
}

locals {
prefix = lower(random_string.module_prefix.result)
}

module "cosmo_federated_graph" {
source = "../cosmo-federated-graph"
namespace = "${var.stage}-${local.prefix}"
router_token_name = "${var.stage}-${local.prefix}-router-token"

federated_graph = {
name = "${local.prefix}-federated-graph"
routing_url = "http://localhost:3000"
label_matchers = [
"team=backend",
]
}
subgraphs = {
"availability" = {
name = "${var.stage}-${local.prefix}-availability"
routing_url = "http://example.com/routing"
schema = <<EOF
extend schema
@link(url: "https://specs.apollo.dev/federation/v2.5", import: ["@authenticated", "@composeDirective", "@external", "@extends", "@inaccessible", "@interfaceObject", "@override", "@provides", "@key", "@requires", "@requiresScopes", "@shareable", "@tag"])
type Mutation {
updateAvailability(employeeID: Int!, isAvailable: Boolean!): Employee!
}
type Employee @key(fields: "id") {
id: Int!
isAvailable: Boolean!
}
EOF
readme = "Availabilty Subgraph"
labels = {
"team" = "backend"
"stage" = "${var.stage}"
}
}
"products" = {
name = "${var.stage}-${local.prefix}-products"
routing_url = "http://example.com/routing"
schema = <<EOF
extend schema
@link(url: "https://specs.apollo.dev/federation/v2.5", import: ["@authenticated", "@composeDirective", "@external", "@extends", "@inaccessible", "@interfaceObject", "@override", "@provides", "@key", "@requires", "@requiresScopes", "@shareable", "@tag"])
schema {
query: Queries
mutation: Mutation
}
type Queries {
productTypes: [Products!]!
topSecretFederationFacts: [TopSecretFact!]! @requiresScopes(scopes: [["read:fact"], ["read:all"]])
factTypes: [TopSecretFactType!]
}
type Mutation {
addFact(fact: TopSecretFactInput!): TopSecretFact! @requiresScopes(scopes: [["write:fact"], ["write:all"]])
}
input TopSecretFactInput {
title: String!
description: FactContent!
factType: TopSecretFactType!
}
enum TopSecretFactType @authenticated {
DIRECTIVE,
ENTITY,
MISCELLANEOUS,
}
interface TopSecretFact @authenticated {
description: FactContent!
factType: TopSecretFactType
}
scalar FactContent @requiresScopes(scopes: [["read:scalar"], ["read:all"]])
type DirectiveFact implements TopSecretFact @authenticated {
title: String!
description: FactContent!
factType: TopSecretFactType
}
type EntityFact implements TopSecretFact @requiresScopes(scopes: [["read:entity"]]){
title: String!
description: FactContent!
factType: TopSecretFactType
}
type MiscellaneousFact implements TopSecretFact {
title: String!
description: FactContent! @requiresScopes(scopes: [["read:miscellaneous"]])
factType: TopSecretFactType
}
enum ProductName {
CONSULTANCY
COSMO
ENGINE
FINANCE
HUMAN_RESOURCES
MARKETING
SDK
}
type Employee @key(fields: "id") {
id: Int!
products: [ProductName!]!
notes: String @override(from: "employees")
}
union Products = Consultancy | Cosmo | Documentation
type Consultancy @key(fields: "upc") {
upc: ID!
name: ProductName!
}
type Cosmo @key(fields: "upc") {
upc: ID!
name: ProductName!
repositoryURL: String!
}
type Documentation {
url(product: ProductName!): String!
urls(products: [ProductName!]!): [String!]!
}
EOF
readme = "Products Subgraph"
labels = {
"team" = "backend"
"stage" = "${var.stage}"
}
}
}

depends_on = [
module.minikube,
module.cosmo_release
]
}

Loading

0 comments on commit 46e18c3

Please sign in to comment.