cosmo icon indicating copy to clipboard operation
cosmo copied to clipboard

Terraform Provider for managing settings

Open InsidersByte opened this issue 1 year ago • 1 comments

Component(s)

controlplane, studio

Is your feature request related to a problem? Please describe.

Currently settings are managed by a combination of the wgc cli and the UI.

With the current solution it is:

  • hard to know what the correct values are
  • review changes
  • make changes to lots of entities, e.g. a new label to all subgraphs

Describe the solution you'd like

A terraform provider to manage a number of the settings to ensure

Describe alternatives you've considered

No response

Additional context

No response

InsidersByte avatar Jun 17 '24 11:06 InsidersByte

WunderGraph commits fully to Open Source and we want to make sure that we can help you as fast as possible. The roadmap is driven by our customers and we have to prioritize issues that are important to them. You can influence the priority by becoming a customer. Please contact us here.

github-actions[bot] avatar Jun 17 '24 11:06 github-actions[bot]

Hi @InsidersByte, thanks for opening an issue. What configuration settings would you like to manage with terraform?

StarpTech avatar Aug 23 '24 12:08 StarpTech

Hello @StarpTech, ultimately I would like to configure everything via terraform for the reasons mentioned above.

A good starting point would be manage the things typically managed via the cli, namespaces, federated graphs, subgraphs, etc.

InsidersByte avatar Aug 30 '24 11:08 InsidersByte

Hi @InsidersByte,

thanks for the feedback. We have taken the topic on our roadmap. We will keep you updated.

AndreasZeissner avatar Aug 30 '24 12:08 AndreasZeissner

Hi @InsidersByte,

Have look here:

  • https://registry.terraform.io/providers/wundergraph/cosmo/latest
  • https://github.com/wundergraph/terraform-provider-cosmo

As an example you can use the provider as follows:

wget https://raw.githubusercontent.com/SpaceXLand/api/master/schema.graphql -O spacex-api.graphql   
terraform {
  required_providers {
    cosmo = {
      source = "wundergraph/cosmo"
      version = "0.0.2"
    }
    docker = {
      source  = "kreuzwerker/docker"
      version = "3.0.2"
    }
  }
}

locals {
  env = "prd"
}

provider "cosmo" {
  api_key = "" # created over the ui
}

provider "docker" {
  host = "unix:///var/run/docker.sock"
}

resource "cosmo_namespace" "test" {
  name = "namespace-${local.env}"
}

resource "cosmo_federated_graph" "test" {
  name           = "federated-graph-${local.env}"
  routing_url    = "https://api.cosmos.wundergraph.com"
  namespace      = cosmo_namespace.test.name
  label_matchers = ["env=${local.env}"]
}

resource "cosmo_subgraph" "test" {
  name        = "subgraph-${local.env}"
  namespace   = cosmo_namespace.test.name
  routing_url = "https://spacex-production.up.railway.app/graphql"
  schema      = file("spacex-api.graphql")
  labels      = {
    "env" = local.env
  }
}

resource "cosmo_router_token" "router" {
  name       = "router-token-${local.env}"
  graph_name = cosmo_federated_graph.test.name
  namespace  = cosmo_namespace.test.name
}

resource "docker_image" "router" {
  name = "ghcr.io/wundergraph/cosmo/router:latest"
}

resource "docker_container" "cosmo_router" {
  image = docker_image.router.image_id
  name  = "cosmo-router"
  restart = "always"

  ports {
    internal = 3002
    external = 3002
  }

  env = [
    "DEV_MODE=true",
    "LISTEN_ADDR=0.0.0.0:3002",
    "GRAPH_API_TOKEN=${cosmo_router_token.router.token}"
  ]
}

It's an early release nevertheless, feel free to open up issues on the new terraform provider repository. Would be great to get some user feedback.

AndreasZeissner avatar Sep 17 '24 19:09 AndreasZeissner