From 0f9afa2ae70f91a42b13a2d5dc56936fb27c22f0 Mon Sep 17 00:00:00 2001 From: Antoine Balliet Date: Fri, 17 Nov 2023 10:05:41 +0100 Subject: [PATCH 1/3] feat: add operation resource --- docs/data-sources/airbyte_operation.md | 82 ++++ docs/data-sources/airbyte_source.md | 2 +- docs/data-sources/airbyte_source_schema.md | 4 +- docs/resources/airbyte_operation.md | 111 ++++++ docs/resources/airbyte_source.md | 6 +- docs/resources/airbyte_source_definition.md | 10 +- .../airbyte_source_definition_manifest.md | 6 +- docs/resources/airbyte_workspace.md | 26 +- .../airbyte_operation/data-source.tf | 3 + .../airbyte_source/data-source.tf | 2 +- .../airbyte_source_schema/data-source.tf | 4 +- .../resources/airbyte_operation/resource.tf | 26 ++ examples/resources/airbyte_source/resource.tf | 6 +- .../airbyte_source_definition/resource.tf | 10 +- .../resource.tf | 6 +- .../resources/airbyte_workspace/resource.tf | 26 +- files.gen | 11 + internal/provider/operation_data_source.go | 197 ++++++++++ .../provider/operation_data_source_sdk.go | 78 ++++ internal/provider/operation_resource.go | 356 ++++++++++++++++++ internal/provider/operation_resource_sdk.go | 298 +++++++++++++++ internal/provider/provider.go | 2 + internal/provider/type_dbt_cloud.go | 10 + .../provider/type_operator_configuration.go | 12 + internal/provider/type_operator_dbt.go | 12 + .../provider/type_operator_normalization.go | 9 + internal/provider/type_operator_webhook.go | 13 + 27 files changed, 1274 insertions(+), 54 deletions(-) create mode 100644 docs/data-sources/airbyte_operation.md create mode 100644 docs/resources/airbyte_operation.md create mode 100644 examples/data-sources/airbyte_operation/data-source.tf create mode 100644 examples/resources/airbyte_operation/resource.tf create mode 100644 internal/provider/operation_data_source.go create mode 100644 internal/provider/operation_data_source_sdk.go create mode 100644 internal/provider/operation_resource.go create mode 100644 internal/provider/operation_resource_sdk.go create mode 100644 internal/provider/type_dbt_cloud.go create mode 100644 internal/provider/type_operator_configuration.go create mode 100644 internal/provider/type_operator_dbt.go create mode 100644 internal/provider/type_operator_normalization.go create mode 100644 internal/provider/type_operator_webhook.go diff --git a/docs/data-sources/airbyte_operation.md b/docs/data-sources/airbyte_operation.md new file mode 100644 index 0000000..583ad98 --- /dev/null +++ b/docs/data-sources/airbyte_operation.md @@ -0,0 +1,82 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "airbyte_operation Data Source - aballiet-terraform-provider-airbyte-oss" +subcategory: "" +description: |- + Operation DataSource +--- + +# airbyte_operation (Data Source) + +Operation DataSource + +## Example Usage + +```terraform +data "airbyte_operation" "my_operation" { + operation_id = "cd96c08a-642e-4276-9d0a-b8d096c23af1" +} +``` + + +## Schema + +### Required + +- `operation_id` (String) + +### Read-Only + +- `name` (String) +- `operator_configuration` (Attributes) (see [below for nested schema](#nestedatt--operator_configuration)) +- `workspace_id` (String) + + +### Nested Schema for `operator_configuration` + +Read-Only: + +- `dbt` (Attributes) (see [below for nested schema](#nestedatt--operator_configuration--dbt)) +- `normalization` (Attributes) (see [below for nested schema](#nestedatt--operator_configuration--normalization)) +- `operator_type` (String) must be one of ["normalization", "dbt", "webhook"] +- `webhook` (Attributes) (see [below for nested schema](#nestedatt--operator_configuration--webhook)) + + +### Nested Schema for `operator_configuration.dbt` + +Read-Only: + +- `dbt_arguments` (String) +- `docker_image` (String) +- `git_repo_branch` (String) +- `git_repo_url` (String) + + + +### Nested Schema for `operator_configuration.normalization` + +Read-Only: + +- `option` (String) must be one of ["basic"] + + + +### Nested Schema for `operator_configuration.webhook` + +Read-Only: + +- `dbt_cloud` (Attributes) (see [below for nested schema](#nestedatt--operator_configuration--webhook--dbt_cloud)) +- `execution_body` (String) DEPRECATED. Populate dbtCloud instead. +- `execution_url` (String) DEPRECATED. Populate dbtCloud instead. +- `webhook_config_id` (String) The id of the webhook configs to use from the workspace. +- `webhook_type` (String) must be one of ["dbtCloud"] + + +### Nested Schema for `operator_configuration.webhook.dbt_cloud` + +Read-Only: + +- `account_id` (Number) The account id associated with the job +- `job_id` (Number) The job id associated with the job + + diff --git a/docs/data-sources/airbyte_source.md b/docs/data-sources/airbyte_source.md index a36f4ca..cc55684 100644 --- a/docs/data-sources/airbyte_source.md +++ b/docs/data-sources/airbyte_source.md @@ -14,7 +14,7 @@ Source DataSource ```terraform data "airbyte_source" "my_source" { - source_id = "f1402c7e-2666-4964-b1e5-4ee038120ec2" + source_id = "300de2cb-a926-4083-9cde-dc24be26fa48" } ``` diff --git a/docs/data-sources/airbyte_source_schema.md b/docs/data-sources/airbyte_source_schema.md index 9d0222a..796c2ab 100644 --- a/docs/data-sources/airbyte_source_schema.md +++ b/docs/data-sources/airbyte_source_schema.md @@ -14,10 +14,10 @@ SourceSchema DataSource ```terraform data "airbyte_source_schema" "my_sourceschema" { - connection_id = "2ac978db-e310-4dc6-a194-f112ed73d68a" + connection_id = "a24e9eae-dfd4-401e-81ae-1e8142cfc767" disable_cache = true notify_schema_change = false - source_id = "280eecd9-6c08-4a64-ae27-6dd0ab8d096c" + source_id = "2da61c2e-c391-4007-81f2-dadfe355f97c" } ``` diff --git a/docs/resources/airbyte_operation.md b/docs/resources/airbyte_operation.md new file mode 100644 index 0000000..27e85d2 --- /dev/null +++ b/docs/resources/airbyte_operation.md @@ -0,0 +1,111 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "airbyte_operation Resource - aballiet-terraform-provider-airbyte-oss" +subcategory: "" +description: |- + Operation Resource +--- + +# airbyte_operation (Resource) + +Operation Resource + +## Example Usage + +```terraform +resource "airbyte_operation" "my_operation" { + name = "Ervin Renner DVM" + operator_configuration = { + dbt = { + dbt_arguments = "...my_dbt_arguments..." + docker_image = "...my_docker_image..." + git_repo_branch = "...my_git_repo_branch..." + git_repo_url = "...my_git_repo_url..." + } + normalization = { + option = "basic" + } + operator_type = "dbt" + webhook = { + dbt_cloud = { + account_id = 3 + job_id = 3 + } + execution_body = "...my_execution_body..." + execution_url = "...my_execution_url..." + webhook_config_id = "25dbfb01-6861-4001-b358-7515722b625e" + webhook_type = "dbtCloud" + } + } + workspace_id = "fa1bbfa8-d645-4f71-9d13-3279f15ad8bb" +} +``` + + +## Schema + +### Required + +- `name` (String) +- `operator_configuration` (Attributes) (see [below for nested schema](#nestedatt--operator_configuration)) +- `workspace_id` (String) + +### Read-Only + +- `operation_id` (String) + + +### Nested Schema for `operator_configuration` + +Required: + +- `operator_type` (String) must be one of ["normalization", "dbt", "webhook"] + +Optional: + +- `dbt` (Attributes) (see [below for nested schema](#nestedatt--operator_configuration--dbt)) +- `normalization` (Attributes) (see [below for nested schema](#nestedatt--operator_configuration--normalization)) +- `webhook` (Attributes) (see [below for nested schema](#nestedatt--operator_configuration--webhook)) + + +### Nested Schema for `operator_configuration.dbt` + +Required: + +- `git_repo_url` (String) + +Optional: + +- `dbt_arguments` (String) +- `docker_image` (String) +- `git_repo_branch` (String) + + + +### Nested Schema for `operator_configuration.normalization` + +Optional: + +- `option` (String) must be one of ["basic"] + + + +### Nested Schema for `operator_configuration.webhook` + +Optional: + +- `dbt_cloud` (Attributes) (see [below for nested schema](#nestedatt--operator_configuration--webhook--dbt_cloud)) +- `execution_body` (String) DEPRECATED. Populate dbtCloud instead. +- `execution_url` (String) DEPRECATED. Populate dbtCloud instead. +- `webhook_config_id` (String) The id of the webhook configs to use from the workspace. +- `webhook_type` (String) must be one of ["dbtCloud"] + + +### Nested Schema for `operator_configuration.webhook.dbt_cloud` + +Required: + +- `account_id` (Number) The account id associated with the job +- `job_id` (Number) The job id associated with the job + + diff --git a/docs/resources/airbyte_source.md b/docs/resources/airbyte_source.md index d76706a..49fe2ee 100644 --- a/docs/resources/airbyte_source.md +++ b/docs/resources/airbyte_source.md @@ -15,10 +15,10 @@ Source Resource ```terraform resource "airbyte_source" "my_source" { connection_configuration = { "user" : "charles" } - name = "Ervin Renner DVM" + name = "Lana Trantow" secret_id = "airbyte_oauth_workspace_0509f049-d671-48cb-8105-0a23d47e6db6_secret_e0d38206-034e-4d75-9d21-da5a99b02826_v1" - source_definition_id = "95525dbf-b016-4861-8013-3587515722b6" - workspace_id = "25efa1bb-fa8d-4645-b719-d133279f15ad" + source_definition_id = "fac9256c-f878-4498-930f-77eda0554f68" + workspace_id = "58fc3535-457d-4244-a68f-f977c6f814b5" } ``` diff --git a/docs/resources/airbyte_source_definition.md b/docs/resources/airbyte_source_definition.md index 0da771d..e08935b 100644 --- a/docs/resources/airbyte_source_definition.md +++ b/docs/resources/airbyte_source_definition.md @@ -14,13 +14,13 @@ SourceDefinition Resource ```terraform resource "airbyte_source_definition" "my_sourcedefinition" { - scope_id = "8bb3fe33-fac9-4256-8f87-8498930f77ed" - scope_type = "organization" + scope_id = "f1dc406d-3e60-467c-8faa-27e0571d07b1" + scope_type = "workspace" source_definition = { - name = "Holly Hane" + name = "Rafael Barrows" docker_repository = "...my_docker_repository..." docker_image_tag = "...my_docker_image_tag..." - documentation_url = "http://moist-escalator.name" + documentation_url = "https://quick-witted-laboratory.biz" icon = "...my_icon..." resource_requirements = { default = { @@ -42,7 +42,7 @@ resource "airbyte_source_definition" "my_sourcedefinition" { ] } } - workspace_id = "c3535457-d244-4268-bf97-7c6f814b5f1d" + workspace_id = "355b45bc-e45d-4e0c-a038-bc3c12192fc9" } ``` diff --git a/docs/resources/airbyte_source_definition_manifest.md b/docs/resources/airbyte_source_definition_manifest.md index f70e324..2d56c91 100644 --- a/docs/resources/airbyte_source_definition_manifest.md +++ b/docs/resources/airbyte_source_definition_manifest.md @@ -18,11 +18,11 @@ resource "airbyte_source_definition_manifest" "my_sourcedefinitionmanifest" { description = "...my_description..." manifest = {} spec = {} - version = 8 + version = 1 } set_as_active_manifest = true - source_definition_id = "06d3e606-7c0f-4aa2-be05-71d07b12f607" - workspace_id = "aea75f35-5b45-4bce-85de-0c2038bc3c12" + source_definition_id = "651b10e8-de28-4ee3-9676-1ccc7d20b17e" + workspace_id = "ae1dd9c4-3502-47c4-ac7c-d806319146c8" } ``` diff --git a/docs/resources/airbyte_workspace.md b/docs/resources/airbyte_workspace.md index 4384bb0..837fb07 100644 --- a/docs/resources/airbyte_workspace.md +++ b/docs/resources/airbyte_workspace.md @@ -15,15 +15,15 @@ Workspace Resource ```terraform resource "airbyte_workspace" "my_workspace" { anonymous_data_collection = false - default_geography = "us" + default_geography = "auto" display_setup_wizard = false - email = "Ole0@hotmail.com" - name = "Jill Carroll Jr." + email = "Dante_Schulist@yahoo.com" + name = "Megan Ernser" news = false notifications = [ { customerio_configuration = {} - notification_type = "customerio" + notification_type = "slack" send_on_failure = true send_on_success = false slack_configuration = { @@ -35,7 +35,7 @@ resource "airbyte_workspace" "my_workspace" { send_on_breaking_change_syncs_disabled = { customerio_configuration = {} notification_type = [ - "slack", + "customerio", ] slack_configuration = { webhook = "...my_webhook..." @@ -44,7 +44,7 @@ resource "airbyte_workspace" "my_workspace" { send_on_breaking_change_warning = { customerio_configuration = {} notification_type = [ - "customerio", + "slack", ] slack_configuration = { webhook = "...my_webhook..." @@ -53,7 +53,7 @@ resource "airbyte_workspace" "my_workspace" { send_on_connection_update = { customerio_configuration = {} notification_type = [ - "customerio", + "slack", ] slack_configuration = { webhook = "...my_webhook..." @@ -62,7 +62,7 @@ resource "airbyte_workspace" "my_workspace" { send_on_connection_update_action_required = { customerio_configuration = {} notification_type = [ - "customerio", + "slack", ] slack_configuration = { webhook = "...my_webhook..." @@ -89,7 +89,7 @@ resource "airbyte_workspace" "my_workspace" { send_on_sync_disabled = { customerio_configuration = {} notification_type = [ - "slack", + "customerio", ] slack_configuration = { webhook = "...my_webhook..." @@ -105,13 +105,13 @@ resource "airbyte_workspace" "my_workspace" { } } } - organization_id = "61ccc7d2-0b17-4eae-9dd9-c435027c42c7" - security_updates = false + organization_id = "f1402c7e-2666-4964-b1e5-4ee038120ec2" + security_updates = true webhook_configs = [ { auth_token = "...my_auth_token..." - id = "d8063191-46c8-4408-a3d9-d1434d4688b6" - name = "Dr. Theresa Dibbert" + id = "ac978dbe-310d-4c62-994f-112ed73d68ab" + name = "Dr. Russell MacGyver" validation_url = "...my_validation_url..." }, ] diff --git a/examples/data-sources/airbyte_operation/data-source.tf b/examples/data-sources/airbyte_operation/data-source.tf new file mode 100644 index 0000000..e4715ab --- /dev/null +++ b/examples/data-sources/airbyte_operation/data-source.tf @@ -0,0 +1,3 @@ +data "airbyte_operation" "my_operation" { + operation_id = "cd96c08a-642e-4276-9d0a-b8d096c23af1" +} \ No newline at end of file diff --git a/examples/data-sources/airbyte_source/data-source.tf b/examples/data-sources/airbyte_source/data-source.tf index d41bab1..ac810da 100644 --- a/examples/data-sources/airbyte_source/data-source.tf +++ b/examples/data-sources/airbyte_source/data-source.tf @@ -1,3 +1,3 @@ data "airbyte_source" "my_source" { - source_id = "f1402c7e-2666-4964-b1e5-4ee038120ec2" + source_id = "300de2cb-a926-4083-9cde-dc24be26fa48" } \ No newline at end of file diff --git a/examples/data-sources/airbyte_source_schema/data-source.tf b/examples/data-sources/airbyte_source_schema/data-source.tf index b7ba78e..57d3f73 100644 --- a/examples/data-sources/airbyte_source_schema/data-source.tf +++ b/examples/data-sources/airbyte_source_schema/data-source.tf @@ -1,6 +1,6 @@ data "airbyte_source_schema" "my_sourceschema" { - connection_id = "2ac978db-e310-4dc6-a194-f112ed73d68a" + connection_id = "a24e9eae-dfd4-401e-81ae-1e8142cfc767" disable_cache = true notify_schema_change = false - source_id = "280eecd9-6c08-4a64-ae27-6dd0ab8d096c" + source_id = "2da61c2e-c391-4007-81f2-dadfe355f97c" } \ No newline at end of file diff --git a/examples/resources/airbyte_operation/resource.tf b/examples/resources/airbyte_operation/resource.tf new file mode 100644 index 0000000..fc118cf --- /dev/null +++ b/examples/resources/airbyte_operation/resource.tf @@ -0,0 +1,26 @@ +resource "airbyte_operation" "my_operation" { + name = "Ervin Renner DVM" + operator_configuration = { + dbt = { + dbt_arguments = "...my_dbt_arguments..." + docker_image = "...my_docker_image..." + git_repo_branch = "...my_git_repo_branch..." + git_repo_url = "...my_git_repo_url..." + } + normalization = { + option = "basic" + } + operator_type = "dbt" + webhook = { + dbt_cloud = { + account_id = 3 + job_id = 3 + } + execution_body = "...my_execution_body..." + execution_url = "...my_execution_url..." + webhook_config_id = "25dbfb01-6861-4001-b358-7515722b625e" + webhook_type = "dbtCloud" + } + } + workspace_id = "fa1bbfa8-d645-4f71-9d13-3279f15ad8bb" +} \ No newline at end of file diff --git a/examples/resources/airbyte_source/resource.tf b/examples/resources/airbyte_source/resource.tf index 45cc82f..d075df6 100644 --- a/examples/resources/airbyte_source/resource.tf +++ b/examples/resources/airbyte_source/resource.tf @@ -1,7 +1,7 @@ resource "airbyte_source" "my_source" { connection_configuration = { "user" : "charles" } - name = "Ervin Renner DVM" + name = "Lana Trantow" secret_id = "airbyte_oauth_workspace_0509f049-d671-48cb-8105-0a23d47e6db6_secret_e0d38206-034e-4d75-9d21-da5a99b02826_v1" - source_definition_id = "95525dbf-b016-4861-8013-3587515722b6" - workspace_id = "25efa1bb-fa8d-4645-b719-d133279f15ad" + source_definition_id = "fac9256c-f878-4498-930f-77eda0554f68" + workspace_id = "58fc3535-457d-4244-a68f-f977c6f814b5" } \ No newline at end of file diff --git a/examples/resources/airbyte_source_definition/resource.tf b/examples/resources/airbyte_source_definition/resource.tf index dc961cf..f7272a6 100644 --- a/examples/resources/airbyte_source_definition/resource.tf +++ b/examples/resources/airbyte_source_definition/resource.tf @@ -1,11 +1,11 @@ resource "airbyte_source_definition" "my_sourcedefinition" { - scope_id = "8bb3fe33-fac9-4256-8f87-8498930f77ed" - scope_type = "organization" + scope_id = "f1dc406d-3e60-467c-8faa-27e0571d07b1" + scope_type = "workspace" source_definition = { - name = "Holly Hane" + name = "Rafael Barrows" docker_repository = "...my_docker_repository..." docker_image_tag = "...my_docker_image_tag..." - documentation_url = "http://moist-escalator.name" + documentation_url = "https://quick-witted-laboratory.biz" icon = "...my_icon..." resource_requirements = { default = { @@ -27,5 +27,5 @@ resource "airbyte_source_definition" "my_sourcedefinition" { ] } } - workspace_id = "c3535457-d244-4268-bf97-7c6f814b5f1d" + workspace_id = "355b45bc-e45d-4e0c-a038-bc3c12192fc9" } \ No newline at end of file diff --git a/examples/resources/airbyte_source_definition_manifest/resource.tf b/examples/resources/airbyte_source_definition_manifest/resource.tf index 6ade2fb..d40bc7b 100644 --- a/examples/resources/airbyte_source_definition_manifest/resource.tf +++ b/examples/resources/airbyte_source_definition_manifest/resource.tf @@ -3,9 +3,9 @@ resource "airbyte_source_definition_manifest" "my_sourcedefinitionmanifest" { description = "...my_description..." manifest = {} spec = {} - version = 8 + version = 1 } set_as_active_manifest = true - source_definition_id = "06d3e606-7c0f-4aa2-be05-71d07b12f607" - workspace_id = "aea75f35-5b45-4bce-85de-0c2038bc3c12" + source_definition_id = "651b10e8-de28-4ee3-9676-1ccc7d20b17e" + workspace_id = "ae1dd9c4-3502-47c4-ac7c-d806319146c8" } \ No newline at end of file diff --git a/examples/resources/airbyte_workspace/resource.tf b/examples/resources/airbyte_workspace/resource.tf index 4e0893e..04c61cc 100644 --- a/examples/resources/airbyte_workspace/resource.tf +++ b/examples/resources/airbyte_workspace/resource.tf @@ -1,14 +1,14 @@ resource "airbyte_workspace" "my_workspace" { anonymous_data_collection = false - default_geography = "us" + default_geography = "auto" display_setup_wizard = false - email = "Ole0@hotmail.com" - name = "Jill Carroll Jr." + email = "Dante_Schulist@yahoo.com" + name = "Megan Ernser" news = false notifications = [ { customerio_configuration = {} - notification_type = "customerio" + notification_type = "slack" send_on_failure = true send_on_success = false slack_configuration = { @@ -20,7 +20,7 @@ resource "airbyte_workspace" "my_workspace" { send_on_breaking_change_syncs_disabled = { customerio_configuration = {} notification_type = [ - "slack", + "customerio", ] slack_configuration = { webhook = "...my_webhook..." @@ -29,7 +29,7 @@ resource "airbyte_workspace" "my_workspace" { send_on_breaking_change_warning = { customerio_configuration = {} notification_type = [ - "customerio", + "slack", ] slack_configuration = { webhook = "...my_webhook..." @@ -38,7 +38,7 @@ resource "airbyte_workspace" "my_workspace" { send_on_connection_update = { customerio_configuration = {} notification_type = [ - "customerio", + "slack", ] slack_configuration = { webhook = "...my_webhook..." @@ -47,7 +47,7 @@ resource "airbyte_workspace" "my_workspace" { send_on_connection_update_action_required = { customerio_configuration = {} notification_type = [ - "customerio", + "slack", ] slack_configuration = { webhook = "...my_webhook..." @@ -74,7 +74,7 @@ resource "airbyte_workspace" "my_workspace" { send_on_sync_disabled = { customerio_configuration = {} notification_type = [ - "slack", + "customerio", ] slack_configuration = { webhook = "...my_webhook..." @@ -90,13 +90,13 @@ resource "airbyte_workspace" "my_workspace" { } } } - organization_id = "61ccc7d2-0b17-4eae-9dd9-c435027c42c7" - security_updates = false + organization_id = "f1402c7e-2666-4964-b1e5-4ee038120ec2" + security_updates = true webhook_configs = [ { auth_token = "...my_auth_token..." - id = "d8063191-46c8-4408-a3d9-d1434d4688b6" - name = "Dr. Theresa Dibbert" + id = "ac978dbe-310d-4c62-994f-112ed73d68ab" + name = "Dr. Russell MacGyver" validation_url = "...my_validation_url..." }, ] diff --git a/files.gen b/files.gen index c29704c..8e60bf1 100755 --- a/files.gen +++ b/files.gen @@ -571,6 +571,11 @@ internal/provider/type_airbyte_stream_configuration.go internal/provider/type_airbyte_stream.go internal/provider/type_airbyte_stream_and_configuration.go internal/provider/type_airbyte_catalog.go +internal/provider/type_operator_dbt.go +internal/provider/type_operator_normalization.go +internal/provider/type_dbt_cloud.go +internal/provider/type_operator_webhook.go +internal/provider/type_operator_configuration.go internal/provider/type_job_type_resource_limit.go internal/provider/type_actor_definition_resource_requirements.go internal/provider/type_source_definition_create.go @@ -596,6 +601,9 @@ examples/provider/provider.tf internal/provider/connection_resource.go internal/provider/connection_resource_sdk.go examples/resources/airbyte_connection/resource.tf +internal/provider/operation_resource.go +internal/provider/operation_resource_sdk.go +examples/resources/airbyte_operation/resource.tf internal/provider/source_resource.go internal/provider/source_resource_sdk.go examples/resources/airbyte_source/resource.tf @@ -608,6 +616,9 @@ examples/resources/airbyte_source_definition_manifest/resource.tf internal/provider/workspace_resource.go internal/provider/workspace_resource_sdk.go examples/resources/airbyte_workspace/resource.tf +internal/provider/operation_data_source.go +internal/provider/operation_data_source_sdk.go +examples/data-sources/airbyte_operation/data-source.tf internal/provider/source_data_source.go internal/provider/source_data_source_sdk.go examples/data-sources/airbyte_source/data-source.tf diff --git a/internal/provider/operation_data_source.go b/internal/provider/operation_data_source.go new file mode 100644 index 0000000..0985554 --- /dev/null +++ b/internal/provider/operation_data_source.go @@ -0,0 +1,197 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package provider + +import ( + "context" + "fmt" + "github.com/aballiet/terraform-provider-airbyte/internal/sdk" + "github.com/aballiet/terraform-provider-airbyte/internal/sdk/pkg/models/shared" + + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-framework/types/basetypes" +) + +// Ensure provider defined types fully satisfy framework interfaces. +var _ datasource.DataSource = &OperationDataSource{} +var _ datasource.DataSourceWithConfigure = &OperationDataSource{} + +func NewOperationDataSource() datasource.DataSource { + return &OperationDataSource{} +} + +// OperationDataSource is the data source implementation. +type OperationDataSource struct { + client *sdk.SDK +} + +// OperationDataSourceModel describes the data model. +type OperationDataSourceModel struct { + Name types.String `tfsdk:"name"` + OperationID types.String `tfsdk:"operation_id"` + OperatorConfiguration OperatorConfiguration `tfsdk:"operator_configuration"` + WorkspaceID types.String `tfsdk:"workspace_id"` +} + +// Metadata returns the data source type name. +func (r *OperationDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_operation" +} + +// Schema defines the schema for the data source. +func (r *OperationDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schema.Schema{ + MarkdownDescription: "Operation DataSource", + + Attributes: map[string]schema.Attribute{ + "name": schema.StringAttribute{ + Computed: true, + }, + "operation_id": schema.StringAttribute{ + Required: true, + }, + "operator_configuration": schema.SingleNestedAttribute{ + Computed: true, + Attributes: map[string]schema.Attribute{ + "operator_type": schema.StringAttribute{ + Computed: true, + Description: `must be one of ["normalization", "dbt", "webhook"]`, + }, + "normalization": schema.SingleNestedAttribute{ + Computed: true, + Attributes: map[string]schema.Attribute{ + "option": schema.StringAttribute{ + Computed: true, + Description: `must be one of ["basic"]`, + }, + }, + }, + "dbt": schema.SingleNestedAttribute{ + Computed: true, + Attributes: map[string]schema.Attribute{ + "git_repo_url": schema.StringAttribute{ + Computed: true, + }, + "git_repo_branch": schema.StringAttribute{ + Computed: true, + }, + "docker_image": schema.StringAttribute{ + Computed: true, + }, + "dbt_arguments": schema.StringAttribute{ + Computed: true, + }, + }, + }, + "webhook": schema.SingleNestedAttribute{ + Computed: true, + Attributes: map[string]schema.Attribute{ + "webhook_config_id": schema.StringAttribute{ + Computed: true, + Description: `The id of the webhook configs to use from the workspace.`, + }, + "webhook_type": schema.StringAttribute{ + Computed: true, + Description: `must be one of ["dbtCloud"]`, + }, + "dbt_cloud": schema.SingleNestedAttribute{ + Computed: true, + Attributes: map[string]schema.Attribute{ + "account_id": schema.Int64Attribute{ + Computed: true, + Description: `The account id associated with the job`, + }, + "job_id": schema.Int64Attribute{ + Computed: true, + Description: `The job id associated with the job`, + }, + }, + }, + "execution_url": schema.StringAttribute{ + Computed: true, + Description: `DEPRECATED. Populate dbtCloud instead.`, + }, + "execution_body": schema.StringAttribute{ + Computed: true, + Description: `DEPRECATED. Populate dbtCloud instead.`, + }, + }, + }, + }, + }, + "workspace_id": schema.StringAttribute{ + Computed: true, + }, + }, + } +} + +func (r *OperationDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { + // Prevent panic if the provider has not been configured. + if req.ProviderData == nil { + return + } + + client, ok := req.ProviderData.(*sdk.SDK) + + if !ok { + resp.Diagnostics.AddError( + "Unexpected DataSource Configure Type", + fmt.Sprintf("Expected *sdk.SDK, got: %T. Please report this issue to the provider developers.", req.ProviderData), + ) + + return + } + + r.client = client +} + +func (r *OperationDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var data *OperationDataSourceModel + var item types.Object + + resp.Diagnostics.Append(req.Config.Get(ctx, &item)...) + if resp.Diagnostics.HasError() { + return + } + + resp.Diagnostics.Append(item.As(ctx, &data, basetypes.ObjectAsOptions{ + UnhandledNullAsEmpty: true, + UnhandledUnknownAsEmpty: true, + })...) + + if resp.Diagnostics.HasError() { + return + } + + operationID := data.OperationID.ValueString() + request := shared.OperationIDRequestBody{ + OperationID: operationID, + } + res, err := r.client.Operation.GetOperation(ctx, request) + if err != nil { + resp.Diagnostics.AddError("failure to invoke API", err.Error()) + if res != nil && res.RawResponse != nil { + resp.Diagnostics.AddError("unexpected http request/response", debugResponse(res.RawResponse)) + } + return + } + if res == nil { + resp.Diagnostics.AddError("unexpected response from API", fmt.Sprintf("%v", res)) + return + } + if res.StatusCode != 200 { + resp.Diagnostics.AddError(fmt.Sprintf("unexpected response from API. Got an unexpected response code %v", res.StatusCode), debugResponse(res.RawResponse)) + return + } + if res.OperationRead == nil { + resp.Diagnostics.AddError("unexpected response from API. No response body", debugResponse(res.RawResponse)) + return + } + data.RefreshFromGetResponse(res.OperationRead) + + // Save updated data into Terraform state + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} diff --git a/internal/provider/operation_data_source_sdk.go b/internal/provider/operation_data_source_sdk.go new file mode 100644 index 0000000..422361f --- /dev/null +++ b/internal/provider/operation_data_source_sdk.go @@ -0,0 +1,78 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package provider + +import ( + "github.com/aballiet/terraform-provider-airbyte/internal/sdk/pkg/models/shared" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +func (r *OperationDataSourceModel) RefreshFromGetResponse(resp *shared.OperationRead) { + r.Name = types.StringValue(resp.Name) + r.OperationID = types.StringValue(resp.OperationID) + r.OperatorConfiguration.OperatorType = types.StringValue(string(resp.OperatorConfiguration.OperatorType)) + if resp.OperatorConfiguration.Normalization == nil { + r.OperatorConfiguration.Normalization = nil + } else { + r.OperatorConfiguration.Normalization = &OperatorNormalization{} + if resp.OperatorConfiguration.Normalization.Option != nil { + r.OperatorConfiguration.Normalization.Option = types.StringValue(string(*resp.OperatorConfiguration.Normalization.Option)) + } else { + r.OperatorConfiguration.Normalization.Option = types.StringNull() + } + } + if resp.OperatorConfiguration.Dbt == nil { + r.OperatorConfiguration.Dbt = nil + } else { + r.OperatorConfiguration.Dbt = &OperatorDbt{} + r.OperatorConfiguration.Dbt.GitRepoURL = types.StringValue(resp.OperatorConfiguration.Dbt.GitRepoURL) + if resp.OperatorConfiguration.Dbt.GitRepoBranch != nil { + r.OperatorConfiguration.Dbt.GitRepoBranch = types.StringValue(*resp.OperatorConfiguration.Dbt.GitRepoBranch) + } else { + r.OperatorConfiguration.Dbt.GitRepoBranch = types.StringNull() + } + if resp.OperatorConfiguration.Dbt.DockerImage != nil { + r.OperatorConfiguration.Dbt.DockerImage = types.StringValue(*resp.OperatorConfiguration.Dbt.DockerImage) + } else { + r.OperatorConfiguration.Dbt.DockerImage = types.StringNull() + } + if resp.OperatorConfiguration.Dbt.DbtArguments != nil { + r.OperatorConfiguration.Dbt.DbtArguments = types.StringValue(*resp.OperatorConfiguration.Dbt.DbtArguments) + } else { + r.OperatorConfiguration.Dbt.DbtArguments = types.StringNull() + } + } + if resp.OperatorConfiguration.Webhook == nil { + r.OperatorConfiguration.Webhook = nil + } else { + r.OperatorConfiguration.Webhook = &OperatorWebhook{} + if resp.OperatorConfiguration.Webhook.WebhookConfigID != nil { + r.OperatorConfiguration.Webhook.WebhookConfigID = types.StringValue(*resp.OperatorConfiguration.Webhook.WebhookConfigID) + } else { + r.OperatorConfiguration.Webhook.WebhookConfigID = types.StringNull() + } + if resp.OperatorConfiguration.Webhook.WebhookType != nil { + r.OperatorConfiguration.Webhook.WebhookType = types.StringValue(string(*resp.OperatorConfiguration.Webhook.WebhookType)) + } else { + r.OperatorConfiguration.Webhook.WebhookType = types.StringNull() + } + if resp.OperatorConfiguration.Webhook.DbtCloud == nil { + r.OperatorConfiguration.Webhook.DbtCloud = nil + } else { + r.OperatorConfiguration.Webhook.DbtCloud = &DbtCloud{} + r.OperatorConfiguration.Webhook.DbtCloud.AccountID = types.Int64Value(resp.OperatorConfiguration.Webhook.DbtCloud.AccountID) + r.OperatorConfiguration.Webhook.DbtCloud.JobID = types.Int64Value(resp.OperatorConfiguration.Webhook.DbtCloud.JobID) + } + if resp.OperatorConfiguration.Webhook.ExecutionURL != nil { + r.OperatorConfiguration.Webhook.ExecutionURL = types.StringValue(*resp.OperatorConfiguration.Webhook.ExecutionURL) + } else { + r.OperatorConfiguration.Webhook.ExecutionURL = types.StringNull() + } + if resp.OperatorConfiguration.Webhook.ExecutionBody != nil { + r.OperatorConfiguration.Webhook.ExecutionBody = types.StringValue(*resp.OperatorConfiguration.Webhook.ExecutionBody) + } else { + r.OperatorConfiguration.Webhook.ExecutionBody = types.StringNull() + } + } + r.WorkspaceID = types.StringValue(resp.WorkspaceID) +} diff --git a/internal/provider/operation_resource.go b/internal/provider/operation_resource.go new file mode 100644 index 0000000..f2f70eb --- /dev/null +++ b/internal/provider/operation_resource.go @@ -0,0 +1,356 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package provider + +import ( + "context" + "fmt" + "github.com/aballiet/terraform-provider-airbyte/internal/sdk" + + "github.com/aballiet/terraform-provider-airbyte/internal/sdk/pkg/models/shared" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-framework/types/basetypes" +) + +// Ensure provider defined types fully satisfy framework interfaces. +var _ resource.Resource = &OperationResource{} +var _ resource.ResourceWithImportState = &OperationResource{} + +func NewOperationResource() resource.Resource { + return &OperationResource{} +} + +// OperationResource defines the resource implementation. +type OperationResource struct { + client *sdk.SDK +} + +// OperationResourceModel describes the resource data model. +type OperationResourceModel struct { + Name types.String `tfsdk:"name"` + OperationID types.String `tfsdk:"operation_id"` + OperatorConfiguration OperatorConfiguration `tfsdk:"operator_configuration"` + WorkspaceID types.String `tfsdk:"workspace_id"` +} + +func (r *OperationResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_operation" +} + +func (r *OperationResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = schema.Schema{ + MarkdownDescription: "Operation Resource", + + Attributes: map[string]schema.Attribute{ + "name": schema.StringAttribute{ + Required: true, + }, + "operation_id": schema.StringAttribute{ + Computed: true, + }, + "operator_configuration": schema.SingleNestedAttribute{ + Required: true, + Attributes: map[string]schema.Attribute{ + "dbt": schema.SingleNestedAttribute{ + Computed: true, + Optional: true, + Attributes: map[string]schema.Attribute{ + "dbt_arguments": schema.StringAttribute{ + Computed: true, + Optional: true, + }, + "docker_image": schema.StringAttribute{ + Computed: true, + Optional: true, + }, + "git_repo_branch": schema.StringAttribute{ + Computed: true, + Optional: true, + }, + "git_repo_url": schema.StringAttribute{ + Required: true, + }, + }, + }, + "normalization": schema.SingleNestedAttribute{ + Computed: true, + Optional: true, + Attributes: map[string]schema.Attribute{ + "option": schema.StringAttribute{ + Computed: true, + Optional: true, + Description: `must be one of ["basic"]`, + Validators: []validator.String{ + stringvalidator.OneOf( + "basic", + ), + }, + }, + }, + }, + "operator_type": schema.StringAttribute{ + Required: true, + Description: `must be one of ["normalization", "dbt", "webhook"]`, + Validators: []validator.String{ + stringvalidator.OneOf( + "normalization", + "dbt", + "webhook", + ), + }, + }, + "webhook": schema.SingleNestedAttribute{ + Computed: true, + Optional: true, + Attributes: map[string]schema.Attribute{ + "dbt_cloud": schema.SingleNestedAttribute{ + Computed: true, + Optional: true, + Attributes: map[string]schema.Attribute{ + "account_id": schema.Int64Attribute{ + Required: true, + Description: `The account id associated with the job`, + }, + "job_id": schema.Int64Attribute{ + Required: true, + Description: `The job id associated with the job`, + }, + }, + }, + "execution_body": schema.StringAttribute{ + Computed: true, + Optional: true, + Description: `DEPRECATED. Populate dbtCloud instead.`, + }, + "execution_url": schema.StringAttribute{ + Computed: true, + Optional: true, + Description: `DEPRECATED. Populate dbtCloud instead.`, + }, + "webhook_config_id": schema.StringAttribute{ + Computed: true, + Optional: true, + Description: `The id of the webhook configs to use from the workspace.`, + }, + "webhook_type": schema.StringAttribute{ + Computed: true, + Optional: true, + Description: `must be one of ["dbtCloud"]`, + Validators: []validator.String{ + stringvalidator.OneOf( + "dbtCloud", + ), + }, + }, + }, + }, + }, + }, + "workspace_id": schema.StringAttribute{ + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + Required: true, + }, + }, + } +} + +func (r *OperationResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { + // Prevent panic if the provider has not been configured. + if req.ProviderData == nil { + return + } + + client, ok := req.ProviderData.(*sdk.SDK) + + if !ok { + resp.Diagnostics.AddError( + "Unexpected Resource Configure Type", + fmt.Sprintf("Expected *sdk.SDK, got: %T. Please report this issue to the provider developers.", req.ProviderData), + ) + + return + } + + r.client = client +} + +func (r *OperationResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var data *OperationResourceModel + var item types.Object + + resp.Diagnostics.Append(req.Plan.Get(ctx, &item)...) + if resp.Diagnostics.HasError() { + return + } + + resp.Diagnostics.Append(item.As(ctx, &data, basetypes.ObjectAsOptions{ + UnhandledNullAsEmpty: true, + UnhandledUnknownAsEmpty: true, + })...) + + if resp.Diagnostics.HasError() { + return + } + + request := *data.ToCreateSDKType() + res, err := r.client.Operation.CreateOperation(ctx, request) + if err != nil { + resp.Diagnostics.AddError("failure to invoke API", err.Error()) + if res != nil && res.RawResponse != nil { + resp.Diagnostics.AddError("unexpected http request/response", debugResponse(res.RawResponse)) + } + return + } + if res == nil { + resp.Diagnostics.AddError("unexpected response from API", fmt.Sprintf("%v", res)) + return + } + if res.StatusCode != 200 { + resp.Diagnostics.AddError(fmt.Sprintf("unexpected response from API. Got an unexpected response code %v", res.StatusCode), debugResponse(res.RawResponse)) + return + } + if res.OperationRead == nil { + resp.Diagnostics.AddError("unexpected response from API. No response body", debugResponse(res.RawResponse)) + return + } + data.RefreshFromCreateResponse(res.OperationRead) + + // Save updated data into Terraform state + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} + +func (r *OperationResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var data *OperationResourceModel + var item types.Object + + resp.Diagnostics.Append(req.State.Get(ctx, &item)...) + if resp.Diagnostics.HasError() { + return + } + + resp.Diagnostics.Append(item.As(ctx, &data, basetypes.ObjectAsOptions{ + UnhandledNullAsEmpty: true, + UnhandledUnknownAsEmpty: true, + })...) + + if resp.Diagnostics.HasError() { + return + } + + operationID := data.OperationID.ValueString() + request := shared.OperationIDRequestBody{ + OperationID: operationID, + } + res, err := r.client.Operation.GetOperation(ctx, request) + if err != nil { + resp.Diagnostics.AddError("failure to invoke API", err.Error()) + if res != nil && res.RawResponse != nil { + resp.Diagnostics.AddError("unexpected http request/response", debugResponse(res.RawResponse)) + } + return + } + if res == nil { + resp.Diagnostics.AddError("unexpected response from API", fmt.Sprintf("%v", res)) + return + } + if res.StatusCode != 200 { + resp.Diagnostics.AddError(fmt.Sprintf("unexpected response from API. Got an unexpected response code %v", res.StatusCode), debugResponse(res.RawResponse)) + return + } + if res.OperationRead == nil { + resp.Diagnostics.AddError("unexpected response from API. No response body", debugResponse(res.RawResponse)) + return + } + data.RefreshFromGetResponse(res.OperationRead) + + // Save updated data into Terraform state + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} + +func (r *OperationResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var data *OperationResourceModel + merge(ctx, req, resp, &data) + if resp.Diagnostics.HasError() { + return + } + + request := *data.ToUpdateSDKType() + res, err := r.client.Operation.UpdateOperation(ctx, request) + if err != nil { + resp.Diagnostics.AddError("failure to invoke API", err.Error()) + if res != nil && res.RawResponse != nil { + resp.Diagnostics.AddError("unexpected http request/response", debugResponse(res.RawResponse)) + } + return + } + if res == nil { + resp.Diagnostics.AddError("unexpected response from API", fmt.Sprintf("%v", res)) + return + } + if res.StatusCode != 200 { + resp.Diagnostics.AddError(fmt.Sprintf("unexpected response from API. Got an unexpected response code %v", res.StatusCode), debugResponse(res.RawResponse)) + return + } + if res.OperationRead == nil { + resp.Diagnostics.AddError("unexpected response from API. No response body", debugResponse(res.RawResponse)) + return + } + data.RefreshFromUpdateResponse(res.OperationRead) + + // Save updated data into Terraform state + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} + +func (r *OperationResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var data *OperationResourceModel + var item types.Object + + resp.Diagnostics.Append(req.State.Get(ctx, &item)...) + if resp.Diagnostics.HasError() { + return + } + + resp.Diagnostics.Append(item.As(ctx, &data, basetypes.ObjectAsOptions{ + UnhandledNullAsEmpty: true, + UnhandledUnknownAsEmpty: true, + })...) + + if resp.Diagnostics.HasError() { + return + } + + operationID := data.OperationID.ValueString() + request := shared.OperationIDRequestBody{ + OperationID: operationID, + } + res, err := r.client.Operation.DeleteOperation(ctx, request) + if err != nil { + resp.Diagnostics.AddError("failure to invoke API", err.Error()) + if res != nil && res.RawResponse != nil { + resp.Diagnostics.AddError("unexpected http request/response", debugResponse(res.RawResponse)) + } + return + } + if res == nil { + resp.Diagnostics.AddError("unexpected response from API", fmt.Sprintf("%v", res)) + return + } + if res.StatusCode != 204 { + resp.Diagnostics.AddError(fmt.Sprintf("unexpected response from API. Got an unexpected response code %v", res.StatusCode), debugResponse(res.RawResponse)) + return + } + +} + +func (r *OperationResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("operation_id"), req.ID)...) +} diff --git a/internal/provider/operation_resource_sdk.go b/internal/provider/operation_resource_sdk.go new file mode 100644 index 0000000..a3c4bc5 --- /dev/null +++ b/internal/provider/operation_resource_sdk.go @@ -0,0 +1,298 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package provider + +import ( + "github.com/aballiet/terraform-provider-airbyte/internal/sdk/pkg/models/shared" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +func (r *OperationResourceModel) ToCreateSDKType() *shared.OperationCreate { + workspaceID := r.WorkspaceID.ValueString() + name := r.Name.ValueString() + operatorType := shared.OperatorType(r.OperatorConfiguration.OperatorType.ValueString()) + var normalization *shared.OperatorNormalization + if r.OperatorConfiguration.Normalization != nil { + option := new(shared.Option) + if !r.OperatorConfiguration.Normalization.Option.IsUnknown() && !r.OperatorConfiguration.Normalization.Option.IsNull() { + *option = shared.Option(r.OperatorConfiguration.Normalization.Option.ValueString()) + } else { + option = nil + } + normalization = &shared.OperatorNormalization{ + Option: option, + } + } + var dbt *shared.OperatorDbt + if r.OperatorConfiguration.Dbt != nil { + gitRepoURL := r.OperatorConfiguration.Dbt.GitRepoURL.ValueString() + gitRepoBranch := new(string) + if !r.OperatorConfiguration.Dbt.GitRepoBranch.IsUnknown() && !r.OperatorConfiguration.Dbt.GitRepoBranch.IsNull() { + *gitRepoBranch = r.OperatorConfiguration.Dbt.GitRepoBranch.ValueString() + } else { + gitRepoBranch = nil + } + dockerImage := new(string) + if !r.OperatorConfiguration.Dbt.DockerImage.IsUnknown() && !r.OperatorConfiguration.Dbt.DockerImage.IsNull() { + *dockerImage = r.OperatorConfiguration.Dbt.DockerImage.ValueString() + } else { + dockerImage = nil + } + dbtArguments := new(string) + if !r.OperatorConfiguration.Dbt.DbtArguments.IsUnknown() && !r.OperatorConfiguration.Dbt.DbtArguments.IsNull() { + *dbtArguments = r.OperatorConfiguration.Dbt.DbtArguments.ValueString() + } else { + dbtArguments = nil + } + dbt = &shared.OperatorDbt{ + GitRepoURL: gitRepoURL, + GitRepoBranch: gitRepoBranch, + DockerImage: dockerImage, + DbtArguments: dbtArguments, + } + } + var webhook *shared.OperatorWebhook + if r.OperatorConfiguration.Webhook != nil { + webhookConfigID := new(string) + if !r.OperatorConfiguration.Webhook.WebhookConfigID.IsUnknown() && !r.OperatorConfiguration.Webhook.WebhookConfigID.IsNull() { + *webhookConfigID = r.OperatorConfiguration.Webhook.WebhookConfigID.ValueString() + } else { + webhookConfigID = nil + } + webhookType := new(shared.WebhookType) + if !r.OperatorConfiguration.Webhook.WebhookType.IsUnknown() && !r.OperatorConfiguration.Webhook.WebhookType.IsNull() { + *webhookType = shared.WebhookType(r.OperatorConfiguration.Webhook.WebhookType.ValueString()) + } else { + webhookType = nil + } + var dbtCloud *shared.DbtCloud + if r.OperatorConfiguration.Webhook.DbtCloud != nil { + accountID := r.OperatorConfiguration.Webhook.DbtCloud.AccountID.ValueInt64() + jobID := r.OperatorConfiguration.Webhook.DbtCloud.JobID.ValueInt64() + dbtCloud = &shared.DbtCloud{ + AccountID: accountID, + JobID: jobID, + } + } + executionURL := new(string) + if !r.OperatorConfiguration.Webhook.ExecutionURL.IsUnknown() && !r.OperatorConfiguration.Webhook.ExecutionURL.IsNull() { + *executionURL = r.OperatorConfiguration.Webhook.ExecutionURL.ValueString() + } else { + executionURL = nil + } + executionBody := new(string) + if !r.OperatorConfiguration.Webhook.ExecutionBody.IsUnknown() && !r.OperatorConfiguration.Webhook.ExecutionBody.IsNull() { + *executionBody = r.OperatorConfiguration.Webhook.ExecutionBody.ValueString() + } else { + executionBody = nil + } + webhook = &shared.OperatorWebhook{ + WebhookConfigID: webhookConfigID, + WebhookType: webhookType, + DbtCloud: dbtCloud, + ExecutionURL: executionURL, + ExecutionBody: executionBody, + } + } + operatorConfiguration := shared.OperatorConfiguration{ + OperatorType: operatorType, + Normalization: normalization, + Dbt: dbt, + Webhook: webhook, + } + out := shared.OperationCreate{ + WorkspaceID: workspaceID, + Name: name, + OperatorConfiguration: operatorConfiguration, + } + return &out +} + +func (r *OperationResourceModel) ToGetSDKType() *shared.OperationCreate { + out := r.ToCreateSDKType() + return out +} + +func (r *OperationResourceModel) ToUpdateSDKType() *shared.OperationUpdate { + operationID := r.OperationID.ValueString() + name := r.Name.ValueString() + operatorType := shared.OperatorType(r.OperatorConfiguration.OperatorType.ValueString()) + var normalization *shared.OperatorNormalization + if r.OperatorConfiguration.Normalization != nil { + option := new(shared.Option) + if !r.OperatorConfiguration.Normalization.Option.IsUnknown() && !r.OperatorConfiguration.Normalization.Option.IsNull() { + *option = shared.Option(r.OperatorConfiguration.Normalization.Option.ValueString()) + } else { + option = nil + } + normalization = &shared.OperatorNormalization{ + Option: option, + } + } + var dbt *shared.OperatorDbt + if r.OperatorConfiguration.Dbt != nil { + gitRepoURL := r.OperatorConfiguration.Dbt.GitRepoURL.ValueString() + gitRepoBranch := new(string) + if !r.OperatorConfiguration.Dbt.GitRepoBranch.IsUnknown() && !r.OperatorConfiguration.Dbt.GitRepoBranch.IsNull() { + *gitRepoBranch = r.OperatorConfiguration.Dbt.GitRepoBranch.ValueString() + } else { + gitRepoBranch = nil + } + dockerImage := new(string) + if !r.OperatorConfiguration.Dbt.DockerImage.IsUnknown() && !r.OperatorConfiguration.Dbt.DockerImage.IsNull() { + *dockerImage = r.OperatorConfiguration.Dbt.DockerImage.ValueString() + } else { + dockerImage = nil + } + dbtArguments := new(string) + if !r.OperatorConfiguration.Dbt.DbtArguments.IsUnknown() && !r.OperatorConfiguration.Dbt.DbtArguments.IsNull() { + *dbtArguments = r.OperatorConfiguration.Dbt.DbtArguments.ValueString() + } else { + dbtArguments = nil + } + dbt = &shared.OperatorDbt{ + GitRepoURL: gitRepoURL, + GitRepoBranch: gitRepoBranch, + DockerImage: dockerImage, + DbtArguments: dbtArguments, + } + } + var webhook *shared.OperatorWebhook + if r.OperatorConfiguration.Webhook != nil { + webhookConfigID := new(string) + if !r.OperatorConfiguration.Webhook.WebhookConfigID.IsUnknown() && !r.OperatorConfiguration.Webhook.WebhookConfigID.IsNull() { + *webhookConfigID = r.OperatorConfiguration.Webhook.WebhookConfigID.ValueString() + } else { + webhookConfigID = nil + } + webhookType := new(shared.WebhookType) + if !r.OperatorConfiguration.Webhook.WebhookType.IsUnknown() && !r.OperatorConfiguration.Webhook.WebhookType.IsNull() { + *webhookType = shared.WebhookType(r.OperatorConfiguration.Webhook.WebhookType.ValueString()) + } else { + webhookType = nil + } + var dbtCloud *shared.DbtCloud + if r.OperatorConfiguration.Webhook.DbtCloud != nil { + accountID := r.OperatorConfiguration.Webhook.DbtCloud.AccountID.ValueInt64() + jobID := r.OperatorConfiguration.Webhook.DbtCloud.JobID.ValueInt64() + dbtCloud = &shared.DbtCloud{ + AccountID: accountID, + JobID: jobID, + } + } + executionURL := new(string) + if !r.OperatorConfiguration.Webhook.ExecutionURL.IsUnknown() && !r.OperatorConfiguration.Webhook.ExecutionURL.IsNull() { + *executionURL = r.OperatorConfiguration.Webhook.ExecutionURL.ValueString() + } else { + executionURL = nil + } + executionBody := new(string) + if !r.OperatorConfiguration.Webhook.ExecutionBody.IsUnknown() && !r.OperatorConfiguration.Webhook.ExecutionBody.IsNull() { + *executionBody = r.OperatorConfiguration.Webhook.ExecutionBody.ValueString() + } else { + executionBody = nil + } + webhook = &shared.OperatorWebhook{ + WebhookConfigID: webhookConfigID, + WebhookType: webhookType, + DbtCloud: dbtCloud, + ExecutionURL: executionURL, + ExecutionBody: executionBody, + } + } + operatorConfiguration := shared.OperatorConfiguration{ + OperatorType: operatorType, + Normalization: normalization, + Dbt: dbt, + Webhook: webhook, + } + out := shared.OperationUpdate{ + OperationID: operationID, + Name: name, + OperatorConfiguration: operatorConfiguration, + } + return &out +} + +func (r *OperationResourceModel) ToDeleteSDKType() *shared.OperationCreate { + out := r.ToCreateSDKType() + return out +} + +func (r *OperationResourceModel) RefreshFromGetResponse(resp *shared.OperationRead) { + r.Name = types.StringValue(resp.Name) + r.OperationID = types.StringValue(resp.OperationID) + if resp.OperatorConfiguration.Dbt == nil { + r.OperatorConfiguration.Dbt = nil + } else { + r.OperatorConfiguration.Dbt = &OperatorDbt{} + if resp.OperatorConfiguration.Dbt.DbtArguments != nil { + r.OperatorConfiguration.Dbt.DbtArguments = types.StringValue(*resp.OperatorConfiguration.Dbt.DbtArguments) + } else { + r.OperatorConfiguration.Dbt.DbtArguments = types.StringNull() + } + if resp.OperatorConfiguration.Dbt.DockerImage != nil { + r.OperatorConfiguration.Dbt.DockerImage = types.StringValue(*resp.OperatorConfiguration.Dbt.DockerImage) + } else { + r.OperatorConfiguration.Dbt.DockerImage = types.StringNull() + } + if resp.OperatorConfiguration.Dbt.GitRepoBranch != nil { + r.OperatorConfiguration.Dbt.GitRepoBranch = types.StringValue(*resp.OperatorConfiguration.Dbt.GitRepoBranch) + } else { + r.OperatorConfiguration.Dbt.GitRepoBranch = types.StringNull() + } + r.OperatorConfiguration.Dbt.GitRepoURL = types.StringValue(resp.OperatorConfiguration.Dbt.GitRepoURL) + } + if resp.OperatorConfiguration.Normalization == nil { + r.OperatorConfiguration.Normalization = nil + } else { + r.OperatorConfiguration.Normalization = &OperatorNormalization{} + if resp.OperatorConfiguration.Normalization.Option != nil { + r.OperatorConfiguration.Normalization.Option = types.StringValue(string(*resp.OperatorConfiguration.Normalization.Option)) + } else { + r.OperatorConfiguration.Normalization.Option = types.StringNull() + } + } + r.OperatorConfiguration.OperatorType = types.StringValue(string(resp.OperatorConfiguration.OperatorType)) + if resp.OperatorConfiguration.Webhook == nil { + r.OperatorConfiguration.Webhook = nil + } else { + r.OperatorConfiguration.Webhook = &OperatorWebhook{} + if resp.OperatorConfiguration.Webhook.DbtCloud == nil { + r.OperatorConfiguration.Webhook.DbtCloud = nil + } else { + r.OperatorConfiguration.Webhook.DbtCloud = &DbtCloud{} + r.OperatorConfiguration.Webhook.DbtCloud.AccountID = types.Int64Value(resp.OperatorConfiguration.Webhook.DbtCloud.AccountID) + r.OperatorConfiguration.Webhook.DbtCloud.JobID = types.Int64Value(resp.OperatorConfiguration.Webhook.DbtCloud.JobID) + } + if resp.OperatorConfiguration.Webhook.ExecutionBody != nil { + r.OperatorConfiguration.Webhook.ExecutionBody = types.StringValue(*resp.OperatorConfiguration.Webhook.ExecutionBody) + } else { + r.OperatorConfiguration.Webhook.ExecutionBody = types.StringNull() + } + if resp.OperatorConfiguration.Webhook.ExecutionURL != nil { + r.OperatorConfiguration.Webhook.ExecutionURL = types.StringValue(*resp.OperatorConfiguration.Webhook.ExecutionURL) + } else { + r.OperatorConfiguration.Webhook.ExecutionURL = types.StringNull() + } + if resp.OperatorConfiguration.Webhook.WebhookConfigID != nil { + r.OperatorConfiguration.Webhook.WebhookConfigID = types.StringValue(*resp.OperatorConfiguration.Webhook.WebhookConfigID) + } else { + r.OperatorConfiguration.Webhook.WebhookConfigID = types.StringNull() + } + if resp.OperatorConfiguration.Webhook.WebhookType != nil { + r.OperatorConfiguration.Webhook.WebhookType = types.StringValue(string(*resp.OperatorConfiguration.Webhook.WebhookType)) + } else { + r.OperatorConfiguration.Webhook.WebhookType = types.StringNull() + } + } + r.WorkspaceID = types.StringValue(resp.WorkspaceID) +} + +func (r *OperationResourceModel) RefreshFromCreateResponse(resp *shared.OperationRead) { + r.RefreshFromGetResponse(resp) +} + +func (r *OperationResourceModel) RefreshFromUpdateResponse(resp *shared.OperationRead) { + r.RefreshFromGetResponse(resp) +} diff --git a/internal/provider/provider.go b/internal/provider/provider.go index e3c4a56..ad3d9dc 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -114,6 +114,7 @@ func (p *AirbyteProvider) Configure(ctx context.Context, req provider.ConfigureR func (p *AirbyteProvider) Resources(ctx context.Context) []func() resource.Resource { return []func() resource.Resource{ NewConnectionResource, + NewOperationResource, NewSourceResource, NewSourceDefinitionResource, NewSourceDefinitionManifestResource, @@ -123,6 +124,7 @@ func (p *AirbyteProvider) Resources(ctx context.Context) []func() resource.Resou func (p *AirbyteProvider) DataSources(ctx context.Context) []func() datasource.DataSource { return []func() datasource.DataSource{ + NewOperationDataSource, NewSourceDataSource, NewSourceSchemaDataSource, } diff --git a/internal/provider/type_dbt_cloud.go b/internal/provider/type_dbt_cloud.go new file mode 100644 index 0000000..0822fb0 --- /dev/null +++ b/internal/provider/type_dbt_cloud.go @@ -0,0 +1,10 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package provider + +import "github.com/hashicorp/terraform-plugin-framework/types" + +type DbtCloud struct { + AccountID types.Int64 `tfsdk:"account_id"` + JobID types.Int64 `tfsdk:"job_id"` +} diff --git a/internal/provider/type_operator_configuration.go b/internal/provider/type_operator_configuration.go new file mode 100644 index 0000000..98cd22a --- /dev/null +++ b/internal/provider/type_operator_configuration.go @@ -0,0 +1,12 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package provider + +import "github.com/hashicorp/terraform-plugin-framework/types" + +type OperatorConfiguration struct { + Dbt *OperatorDbt `tfsdk:"dbt"` + Normalization *OperatorNormalization `tfsdk:"normalization"` + OperatorType types.String `tfsdk:"operator_type"` + Webhook *OperatorWebhook `tfsdk:"webhook"` +} diff --git a/internal/provider/type_operator_dbt.go b/internal/provider/type_operator_dbt.go new file mode 100644 index 0000000..fcb55a4 --- /dev/null +++ b/internal/provider/type_operator_dbt.go @@ -0,0 +1,12 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package provider + +import "github.com/hashicorp/terraform-plugin-framework/types" + +type OperatorDbt struct { + DbtArguments types.String `tfsdk:"dbt_arguments"` + DockerImage types.String `tfsdk:"docker_image"` + GitRepoBranch types.String `tfsdk:"git_repo_branch"` + GitRepoURL types.String `tfsdk:"git_repo_url"` +} diff --git a/internal/provider/type_operator_normalization.go b/internal/provider/type_operator_normalization.go new file mode 100644 index 0000000..07a40c9 --- /dev/null +++ b/internal/provider/type_operator_normalization.go @@ -0,0 +1,9 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package provider + +import "github.com/hashicorp/terraform-plugin-framework/types" + +type OperatorNormalization struct { + Option types.String `tfsdk:"option"` +} diff --git a/internal/provider/type_operator_webhook.go b/internal/provider/type_operator_webhook.go new file mode 100644 index 0000000..9c8dd76 --- /dev/null +++ b/internal/provider/type_operator_webhook.go @@ -0,0 +1,13 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package provider + +import "github.com/hashicorp/terraform-plugin-framework/types" + +type OperatorWebhook struct { + DbtCloud *DbtCloud `tfsdk:"dbt_cloud"` + ExecutionBody types.String `tfsdk:"execution_body"` + ExecutionURL types.String `tfsdk:"execution_url"` + WebhookConfigID types.String `tfsdk:"webhook_config_id"` + WebhookType types.String `tfsdk:"webhook_type"` +} From 8044e6f0adc661d92de3fa25ba2a8af24769aaf0 Mon Sep 17 00:00:00 2001 From: Antoine Balliet Date: Fri, 17 Nov 2023 10:11:28 +0100 Subject: [PATCH 2/3] doc: update --- README.md | 9 ++++++--- docs/index.md | 8 +++++--- examples/provider/provider.tf | 2 +- gen.yaml | 2 +- internal/sdk/sdk.go | 4 ++-- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 0e1d430..d1c3964 100755 --- a/README.md +++ b/README.md @@ -9,14 +9,17 @@ To install this provider, copy and paste this code into your Terraform configura terraform { required_providers { airbyte = { - source = "aballiet/airbyte" - version = "1.0.6" + source = "aballiet/airbyte-oss" + version = "1.0.7" } } } provider "airbyte" { - # Configuration options + # Must match your Airbyte server endpoint (airbyte-server-svc on k8s) + server_url = "http://localhost:8001/api/" + username = "YOUR_USERNAME" + password = "YOUR_PASSWORD" } ``` diff --git a/docs/index.md b/docs/index.md index 309232a..ed42da4 100644 --- a/docs/index.md +++ b/docs/index.md @@ -57,14 +57,16 @@ Authentication (OSS): terraform { required_providers { airbyte = { - source = "aballiet/airbyte" - version = "1.0.6" + source = "aballiet/airbyte-oss" + version = "1.0.7" } } } provider "airbyte" { - # Configuration options + server_url = "http://localhost:8001/api/" # Must match your Airbyte server endpoint (airbyte-server-svc on k8s) + username = "YOUR_USERNAME" + password = "YOUR_PASSWORD" } ``` diff --git a/examples/provider/provider.tf b/examples/provider/provider.tf index f384d6d..4ec8c6c 100644 --- a/examples/provider/provider.tf +++ b/examples/provider/provider.tf @@ -2,7 +2,7 @@ terraform { required_providers { airbyte = { source = "aballiet/airbyte" - version = "1.0.6" + version = "1.0.7" } } } diff --git a/gen.yaml b/gen.yaml index 2c265b6..bdce6e1 100755 --- a/gen.yaml +++ b/gen.yaml @@ -13,7 +13,7 @@ features: globalSecurity: 2.81.1 globalServerURLs: 2.82.0 terraform: - version: 1.0.6 + version: 1.0.7 author: aballiet imports: option: openapi diff --git a/internal/sdk/sdk.go b/internal/sdk/sdk.go index ad36e8e..6246635 100644 --- a/internal/sdk/sdk.go +++ b/internal/sdk/sdk.go @@ -217,9 +217,9 @@ func New(opts ...SDKOption) *SDK { sdkConfiguration: sdkConfiguration{ Language: "go", OpenAPIDocVersion: "1.0.0", - SDKVersion: "1.0.6", + SDKVersion: "1.0.7", GenVersion: "2.192.1", - UserAgent: "speakeasy-sdk/go 1.0.6 2.192.1 1.0.0 airbyte", + UserAgent: "speakeasy-sdk/go 1.0.7 2.192.1 1.0.0 airbyte", }, } for _, opt := range opts { From 8e926dc14c8f0eb709ca21ecfbe83ab506834283 Mon Sep 17 00:00:00 2001 From: Antoine Balliet Date: Fri, 17 Nov 2023 12:57:09 +0100 Subject: [PATCH 3/3] Update index.md --- docs/index.md | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/docs/index.md b/docs/index.md index ed42da4..a719898 100644 --- a/docs/index.md +++ b/docs/index.md @@ -40,16 +40,8 @@ WARNING * This API is utilized internally by the Airbyte Engineering team and may be modified in the future if the need arises. * Modifications by the Airbyte Engineering team could create breaking changes and OSS users would need to update their code to catch up to any backwards incompatible changes in the API. -This API is a collection of HTTP RPC-style methods. While it is not a REST API, those familiar with REST should find the conventions of this API recognizable. - -Here are some conventions that this API follows: -* All endpoints are http POST methods. -* All endpoints accept data via `application/json` request bodies. The API does not accept any data via query params. -* The naming convention for endpoints is: localhost:8000/{VERSION}/{METHOD_FAMILY}/{METHOD_NAME} e.g. `localhost:8000/v1/connections/create`. -* For all `update` methods, the whole object must be passed in, even the fields that did not change. - Authentication (OSS): -* When authenticating to the Configuration API, you must use Basic Authentication by setting the Authentication Header to Basic and base64 encoding the username and password (which are `airbyte` and `password` by default - so base64 encoding `airbyte:password` results in `YWlyYnl0ZTpwYXNzd29yZA==`). So the full header reads `'Authorization': "Basic YWlyYnl0ZTpwYXNzd29yZA=="` +* When authenticating to the Configuration API, you must use Basic Authentication by setting username and password (which are `airbyte` and `password` by default). ## Example Usage @@ -70,6 +62,36 @@ provider "airbyte" { } ``` +Below a full example with a custom connector : defining a `SourceDefintion`, `Source` and a `Connection` : + +```hcl + +locals { + workspace_id = "" +} + +resource "airbyte_source_definition" "ashby" { + source_definition = { + docker_image_tag = "0.1.0" + docker_repository = "us-central1-docker.pkg.dev//airbyte/source-ashby" + documentation_url = "https://developers.ashbyhq.com/reference/introduction" + name = "Ashby" + } + workspace_id = local.workspace_id +} + +resource "airbyte_source" "ashby" { + connection_configuration = jsonencode({ + api_key = "" + }) + name = "Ashby" + source_definition_id = airbyte_source_definition.ashby.source_definition_id + workspace_id = local.workspace_id +} + +# TODO for connection : I will publish a Terraform module to make it easier (need to discover Stream schema) +``` + ## Schema