Skip to content

Commit ee38b66

Browse files
authored
Merge pull request #18 from davidweterings/feat/context-id-data-resource
feat/context id data resource
2 parents d5b99d0 + 7c8aa06 commit ee38b66

4 files changed

Lines changed: 135 additions & 21 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
kind: Added
2+
body: Added context_id to data schema check resource, similar to resource
3+
time: 2025-05-13T13:51:18.940026+02:00

README.md

Lines changed: 112 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,52 @@
11
# GraphQL Hive Terraform Provider
22

3+
The Terraform GraphQL Hive provider allows you to configure your [GraphQL Hive](https://graphql-hive.com/) project with infrastructure-as-code principles.
4+
5+
# Commercial support
6+
7+
Need support implementing this terraform provider in your organization? Or are you missing features
8+
that need to be added, then we are able to offer support. Please contact us at opensource@labdigital.nl
9+
10+
# Quick start
11+
12+
[Read our documentation](https://registry.terraform.io/providers/labd/hive/latest/docs)
13+
and check out the examples in the [examples](./examples) directory.
314

415
## Usage
516

6-
```hcl
17+
The provider is distributed via the Terraform registry. To use it you need to configure
18+
the [`required_providers`](https://www.terraform.io/language/providers/requirements#requiring-providers) block. For example:
719

20+
```hcl
821
terraform {
922
required_providers {
1023
hive = {
11-
source = "labd/hive"
12-
version = "0.0.1"
24+
source = "labd/hive"
25+
26+
# It's recommended to pin the version, e.g.:
27+
# version = "~> 1.0.0"
1328
}
1429
}
1530
}
1631
1732
data "hive_schema_check" "my-service" {
1833
project = "my-project"
19-
target = "my-target
34+
target = "my-target"
2035
service = "my-service"
2136
schema = file("schema.graphql")
2237
}
2338
2439
resource "hive_schema_check" "my-service" {
2540
project = "my-project"
26-
target = "my-target
41+
target = "my-target"
2742
service = "my-service"
2843
commit = "57ee05c"
2944
schema = file("schema.graphql")
3045
}
3146
3247
resource "hive_schema_publish" "my-service" {
3348
project = "my-project"
34-
target = "my-target
49+
target = "my-target"
3550
service = "my-service"
3651
commit = "57ee05c"
3752
url = "https://checkout.example.com/graphql"
@@ -40,12 +55,101 @@ resource "hive_schema_publish" "my-service" {
4055
4156
resource "hive_app_create" "persisted_documents" {
4257
name = "site"
43-
version = "1.0.0"
58+
version = "1.0.0"
4459
documents = file("persisted_documents.json")
4560
}
4661
4762
resource "hive_app_publish" "persisted_documents" {
4863
name = "site"
49-
version = "1.0.0"
64+
version = "1.0.0"
65+
}
66+
```
67+
68+
# Binaries
69+
70+
Packages of the releases are available at
71+
https://github.com/labd/terraform-provider-hive/releases See the
72+
[terraform documentation](https://www.terraform.io/docs/configuration/providers.html#third-party-plugins)
73+
for more information about installing third-party providers.
74+
75+
# Contributing
76+
77+
## Requirements
78+
79+
- [Go](https://golang.org/doc/install) >= 1.24
80+
- [Task](https://taskfile.dev/installation/)
81+
- [Changie](https://github.com/miniscruff/changie)
82+
83+
## Building the provider
84+
85+
Clone repository to: `$GOPATH/src/github.com/labd/terraform-provider-hive`
86+
87+
```sh
88+
$ mkdir -p $GOPATH/src/github.com/labd; cd $GOPATH/src/github.com/labd
89+
$ git clone git@github.com:labd/terraform-provider-hive
90+
```
91+
92+
Enter the provider directory and build the provider
93+
94+
```sh
95+
$ cd $GOPATH/src/github.com/labd/terraform-provider-hive
96+
$ task build-local
97+
```
98+
99+
A build is created `terraform-provider-hive_99.0.0` in the root directory and added to plugin folder available
100+
locally:
101+
102+
```sh
103+
~/.terraform.d/plugins/registry.terraform.io/labd/hive/99.0.0/${OS_ARCH}/terraform-provider-hive_v99.0.0
104+
```
105+
106+
Use version `99.0.0` in the provider to test your changes locally
107+
108+
```hcl
109+
terraform {
110+
required_providers {
111+
hive = {
112+
source = "labd/hive"
113+
version = "99.0.0"
114+
}
115+
}
50116
}
51117
```
118+
119+
## Debugging / Troubleshooting
120+
121+
There are two environment settings for troubleshooting:
122+
123+
- `TF_LOG=INFO` enables debug output for Terraform.
124+
- `HIVE_DEBUG=1` enables debug output for the GraphQL Hive GO SDK this provider uses.
125+
126+
Note this generates a lot of output!
127+
128+
## Releasing
129+
130+
When creating a PR with changes, please include a changie file in the `changelogs/unreleased` folder. This file can be
131+
interactively generated by running `changie new` in the root of the project. Pick a suitable category for the change. We
132+
recommend `Fixed` or `Added` for most cases.
133+
134+
Once a new version is released, all the unreleased changelog files will be merged and added to the general CHANGELOG.md file.
135+
136+
## Testing
137+
138+
### Running the unit tests
139+
140+
```sh
141+
$ task test
142+
```
143+
144+
### Running the unit tests with coverage
145+
146+
```sh
147+
$ task coverage
148+
```
149+
150+
## Authors
151+
152+
This project is developed by [Lab Digital](https://www.labdigital.nl). We
153+
welcome additional contributors. Please see our
154+
[GitHub repository](https://github.com/labd/terraform-provider-hive)
155+
for more information.

docs/data-sources/schema_check.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ data "hive_schema_check" "check" {
3939

4040
- `author` (String) The author of the version
4141
- `commit` (String) The commit or version identifier
42+
- `context_id` (String) Optional context ID to group schema checks together. Manually approved breaking changes will be memorized for schema checks with the same context id.
4243
- `project` (String) The project name
4344
- `target` (String) The target name
4445

internal/provider/data_source_schema_check.go

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ func (r *HiveSchemaCheckDataSource) Metadata(ctx context.Context, req datasource
2727
}
2828

2929
type HiveSchemaCheckDataSourceModel struct {
30-
Service types.String `tfsdk:"service"`
31-
Commit types.String `tfsdk:"commit"`
32-
Author types.String `tfsdk:"author"`
33-
Schema types.String `tfsdk:"schema"`
34-
Id types.String `tfsdk:"id"`
35-
Target types.String `tfsdk:"target"`
36-
Project types.String `tfsdk:"project"`
30+
Service types.String `tfsdk:"service"`
31+
Commit types.String `tfsdk:"commit"`
32+
Author types.String `tfsdk:"author"`
33+
Schema types.String `tfsdk:"schema"`
34+
ContextId types.String `tfsdk:"context_id"`
35+
Id types.String `tfsdk:"id"`
36+
Target types.String `tfsdk:"target"`
37+
Project types.String `tfsdk:"project"`
3738
}
3839

3940
func (d *HiveSchemaCheckDataSource) Schema(ctx context.Context, _req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
@@ -69,6 +70,10 @@ func (d *HiveSchemaCheckDataSource) Schema(ctx context.Context, _req datasource.
6970
Computed: true,
7071
MarkdownDescription: "The resource ID",
7172
},
73+
"context_id": schema.StringAttribute{
74+
MarkdownDescription: "Optional context ID to group schema checks together. Manually approved breaking changes will be memorized for schema checks with the same context id.",
75+
Optional: true,
76+
},
7277
},
7378
}
7479
}
@@ -100,12 +105,13 @@ func (r *HiveSchemaCheckDataSource) Read(ctx context.Context, req datasource.Rea
100105
}
101106

102107
result, err := r.client.SchemaCheck(ctx, &sdk.SchemaCheckInput{
103-
Service: data.Service.ValueString(),
104-
Schema: data.Schema.ValueString(),
105-
Commit: data.Commit.ValueString(),
106-
Author: data.Author.ValueString(),
107-
Target: data.Target.ValueString(),
108-
Project: data.Project.ValueString(),
108+
Service: data.Service.ValueString(),
109+
Schema: data.Schema.ValueString(),
110+
Commit: data.Commit.ValueString(),
111+
Author: data.Author.ValueString(),
112+
Target: data.Target.ValueString(),
113+
Project: data.Project.ValueString(),
114+
ContextId: data.ContextId.ValueString(),
109115
})
110116

111117
if err != nil {

0 commit comments

Comments
 (0)