From 05367ff2253eb46fb5c0f925b19fdb0a91abfc9e Mon Sep 17 00:00:00 2001 From: Mikhail Yohman Date: Mon, 15 May 2023 01:20:23 -0600 Subject: [PATCH] Datasource graphql (#6) * Add graphql datasource. * Add docs via go generate ./.. --- .gitignore | 2 + docs/data-sources/graphql.md | 27 +++++++ .../nautobot_data_source/data-source.tf | 12 ++- internal/provider/data_source_graphql.go | 81 +++++++++++++++++++ internal/provider/data_source_graphql_test.go | 47 +++++++++++ internal/provider/provider.go | 22 ++++- test/output.tf | 23 +++++- 7 files changed, 208 insertions(+), 6 deletions(-) create mode 100644 docs/data-sources/graphql.md create mode 100644 internal/provider/data_source_graphql.go create mode 100644 internal/provider/data_source_graphql_test.go diff --git a/.gitignore b/.gitignore index 805e66f..83a87b3 100644 --- a/.gitignore +++ b/.gitignore @@ -25,8 +25,10 @@ website/node_modules *.test *.iml +.vscode/ test/.terraform.lock.hcl website/vendor +test/*.tfplan # Test exclusions !command/test-fixtures/**/*.tfstate diff --git a/docs/data-sources/graphql.md b/docs/data-sources/graphql.md new file mode 100644 index 0000000..ba58111 --- /dev/null +++ b/docs/data-sources/graphql.md @@ -0,0 +1,27 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "nautobot_graphql Data Source - terraform-provider-nautobot" +subcategory: "" +description: |- + Provide an interface to make GraphQL calls to Nautobot as a flexible data source. +--- + +# nautobot_graphql (Data Source) + +Provide an interface to make GraphQL calls to Nautobot as a flexible data source. + + + + +## Schema + +### Required + +- `query` (String) The GraphQL query that will be sent to Nautobot. + +### Read-Only + +- `data` (String) The data returned by the GraphQL query. +- `id` (String) The ID of this resource. + + diff --git a/examples/data-sources/nautobot_data_source/data-source.tf b/examples/data-sources/nautobot_data_source/data-source.tf index f71d4fb..f2f6650 100644 --- a/examples/data-sources/nautobot_data_source/data-source.tf +++ b/examples/data-sources/nautobot_data_source/data-source.tf @@ -1 +1,11 @@ -data "nautobot_manufacturers" "all" {} \ No newline at end of file +data "nautobot_manufacturers" "all" {} + +data "nautobot_graphql" "vms" { + query = < manufacturer if manufacturer.name == var.manufacturer_name } -} \ No newline at end of file +} +data "nautobot_graphql" "nodes" { + query = <