Skip to content

Commit

Permalink
chore: add example for import
Browse files Browse the repository at this point in the history
  • Loading branch information
Noroth committed Jan 20, 2025
1 parent 69a6fc5 commit 6cfe87a
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Cosmo Terraform Provider

This repository is for the [Cosmo](https://registry.terraform.io/wundergraph/cosmo) Terraform provider, designed to manage Cosmo resources within Terraform. It includes a resource and a data source, examples, and generated documentation.
This repository is for the [Cosmo](https://registry.terraform.io/providers/wundergraph/cosmo/latest) Terraform provider, designed to manage Cosmo resources within Terraform. It includes a resource and a data source, examples, and generated documentation.

## Requirements

Expand Down
18 changes: 18 additions & 0 deletions examples/import/import-resources/import.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# file to showcase how to import various resources

# 1. define the resources to import
# 2. find the resource IDs in the UI or wgc
# 3. Run terraform import

# terraform import cosmo_namespace.import <namespace_id>
resource "cosmo_namespace" "import" {}

# terraform import cosmo_contract.import <contract_id>
resource "cosmo_contract" "import" {}

# terraform import cosmo_federated_graph.import <federated_graph_id>
resource "cosmo_federated_graph" "import" {}

# terraform import cosmo_subgraph.import <subgraph_id>
resource "cosmo_subgraph" "import" {}

8 changes: 8 additions & 0 deletions examples/import/import-resources/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
required_providers {
cosmo = {
source = "wundergraph/cosmo"
version = "0.0.1"
}
}
}
53 changes: 53 additions & 0 deletions examples/import/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
locals {
schema = <<EOF
type Query {
getWunder: Wunder!
getWunderByTitle(title: String!): Wunder!
}
type Wunder {
title: String
}
type Graph {
name: String
wunders: [Wunder]
}
EOF
}

resource "cosmo_namespace" "test" {
name = "import-test"
}

resource "cosmo_federated_graph" "test" {

name = "import-test"
namespace = cosmo_namespace.test.name

routing_url = "http://localhost:9999"
label_matchers = ["team=backend", "stage=import-test"]
depends_on = [cosmo_subgraph.test]
}

// create each stages subgraph
resource "cosmo_subgraph" "test" {
name = "import-test-sg"
schema = local.schema

namespace = cosmo_namespace.test.name
labels = {
"team" = "backend"
"stage" = "import-test"
}

routing_url = "http://localhost:9997"
}

resource "cosmo_contract" "test" {
name = "import-test-contract"
namespace = cosmo_namespace.test.name
source = cosmo_federated_graph.test.name

routing_url = "http://localhost:9998"
exclude_tags = ["backend"]
}
8 changes: 8 additions & 0 deletions examples/import/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
required_providers {
cosmo = {
source = "wundergraph/cosmo"
version = "0.0.1"
}
}
}
1 change: 1 addition & 0 deletions examples/resources/cosmo_contract/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ resource "cosmo_contract" "test" {
source = var.source_graph_name
routing_url = var.routing_url
exclude_tags = var.exclude_tags
include_tags = var.include_tags
}
6 changes: 6 additions & 0 deletions examples/resources/cosmo_contract/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ variable "source_graph_name" {

variable "exclude_tags" {
type = list(string)
default = []
}

variable "include_tags" {
type = list(string)
default = []
}

0 comments on commit 6cfe87a

Please sign in to comment.