Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable contract usage #7

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f05636e
feat: implement contract enhance error handling
AndreasZeissner Sep 19, 2024
5bf17fb
chore: update docs and examples
AndreasZeissner Sep 19, 2024
40363a3
chore: extend example schema
AndreasZeissner Sep 19, 2024
fb27163
fix: linter errors
AndreasZeissner Sep 19, 2024
f9b8ae6
docs: show api_url default
AndreasZeissner Sep 20, 2024
9f48bb7
docs: improve provider usage documentation
AndreasZeissner Sep 20, 2024
fb7965d
docs: remove provider template from rendered docs
AndreasZeissner Sep 20, 2024
8a44a4e
docs: add markdown description to contract
AndreasZeissner Sep 20, 2024
b7c3fae
fix: handle subgraph composition on deletion
AndreasZeissner Sep 20, 2024
dcffa72
chore: overhaul examples, add guides
AndreasZeissner Sep 20, 2024
ebd315f
docs: regenerate
AndreasZeissner Sep 20, 2024
7ae11b6
chore: add new contract tasks to Makefile
AndreasZeissner Sep 20, 2024
617c347
chore: make error handling more resilient in namespace
AndreasZeissner Sep 20, 2024
f486830
chore: update module paths
AndreasZeissner Sep 20, 2024
412f286
chore: do not imply cosmo variables setup on cosmo-local
AndreasZeissner Sep 20, 2024
b933440
chore: add delete tests for resources
AndreasZeissner Sep 20, 2024
1fcb938
fix: do not run cosmo-local with e2e tests
AndreasZeissner Sep 20, 2024
fc7f04b
chore: adjust error handling also in federated graph
AndreasZeissner Sep 20, 2024
2638119
fix: golangci-lint issues
AndreasZeissner Sep 20, 2024
2242c85
feat: make contract readable add guide
AndreasZeissner Sep 20, 2024
475c561
chore: handle errors consistently
AndreasZeissner Sep 20, 2024
ea62046
fix: reread label matchers in resource
AndreasZeissner Sep 20, 2024
ad8597f
fix: examples
AndreasZeissner Sep 20, 2024
6997adb
chore: streamline error handling in contracts
AndreasZeissner Sep 20, 2024
bf1303c
fix: example
AndreasZeissner Sep 20, 2024
9db0b8b
docs: update readme
AndreasZeissner Sep 20, 2024
a249e1e
docs: add missing resources
AndreasZeissner Sep 25, 2024
b0a3dfc
Merge branch 'main' of github.com:wundergraph/terraform-provider-cosm…
AndreasZeissner Sep 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 32 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ include examples/Makefile
.PHONY: e2e-cd e2e-cosmo e2e-cosmo-monograph clean

e2e-apply-cd:
rm -rf examples/provider/.terraform.lock.hcl
FEATURE=examples/provider make e2e-init
FEATURE=examples/provider make e2e-apply

Expand All @@ -82,24 +83,37 @@ e2e-clean-cd:
make e2e-clean

e2e-apply-cosmo:
FEATURE=examples/cosmo make e2e-init
FEATURE=examples/cosmo make e2e-apply
rm -rf examples/guides/cosmo/.terraform.lock.hcl
FEATURE=examples/guides/cosmo make e2e-init
FEATURE=examples/guides/cosmo make e2e-apply

e2e-destroy-cosmo:
FEATURE=examples/cosmo make e2e-destroy
FEATURE=examples/guides/cosmo make e2e-destroy

e2e-clean-cosmo:
FEATURE=examples/cosmo make e2e-clean
FEATURE=examples/guides/cosmo make e2e-clean

e2e-apply-cosmo-monograph:
FEATURE=examples/resources/comso_monograph make e2e-init
FEATURE=examples/resources/comso_monograph make e2e-apply
rm -rf examples/guides/cosmo-monograph/.terraform.lock.hcl
FEATURE=examples/guides/cosmo-monograph make e2e-init
FEATURE=examples/guides/cosmo-monograph make e2e-apply

e2e-destroy-cosmo-monograph:
FEATURE=examples/resources/comso_monograph make e2e-destroy
FEATURE=examples/guides/cosmo-monograph make e2e-destroy

e2e-clean-cosmo-monograph:
FEATURE=examples/resources/comso_monograph make e2e-clean
FEATURE=examples/guides/cosmo-monograph make e2e-clean

e2e-apply-cosmo-monograph-contract:
rm -rf examples/guides/cosmo-monograph-contract/.terraform.lock.hcl
FEATURE=examples/guides/cosmo-monograph-contract make e2e-init
FEATURE=examples/guides/cosmo-monograph-contract make e2e-apply

e2e-destroy-cosmo-monograph-contract:
FEATURE=examples/guides/cosmo-monograph-contract make e2e-destroy

e2e-clean-cosmo-monograph-contract:
FEATURE=examples/guides/cosmo-monograph-contract make e2e-clean

## Cosmo Local
# Full example installing cosmo locally with a minikube kubernetes cluster
Expand All @@ -108,23 +122,25 @@ e2e-clean-cosmo-monograph:
# output "hosts" generated after apply

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

e2e-destroy-cosmo-local:
FEATURE=examples/cosmo-local make e2e-destroy
FEATURE=examples/guides/cosmo-local make e2e-destroy

e2e-clean-cosmo-local:
FEATURE=examples/cosmo-local make e2e-clean
FEATURE=examples/guides/cosmo-local make e2e-clean

## Convenience targets to run specific e2e tests

e2e-cd: e2e-apply-cd e2e-destroy-cd
e2e-cosmo: e2e-apply-cosmo e2e-destroy-cosmo
e2e-cosmo-monograph: e2e-apply-cosmo-monograph e2e-destroy-cosmo-monograph
e2e-cosmo-monograph-contract: e2e-apply-cosmo-monograph-contract e2e-destroy-cosmo-monograph-contract
e2e-cosmo-local: e2e-apply-cosmo-local e2e-destroy-cosmo-local

e2e: e2e-cd e2e-cosmo e2e-cosmo-monograph
e2e: e2e-cd e2e-cosmo e2e-cosmo-monograph e2e-cosmo-monograph-contract

clean: e2e-clean-cd e2e-clean-cosmo e2e-clean-cosmo-monograph clean-local
destroy: e2e-destroy-cd e2e-destroy-cosmo e2e-destroy-cosmo-monograph
clean: e2e-clean-cd e2e-clean-cosmo e2e-clean-cosmo-monograph e2e-clean-cosmo-monograph-contract clean-local
destroy: e2e-destroy-cd e2e-destroy-cosmo e2e-destroy-cosmo-monograph e2e-destroy-cosmo-monograph-contract e2e-destroy-cosmo-local
43 changes: 32 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,24 +203,45 @@ The following commands are used to build and install the provider binary locally

The Makefile includes several tasks to facilitate development and testing. For local development, `make build install` should be used to install the provider locally.

### General Build Tasks

- **default**: Runs acceptance tests.
- **testacc**: Runs tests with a timeout.
- **test-go**: Runs Go tests.
- **test**: Cleans, builds, installs, runs acceptance tests, and executes end-to-end tests.
- **generate**: Updates generated files.
- **tidy**: Cleans up the `go.mod` file.
- **fmt**: Formats code.
- **fmt**: Formats Go and Terraform files for consistency.
- **build**: Compiles the provider binary.
- **install**: Installs the binary in the Terraform plugin directory after building it.
- **clean-local**: Cleans up local build artifacts.
- **build-all-arches**: Compiles the binary for multiple OS and architectures.
- **release**: Generates files and builds binaries for all architectures.
- **e2e-cd-apply**: Runs end-to-end tests for apply. (References: `examples/provider`)
- **e2e-cd-destroy**: Runs end-to-end tests for destroy. (References: `examples/provider`)
- **e2e-cosmo-apply**: Runs end-to-end tests for the cosmo feature. (References: `examples/cosmo`)
- **e2e-cosmo-destroy**: Runs end-to-end tests for cosmo destroy. (References: `examples/cosmo`)
- **e2e-cosmo-monograph-apply**: Runs end-to-end tests for the monograph feature. (References: `examples/resources/comso_monograph`)
- **e2e-cosmo-monograph-destroy**: Runs end-to-end tests for monograph destroy. (References: `examples/resources/comso_monograph`)
- **e2e-apply-cosmo-local**: Runs end-to-end tests for cosmo local. (References: `examples/cosmo-local`)
- **e2e-destroy-cosmo-local**: Runs end-to-end tests for cosmo local destroy. (References: `examples/cosmo-local`)
- **e2e-clean-cosmo-local**: Cleans up the cosmo local setup. (References: `examples/cosmo-local`)

### End-to-End (E2E) Tasks

- **e2e-apply-cd**: Runs end-to-end tests for the CD feature (points to `examples/provider`).
- **e2e-destroy-cd**: Cleans up after CD tests (points to `examples/provider`).
- **e2e-clean-cd**: Cleans up CD test artifacts (points to `examples/provider`).
- **e2e-apply-cosmo**: Runs end-to-end tests for the Cosmo feature (points to `examples/guides/cosmo`).
- **e2e-destroy-cosmo**: Cleans up after Cosmo tests (points to `examples/guides/cosmo`).
- **e2e-clean-cosmo**: Cleans up Cosmo test artifacts (points to `examples/guides/cosmo`).
- **e2e-apply-cosmo-monograph**: Runs end-to-end tests for the Cosmo monograph feature (points to `examples/guides/cosmo-monograph`).
- **e2e-destroy-cosmo-monograph**: Cleans up after Cosmo monograph tests (points to `examples/guides/cosmo-monograph`).
- **e2e-clean-cosmo-monograph**: Cleans up Cosmo monograph test artifacts (points to `examples/guides/cosmo-monograph`).
- **e2e-apply-cosmo-monograph-contract**: Runs end-to-end tests for the Cosmo monograph contract feature (points to `examples/guides/cosmo-monograph-contract`).
- **e2e-destroy-cosmo-monograph-contract**: Cleans up after Cosmo monograph contract tests (points to `examples/guides/cosmo-monograph-contract`).
- **e2e-clean-cosmo-monograph-contract**: Cleans up Cosmo monograph contract test artifacts (points to `examples/guides/cosmo-monograph-contract`).
- **e2e-apply-cosmo-local**: Runs end-to-end tests for the local Cosmo setup (points to `examples/guides/cosmo-local`).
- **e2e-destroy-cosmo-local**: Cleans up after local Cosmo tests (points to `examples/guides/cosmo-local`).
- **e2e-clean-cosmo-local**: Cleans up local Cosmo test artifacts (points to `examples/guides/cosmo-local`).
- **e2e-cd**: Runs both apply and destroy for CD tests.
- **e2e-cosmo**: Runs both apply and destroy for Cosmo tests.
- **e2e-cosmo-monograph**: Runs both apply and destroy for Cosmo monograph tests.
- **e2e-cosmo-monograph-contract**: Runs both apply and destroy for Cosmo monograph contract tests.
- **e2e-cosmo-local**: Runs both apply and destroy for local Cosmo tests.
- **e2e**: Runs all end-to-end tests.
- **clean**: Cleans up all test artifacts and local builds.
- **destroy**: Cleans up all resources created by the tests.

## Releasing

Expand Down
37 changes: 37 additions & 0 deletions docs/data-sources/contract.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "cosmo_contract Data Source - cosmo"
subcategory: ""
description: |-

---

# cosmo_contract (Data Source)



## Example Usage

```terraform
data "cosmo_subgraph" "test" {
name = var.name
namespace = var.namespace
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `name` (String) The name of the federated graph.
- `namespace` (String) The namespace in which the federated graph is located.

### Read-Only

- `admission_webhook_secret` (String, Sensitive) The secret token used to authenticate the admission webhook requests.
- `admission_webhook_url` (String) The URL for the admission webhook that will be triggered during graph operations.
- `id` (String) The unique identifier of the federated graph resource, automatically generated by the system.
- `label_matchers` (Map of String) A list of label matchers used to select the services that will form the federated graph.
- `readme` (String) Readme content for the federated graph.
- `routing_url` (String) The URL for the federated graph.
9 changes: 0 additions & 9 deletions docs/data-sources/federated_graph.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@ Cosmo Federated Graph Data Source
## Example Usage

```terraform
terraform {
required_providers {
cosmo = {
source = "terraform.local/wundergraph/cosmo"
version = "0.0.1"
}
}
}

data "cosmo_federated_graph" "test" {
name = var.name
namespace = var.namespace
Expand Down
9 changes: 0 additions & 9 deletions docs/data-sources/monograph.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@ Cosmo Monograph Data Source
## Example Usage

```terraform
terraform {
required_providers {
cosmo = {
source = "terraform.local/wundergraph/cosmo"
version = "0.0.1"
}
}
}

data "cosmo_monograph" "example" {
name = var.name
}
Expand Down
9 changes: 0 additions & 9 deletions docs/data-sources/namespace.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@ Cosmo Namespace Data Source
## Example Usage

```terraform
terraform {
required_providers {
cosmo = {
source = "terraform.local/wundergraph/cosmo"
version = "0.0.1"
}
}
}

data "cosmo_namespace" "test" {
name = var.name
}
Expand Down
9 changes: 0 additions & 9 deletions docs/data-sources/subgraph.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@ Cosmo Subgraph Data Source
## Example Usage

```terraform
terraform {
required_providers {
cosmo = {
source = "terraform.local/wundergraph/cosmo"
version = "0.0.1"
}
}
}

data "cosmo_subgraph" "test" {
name = var.name
namespace = var.namespace
Expand Down
22 changes: 6 additions & 16 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,24 @@ page_title: "cosmo Provider"
subcategory: ""
description: |-
The Cosmo provider allows you to interact with WunderGraph's Cosmo API, managing key resources.
It supports creating and reading namespaces, federated graphs, and monographs.
You can also generate router tokens for use with the router, and manage subgraphs by creating, publishing, or reading them.
It supports creating and reading namespaces, federated graphs, subgraphs, router tokens, monographs, and contracts.
Refer to the official Cosmo Documentation https://cosmo-docs.wundergraph.com/ for more details.
---

# cosmo Provider

The Cosmo provider allows you to interact with WunderGraph's Cosmo API, managing key resources.
It supports creating and reading namespaces, federated graphs, and monographs.
You can also generate router tokens for use with the router, and manage subgraphs by creating, publishing, or reading them.
It supports creating and reading namespaces, federated graphs, subgraphs, router tokens, monographs, and contracts.

Refer to the official [Cosmo Documentation](https://cosmo-docs.wundergraph.com/) for more details.

## Example Usage

```terraform
terraform {
required_providers {
cosmo = {
source = "terraform.local/wundergraph/cosmo"
version = "0.0.1"
}
}
}

provider "cosmo" {
api_url = var.api_url
api_key = var.api_key
# Set to your onpremise instance if needed
# api_url = var.api_url
}
```

Expand All @@ -40,5 +30,5 @@ provider "cosmo" {

### Optional

- `api_key` (String) The Api Key to be used: COSMO_API_KEY
- `api_url` (String) The Api Url to be used: COSMO_API_URL
- `api_key` (String) The Api Key to be used: Leave blank to use the COSMO_API_KEY environment variable
- `api_url` (String) The Api Url to be used: Leave blank to use: https://cosmo-cp.wundergraph.com or use the COSMO_API_URL environment variable
47 changes: 47 additions & 0 deletions docs/resources/contract.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "cosmo_contract Resource - cosmo"
subcategory: ""
description: |-
A contract is a Terraform resource representing a single subgraph with GraphQL Federation enabled, allowing developers to build versatile, multi-audience graphs while simplifying development and ensuring maintainability.
For more information, refer to the Cosmo Documentation at https://cosmo-docs.wundergraph.com/concepts/schema-contracts.
---

# cosmo_contract (Resource)

A contract is a Terraform resource representing a single subgraph with GraphQL Federation enabled, allowing developers to build versatile, multi-audience graphs while simplifying development and ensuring maintainability.

For more information, refer to the Cosmo Documentation at https://cosmo-docs.wundergraph.com/concepts/schema-contracts.

## Example Usage

```terraform
resource "cosmo_contract" "test" {
name = var.name
namespace = var.namespace
source = var.source_graph_name
routing_url = var.routing_url
exclude_tags = var.exclude_tags
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `name` (String)
- `namespace` (String)
- `routing_url` (String)
- `source` (String)

### Optional

- `admission_webhook_secret` (String)
- `admission_webhook_url` (String)
- `exclude_tags` (List of String)
- `readme` (String)

### Read-Only

- `id` (String) The ID of this resource.
9 changes: 0 additions & 9 deletions docs/resources/federated_graph.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@ For more information on federated graphs, please refer to the [Cosmo Documentati
## Example Usage

```terraform
terraform {
required_providers {
cosmo = {
source = "terraform.local/wundergraph/cosmo"
version = "0.0.1"
}
}
}

resource "cosmo_federated_graph" "test" {
name = var.name
routing_url = var.routing_url
Expand Down
11 changes: 10 additions & 1 deletion docs/resources/monograph.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@ A monograph is a resource that represents a single subgraph with GraphQL Federat

For more information on monographs, please refer to the [Cosmo Documentation](https://cosmo-docs.wundergraph.com/cli/monograph).


## Example Usage

```terraform
resource "cosmo_monograph" "example" {
name = var.monograph_name
namespace = var.monograph_namespace
graph_url = var.monograph_graph_url
routing_url = var.monograph_routing_url
}
```

<!-- schema generated by tfplugindocs -->
## Schema
Expand Down
9 changes: 0 additions & 9 deletions docs/resources/namespace.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@ For more information on namespaces, please refer to the [Cosmo Documentation](ht
## Example Usage

```terraform
terraform {
required_providers {
cosmo = {
source = "terraform.local/wundergraph/cosmo"
version = "0.0.1"
}
}
}

resource "cosmo_namespace" "test" {
name = var.name
}
Expand Down
Loading