diff --git a/.codegen/_openapi_sha b/.codegen/_openapi_sha index 9fbcbf16e0..f1223de085 100755 --- a/.codegen/_openapi_sha +++ b/.codegen/_openapi_sha @@ -1 +1 @@ -fdd601b0b898ac466db7fc48626fa9247c22b0cc \ No newline at end of file +0b8f4fd36b4cd47ad6c053f11b7b551c9d7da814 \ No newline at end of file diff --git a/.gitattributes b/.gitattributes index 5f0dd2875b..ec12cdc993 100755 --- a/.gitattributes +++ b/.gitattributes @@ -69,6 +69,7 @@ docs/data-sources/policy_infos.md linguist-generated=true docs/data-sources/postgres_branch.md linguist-generated=true docs/data-sources/postgres_branches.md linguist-generated=true docs/data-sources/postgres_catalog.md linguist-generated=true +docs/data-sources/postgres_data_api.md linguist-generated=true docs/data-sources/postgres_database.md linguist-generated=true docs/data-sources/postgres_databases.md linguist-generated=true docs/data-sources/postgres_endpoint.md linguist-generated=true @@ -130,6 +131,7 @@ docs/resources/online_store.md linguist-generated=true docs/resources/policy_info.md linguist-generated=true docs/resources/postgres_branch.md linguist-generated=true docs/resources/postgres_catalog.md linguist-generated=true +docs/resources/postgres_data_api.md linguist-generated=true docs/resources/postgres_database.md linguist-generated=true docs/resources/postgres_endpoint.md linguist-generated=true docs/resources/postgres_project.md linguist-generated=true @@ -252,6 +254,8 @@ internal/providers/pluginfw/products/postgres_branch/data_postgres_branches.go l internal/providers/pluginfw/products/postgres_branch/resource_postgres_branch.go linguist-generated=true internal/providers/pluginfw/products/postgres_catalog/data_postgres_catalog.go linguist-generated=true internal/providers/pluginfw/products/postgres_catalog/resource_postgres_catalog.go linguist-generated=true +internal/providers/pluginfw/products/postgres_data_api/data_postgres_data_api.go linguist-generated=true +internal/providers/pluginfw/products/postgres_data_api/resource_postgres_data_api.go linguist-generated=true internal/providers/pluginfw/products/postgres_database/data_postgres_database.go linguist-generated=true internal/providers/pluginfw/products/postgres_database/data_postgres_databases.go linguist-generated=true internal/providers/pluginfw/products/postgres_database/resource_postgres_database.go linguist-generated=true diff --git a/NEXT_CHANGELOG.md b/NEXT_CHANGELOG.md old mode 100644 new mode 100755 index d038b5e88d..dcbddcfb1b --- a/NEXT_CHANGELOG.md +++ b/NEXT_CHANGELOG.md @@ -5,6 +5,7 @@ ### Breaking Changes ### New Features and Improvements +* Add resource and data source for `databricks_postgres_data_api`. * Add resource and data sources for `databricks_ai_search_endpoint`. * Add resource and data sources for `databricks_ai_search_index`. diff --git a/common/customizable_schema.go b/common/customizable_schema.go old mode 100644 new mode 100755 index c38d2fa7f1..3af9bd27a1 --- a/common/customizable_schema.go +++ b/common/customizable_schema.go @@ -118,7 +118,14 @@ func (s *CustomizableSchema) SetRequired() *CustomizableSchema { } func (s *CustomizableSchema) SetSuppressDiff() *CustomizableSchema { - s.Schema.DiffSuppressFunc = diffSuppressor(s.path[len(s.path)-1], s.Schema) + return s.SetConditionalSuppressDiff(alwaysSuppress) +} + +// SetConditionalSuppressDiff behaves like SetSuppressDiff, but only suppresses +// the diff when enable returns true. This lets a resource gate the suppression +// on, for example, the value of another attribute. +func (s *CustomizableSchema) SetConditionalSuppressDiff(enable DiffSuppressorFn) *CustomizableSchema { + s.Schema.DiffSuppressFunc = conditionalDiffSuppressor(enable, s.path[len(s.path)-1], s.Schema) s.isSuppressDiff = true if s.Schema.Type == schema.TypeList && s.Schema.MaxItems == 1 { // If it is a list with max items = 1, it means the corresponding sdk schema type is a struct or a ptr. @@ -127,9 +134,8 @@ func (s *CustomizableSchema) SetSuppressDiff() *CustomizableSchema { if !ok { panic("Cannot cast Elem into Resource type.") } - nestedSchema := resource.Schema - for k, v := range nestedSchema { - v.DiffSuppressFunc = diffSuppressor(k, v) + for k, v := range resource.Schema { + v.DiffSuppressFunc = conditionalDiffSuppressor(enable, k, v) } } return s diff --git a/common/reflect_resource.go b/common/reflect_resource.go old mode 100644 new mode 100755 index ac1c5bf777..38735fae5b --- a/common/reflect_resource.go +++ b/common/reflect_resource.go @@ -364,9 +364,28 @@ func chooseFieldName(typeField reflect.StructField) string { return getJsonFieldName(typeField) } -func diffSuppressor(fieldName string, v *schema.Schema) func(k, old, new string, d *schema.ResourceData) bool { +// DiffSuppressorFn is the signature of a schema.Schema DiffSuppressFunc. +type DiffSuppressorFn = func(k, old, new string, d *schema.ResourceData) bool + +// alwaysSuppress is the default enable predicate: suppression is always allowed. +func alwaysSuppress(_, _, _ string, _ *schema.ResourceData) bool { return true } + +// diffSuppressor suppresses the diff for a field that the platform populated +// with a value the configuration left unset (including an empty nested block). +func diffSuppressor(fieldName string, v *schema.Schema) DiffSuppressorFn { + return conditionalDiffSuppressor(alwaysSuppress, fieldName, v) +} + +// conditionalDiffSuppressor is diffSuppressor gated by an enable predicate: when +// enable returns false the diff is never suppressed; otherwise suppression +// follows the same rules as diffSuppressor. +func conditionalDiffSuppressor(enable DiffSuppressorFn, fieldName string, v *schema.Schema) DiffSuppressorFn { zero := fmt.Sprintf("%v", v.Type.Zero()) return func(k, old, new string, d *schema.ResourceData) bool { + if !enable(k, old, new, d) { + return false + } + // HasChange allows to check if the field is explicitly changed in the configuration. // If the field is explicitly set in the configuration, we should not suppress the diff. if new == zero && old != zero && !d.HasChange(k) { diff --git a/docs/data-sources/postgres_data_api.md b/docs/data-sources/postgres_data_api.md new file mode 100755 index 0000000000..4e267f4c0e --- /dev/null +++ b/docs/data-sources/postgres_data_api.md @@ -0,0 +1,77 @@ +--- +subcategory: "Postgres" +--- +# databricks_postgres_data_api Data Source +[![Private Preview](https://img.shields.io/badge/Release_Stage-Private_Preview-blueviolet)](https://docs.databricks.com/aws/en/release-notes/release-types) + +[API Documentation](https://docs.databricks.com/api/workspace/postgres) + +This data source retrieves the Data API configuration for a single Lakebase database, including the public Data API URL. + + +## Example Usage +### Retrieve the Data API for a Database + +```hcl +data "databricks_postgres_data_api" "app" { + name = "projects/my-project/branches/main/databases/app/data-api" +} + +output "data_api_url" { + value = data.databricks_postgres_data_api.app.status.url +} + +output "available_schemas" { + value = data.databricks_postgres_data_api.app.status.available_schemas +} +``` + + +## Arguments +The following arguments are supported: +* `name` (string, required) - Resource name: projects/{project_id}/branches/{branch_id}/databases/{database_id}/data-api +* `provider_config` (ProviderConfig, optional) - Configure the provider for management through account provider. + +### ProviderConfig +* `workspace_id` (string,optional) - Workspace ID which the resource belongs to. This workspace must be part of the account which the provider is configured with. + +## Attributes +The following attributes are exported: +* `create_time` (string) - A timestamp indicating when the Data API was first enabled +* `name` (string) - Resource name: projects/{project_id}/branches/{branch_id}/databases/{database_id}/data-api +* `parent` (string) - The database containing this Data API configuration. + Format: projects/{project_id}/branches/{branch_id}/databases/{database_id} +* `spec` (DataApiDataApiSpec) - The desired Data API configuration +* `status` (DataApiDataApiStatus) - The observed Data API state (read-only) +* `update_time` (string) - A timestamp indicating when the Data API configuration was last updated + +### DataApiDataApiSpec +* `db_aggregates_enabled` (boolean) - Enable aggregate functions (count, sum, avg, etc.) in Data API responses. + Default: true +* `db_extra_search_path` (list of string) - Additional schemas to include in the PostgreSQL search path. + Each entry must be a valid PostgreSQL schema name +* `db_max_rows` (integer) - Maximum number of rows returned in a single Data API response. + Must be a positive integer +* `db_schemas` (list of string) - Database schemas exposed through the Data API. + Each entry must be a valid PostgreSQL schema name (1-63 chars, [a-zA-Z_][a-zA-Z0-9_$]*). + Maximum 100 entries. Default: ["public"] +* `jwt_cache_max_lifetime` (string) - Maximum lifetime for cached JWT tokens. Zero duration disables caching +* `jwt_role_claim_key` (string) - JSON path to the role claim in JWT tokens (e.g., ".sub"). + Default: ".sub" +* `openapi_mode` (string) - OpenAPI documentation mode for the Data API endpoint. Possible values are: `OPEN_API_MODE_DISABLED`, `OPEN_API_MODE_IGNORE_PRIVILEGES` +* `server_cors_allowed_origins` (list of string) - Allowed origins for CORS requests. + Each entry should be a valid origin URL, or use "*" to allow all origins +* `server_timing_enabled` (boolean) - Enable the Server-Timing header in Data API responses + +### DataApiDataApiStatus +* `available_schemas` (list of string) - Schemas available in the database (for reference when configuring db_schemas) +* `db_aggregates_enabled` (boolean) - Actual aggregate function setting read from the database +* `db_extra_search_path` (list of string) - Actual extra search path schemas read from the database +* `db_max_rows` (integer) - Actual max rows setting read from the database +* `db_schemas` (list of string) - Actual exposed schemas read from the database +* `jwt_cache_max_lifetime` (string) - Actual JWT cache max lifetime read from the database +* `jwt_role_claim_key` (string) - Actual JWT role claim key read from the database +* `openapi_mode` (string) - Actual OpenAPI mode read from the database. Possible values are: `OPEN_API_MODE_DISABLED`, `OPEN_API_MODE_IGNORE_PRIVILEGES` +* `server_cors_allowed_origins` (list of string) - Actual CORS allowed origins read from the database +* `server_timing_enabled` (boolean) - Actual Server-Timing header setting read from the database +* `url` (string) - Data API endpoint URL \ No newline at end of file diff --git a/docs/resources/postgres_data_api.md b/docs/resources/postgres_data_api.md new file mode 100755 index 0000000000..d3ae654d2d --- /dev/null +++ b/docs/resources/postgres_data_api.md @@ -0,0 +1,211 @@ +--- +subcategory: "Postgres" +--- +# databricks_postgres_data_api Resource +[![Private Preview](https://img.shields.io/badge/Release_Stage-Private_Preview-blueviolet)](https://docs.databricks.com/aws/en/release-notes/release-types) + +[API Documentation](https://docs.databricks.com/api/workspace/postgres) + +### Lakebase Autoscaling Terraform Behavior + +This resource uses Lakebase Autoscaling Terraform semantics. For complete details on how spec/status fields work, drift detection behavior, and state management requirements, see the `databricks_postgres_project` resource documentation. + +### Overview + +The Data API is a [PostgREST](https://docs.postgrest.org/)-compatible REST interface for a Lakebase Postgres database, served by a Databricks-managed implementation. See the [Lakebase Data API docs](https://docs.databricks.com/aws/en/oltp/projects/data-api) for an overview. Creating this resource enables the Data API on the parent database; deleting it disables it. + +There is at most one Data API per database. The Data API is identified by the parent database — you do not provide a separate ID. + +### Hierarchy Context + +Data APIs exist within the Lakebase Autoscaling resource hierarchy: +- A **Data API** belongs to a **database** within a **branch** within a **project** +- A database may have at most one Data API enabled +- Removing the `databricks_postgres_data_api` resource (e.g. via `terraform destroy`) only disables the Data API; the underlying database is left intact + +### Configuration + +`spec` holds the desired Data API configuration. All fields are optional and have reasonable defaults. + +The Data API is wire-compatible with PostgREST and most spec fields are named after the corresponding PostgREST configuration parameter. Where a setting maps to PostgREST, the upstream documentation link is provided and semantics match it unless explicitly noted otherwise. Settings marked **Currently not honored** are accepted, validated, and round-tripped through the API but are ignored by the runtime — they are reserved so configuration set today does not need to be migrated when the behavior is implemented. + +#### Database settings + +- `db_aggregates_enabled` (`bool`, default `true`) — enables aggregate functions (`count`, `sum`, `avg`, …) in Data API responses. Maps to PostgREST [`db-aggregates-enabled`](https://docs.postgrest.org/en/latest/references/configuration.html#db-aggregates-enabled). +- `db_schemas` (`list`, default `["public"]`) — Postgres schemas exposed through the Data API. Maps to PostgREST [`db-schemas`](https://docs.postgrest.org/en/latest/references/configuration.html#db-schemas). Each schema must already exist in the database (application-managed). +- `db_extra_search_path` (`list`) — additional schemas added to the Postgres `search_path` for resolving unqualified identifiers. Maps to PostgREST [`db-extra-search-path`](https://docs.postgrest.org/en/latest/references/configuration.html#db-extra-search-path). +- `db_max_rows` (`int32`, must be positive) — caps the rows returned by a single query. Maps to PostgREST [`db-max-rows`](https://docs.postgrest.org/en/latest/references/configuration.html#db-max-rows). When unset, no limit is applied (PostgREST default). + +#### JWT / authentication settings + +- `jwt_role_claim_key` (`string`, default `".sub"`) — JSON path to the JWT claim that selects the Postgres role for the request. Maps to PostgREST [`jwt-role-claim-key`](https://docs.postgrest.org/en/latest/references/configuration.html#jwt-role-claim-key). **Currently not honored** — the runtime hardcodes the role-claim path to `.sub` (the Databricks user email). +- `jwt_cache_max_lifetime` (`Duration`) — maximum lifetime for cached validated JWTs; `0s` disables caching, larger values amortize signature verification across requests. Maps to PostgREST [`jwt-cache-max-lifetime`](https://docs.postgrest.org/en/latest/references/configuration.html#jwt-cache-max-lifetime). **Currently not honored** — the runtime uses fixed caching behavior. + +#### Server settings + +- `server_cors_allowed_origins` (`list`) — allowed CORS origins, or `["*"]` to allow any origin. Maps to PostgREST [`server-cors-allowed-origins`](https://docs.postgrest.org/en/latest/references/configuration.html#server-cors-allowed-origins). +- `server_timing_enabled` (`bool`) — emits the `Server-Timing` HTTP header on responses. Maps to PostgREST [`server-timing-enabled`](https://docs.postgrest.org/en/latest/references/configuration.html#server-timing-enabled). + +#### OpenAPI settings + +- `openapi_mode` (enum) — controls how the Data API exposes the auto-generated OpenAPI document. Maps to PostgREST [`openapi-mode`](https://docs.postgrest.org/en/latest/references/configuration.html#openapi-mode). **Only `OPEN_API_MODE_IGNORE_PRIVILEGES` and `OPEN_API_MODE_DISABLED` are supported** today; PostgREST's `follow-privileges` mode is not implemented yet. + +`status` is read-only and reflects the actual Data API configuration applied to the database, plus: +- `url` — the HTTPS endpoint at which the Data API is served. +- `available_schemas` — schemas in the database, useful when configuring `db_schemas`. + +### Use Cases + +- **Public read API**: expose a `public` schema to anonymous clients with `db_max_rows` capped to a safe value. +- **OpenAPI catalog**: set `openapi_mode` so consumers can discover endpoints automatically. + + +## Example Usage +### Enable the Data API on a Database + +Enable the Data API on a Lakebase database with default settings. The `parent` is the database resource name; the resulting Data API URL is exposed via `status.url`. + +```hcl +resource "databricks_postgres_project" "this" { + project_id = "my-project" + spec = { + pg_version = 17 + display_name = "My Project" + } +} + +resource "databricks_postgres_branch" "main" { + branch_id = "main" + parent = databricks_postgres_project.this.name + spec = { + no_expiry = true + } +} + +resource "databricks_postgres_role" "app_owner" { + role_id = "app-owner" + parent = databricks_postgres_branch.main.name + spec = { + postgres_role = "app_owner" + } +} + +resource "databricks_postgres_database" "app" { + database_id = "app" + parent = databricks_postgres_branch.main.name + spec = { + postgres_database = "app" + role = databricks_postgres_role.app_owner.name + } +} + +resource "databricks_postgres_data_api" "app" { + parent = databricks_postgres_database.app.name +} + +output "data_api_url" { + value = databricks_postgres_data_api.app.status.url +} +``` + +> [!NOTE] +> **`db_schemas` is application-managed, not infrastructure.** +> +> Enabling the Data API only stands up the PostgREST machinery (`pgrst` schema, `authenticator` role, `pre_config` function); the schemas exposed via `db_schemas` must already exist in the database. They are application data, expected to be created by the application managing the database (SQL, sqitch, Flyway, etc.). Terraform should not own them. + +### Custom PostgREST Settings + +Tighten response size, restrict CORS, and configure the OpenAPI mode. + +```hcl +resource "databricks_postgres_data_api" "app" { + parent = databricks_postgres_database.app.name + spec = { + db_schemas = ["public"] + db_max_rows = 1000 + + server_cors_allowed_origins = ["https://app.example.com"] + server_timing_enabled = true + openapi_mode = "OPEN_API_MODE_IGNORE_PRIVILEGES" + } +} +``` + +### Caveat: Clearing a Previously-Set Field + +Removing a field from `spec` (or setting it to `null`) does **not** clear the value on the server with the typed schema today; the previous value remains in effect. To clear a field, taint the resource and re-apply, or use the API directly. + +### Refreshing the PostgREST schema cache + +PostgREST caches the database's schemas, roles, and functions in memory and only re-reads them on a refresh. Create/Update normally trigger this refresh automatically, but if it fails (for example a transient network blip), the database is configured but PostgREST can't see the new schemas. + +To re-trigger the refresh without changing any settings, call Update with no fields set in `spec` — the server treats this as a refresh-only request, re-reads the cache, and returns the unchanged state. Via the API directly: + +```sh +curl -X PATCH "$WORKSPACE/api/2.0/postgres/projects/{p}/branches/{b}/databases/{d}/data-api?update_mask=spec" \ + -H "Authorization: Bearer $TOKEN" \ + -d '{"spec": {}}' +``` + + +## Arguments +The following arguments are supported: +* `parent` (string, required) - The database containing this Data API configuration. + Format: projects/{project_id}/branches/{branch_id}/databases/{database_id} +* `spec` (DataApiDataApiSpec, optional) - The desired Data API configuration +* `provider_config` (ProviderConfig, optional) - Configure the provider for management through account provider. + +### ProviderConfig +* `workspace_id` (string,optional) - Workspace ID which the resource belongs to. This workspace must be part of the account which the provider is configured with. + +### DataApiDataApiSpec +* `db_aggregates_enabled` (boolean, optional) - Enable aggregate functions (count, sum, avg, etc.) in Data API responses. + Default: true +* `db_extra_search_path` (list of string, optional) - Additional schemas to include in the PostgreSQL search path. + Each entry must be a valid PostgreSQL schema name +* `db_max_rows` (integer, optional) - Maximum number of rows returned in a single Data API response. + Must be a positive integer +* `db_schemas` (list of string, optional) - Database schemas exposed through the Data API. + Each entry must be a valid PostgreSQL schema name (1-63 chars, [a-zA-Z_][a-zA-Z0-9_$]*). + Maximum 100 entries. Default: ["public"] +* `jwt_cache_max_lifetime` (string, optional) - Maximum lifetime for cached JWT tokens. Zero duration disables caching +* `jwt_role_claim_key` (string, optional) - JSON path to the role claim in JWT tokens (e.g., ".sub"). + Default: ".sub" +* `openapi_mode` (string, optional) - OpenAPI documentation mode for the Data API endpoint. Possible values are: `OPEN_API_MODE_DISABLED`, `OPEN_API_MODE_IGNORE_PRIVILEGES` +* `server_cors_allowed_origins` (list of string, optional) - Allowed origins for CORS requests. + Each entry should be a valid origin URL, or use "*" to allow all origins +* `server_timing_enabled` (boolean, optional) - Enable the Server-Timing header in Data API responses + +## Attributes +In addition to the above arguments, the following attributes are exported: +* `create_time` (string) - A timestamp indicating when the Data API was first enabled +* `name` (string) - Resource name: projects/{project_id}/branches/{branch_id}/databases/{database_id}/data-api +* `status` (DataApiDataApiStatus) - The observed Data API state (read-only) +* `update_time` (string) - A timestamp indicating when the Data API configuration was last updated + +### DataApiDataApiStatus +* `available_schemas` (list of string) - Schemas available in the database (for reference when configuring db_schemas) +* `db_aggregates_enabled` (boolean) - Actual aggregate function setting read from the database +* `db_extra_search_path` (list of string) - Actual extra search path schemas read from the database +* `db_max_rows` (integer) - Actual max rows setting read from the database +* `db_schemas` (list of string) - Actual exposed schemas read from the database +* `jwt_cache_max_lifetime` (string) - Actual JWT cache max lifetime read from the database +* `jwt_role_claim_key` (string) - Actual JWT role claim key read from the database +* `openapi_mode` (string) - Actual OpenAPI mode read from the database. Possible values are: `OPEN_API_MODE_DISABLED`, `OPEN_API_MODE_IGNORE_PRIVILEGES` +* `server_cors_allowed_origins` (list of string) - Actual CORS allowed origins read from the database +* `server_timing_enabled` (boolean) - Actual Server-Timing header setting read from the database +* `url` (string) - Data API endpoint URL + +## Import +As of Terraform v1.5, resources can be imported through configuration. +```hcl +import { + id = "name" + to = databricks_postgres_data_api.this +} +``` + +If you are using an older version of Terraform, import the resource using the `terraform import` command as follows: +```sh +terraform import databricks_postgres_data_api.this "name" +``` \ No newline at end of file diff --git a/go.mod b/go.mod index 9ad0656928..f4d2e01651 100755 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/databricks/terraform-provider-databricks go 1.25.8 require ( - github.com/databricks/databricks-sdk-go v0.145.0 + github.com/databricks/databricks-sdk-go v0.146.0 github.com/golang-jwt/jwt/v4 v4.5.2 github.com/google/go-cmp v0.7.0 github.com/hashicorp/go-cty v1.5.0 diff --git a/go.sum b/go.sum index a7699566b8..046c1a8f5e 100755 --- a/go.sum +++ b/go.sum @@ -27,8 +27,8 @@ github.com/cloudflare/circl v1.6.3 h1:9GPOhQGF9MCYUeXyMYlqTR6a5gTrgR/fBLXvUgtVcg github.com/cloudflare/circl v1.6.3/go.mod h1:2eXP6Qfat4O/Yhh8BznvKnJ+uzEoTQ6jVKJRn81BiS4= github.com/cyphar/filepath-securejoin v0.4.1 h1:JyxxyPEaktOD+GAnqIqTf9A8tHyAG22rowi7HkoSU1s= github.com/cyphar/filepath-securejoin v0.4.1/go.mod h1:Sdj7gXlvMcPZsbhwhQ33GguGLDGQL7h7bg04C/+u9jI= -github.com/databricks/databricks-sdk-go v0.145.0 h1:3tTu19kEqf7rnMrNzo90q8XSp5XRjdPtTLOAKo2avK8= -github.com/databricks/databricks-sdk-go v0.145.0/go.mod h1:C5LNgGe6hGuRrTwoxFmuup3XtQQEaqtq0e+K8IFDIS4= +github.com/databricks/databricks-sdk-go v0.146.0 h1:rOs8PSkMUBIbvq2jBljjWPJyvzLZxnv/QT2vZvCBQcY= +github.com/databricks/databricks-sdk-go v0.146.0/go.mod h1:C5LNgGe6hGuRrTwoxFmuup3XtQQEaqtq0e+K8IFDIS4= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= diff --git a/internal/providers/pluginfw/auto_generation.go b/internal/providers/pluginfw/auto_generation.go index 15d25c026e..0304ce190d 100755 --- a/internal/providers/pluginfw/auto_generation.go +++ b/internal/providers/pluginfw/auto_generation.go @@ -69,6 +69,8 @@ import ( "github.com/databricks/terraform-provider-databricks/internal/providers/pluginfw/products/postgres_catalog" + "github.com/databricks/terraform-provider-databricks/internal/providers/pluginfw/products/postgres_data_api" + "github.com/databricks/terraform-provider-databricks/internal/providers/pluginfw/products/postgres_database" "github.com/databricks/terraform-provider-databricks/internal/providers/pluginfw/products/postgres_endpoint" @@ -140,6 +142,7 @@ var autoGeneratedResources = []func() resource.Resource{ policy_info.ResourcePolicyInfo, postgres_branch.ResourceBranch, postgres_catalog.ResourceCatalog, + postgres_data_api.ResourceDataApi, postgres_database.ResourceDatabase, postgres_endpoint.ResourceEndpoint, postgres_project.ResourceProject, @@ -193,6 +196,7 @@ var autoGeneratedDataSources = []func() datasource.DataSource{ policy_info.DataSourcePolicyInfo, postgres_branch.DataSourceBranch, postgres_catalog.DataSourceCatalog, + postgres_data_api.DataSourceDataApi, postgres_database.DataSourceDatabase, postgres_endpoint.DataSourceEndpoint, postgres_project.DataSourceProject, diff --git a/internal/providers/pluginfw/products/postgres_data_api/data_postgres_data_api.go b/internal/providers/pluginfw/products/postgres_data_api/data_postgres_data_api.go new file mode 100755 index 0000000000..dd5a2fae88 --- /dev/null +++ b/internal/providers/pluginfw/products/postgres_data_api/data_postgres_data_api.go @@ -0,0 +1,252 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package postgres_data_api + +import ( + "context" + "reflect" + + "github.com/databricks/databricks-sdk-go/service/postgres" + "github.com/databricks/terraform-provider-databricks/internal/providers/pluginfw/autogen" + pluginfwcontext "github.com/databricks/terraform-provider-databricks/internal/providers/pluginfw/context" + "github.com/databricks/terraform-provider-databricks/internal/providers/pluginfw/converters" + "github.com/databricks/terraform-provider-databricks/internal/providers/pluginfw/tfschema" + "github.com/databricks/terraform-provider-databricks/internal/service/postgres_tf" + "github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" + "github.com/hashicorp/terraform-plugin-framework/attr" + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/datasource/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/types" + "github.com/hashicorp/terraform-plugin-framework/types/basetypes" +) + +const dataSourceName = "postgres_data_api" + +var _ datasource.DataSourceWithConfigure = &DataApiDataSource{} + +func DataSourceDataApi() datasource.DataSource { + return &DataApiDataSource{} +} + +type DataApiDataSource struct { + Client *autogen.DatabricksClient +} + +// ProviderConfigData contains the fields to configure the provider. +type ProviderConfigData struct { + WorkspaceID types.String `tfsdk:"workspace_id"` +} + +// ApplySchemaCustomizations applies the schema customizations to the ProviderConfig type. +func (r ProviderConfigData) ApplySchemaCustomizations(attrs map[string]tfschema.AttributeBuilder) map[string]tfschema.AttributeBuilder { + attrs["workspace_id"] = attrs["workspace_id"].SetOptional() + attrs["workspace_id"] = attrs["workspace_id"].SetComputed() + + attrs["workspace_id"] = attrs["workspace_id"].(tfschema.StringAttributeBuilder).AddValidator(stringvalidator.LengthAtLeast(1)) + return attrs +} + +// ProviderConfigDataWorkspaceIDPlanModifier is plan modifier for the workspace_id field. +// Resource requires replacement if the workspace_id changes from one non-empty value to another. +func ProviderConfigDataWorkspaceIDPlanModifier(ctx context.Context, req planmodifier.StringRequest, resp *stringplanmodifier.RequiresReplaceIfFuncResponse) { + // Require replacement if workspace_id changes from one non-empty value to another + oldValue := req.StateValue.ValueString() + newValue := req.PlanValue.ValueString() + + if oldValue != "" && newValue != "" && oldValue != newValue { + resp.RequiresReplace = true + } +} + +// GetComplexFieldTypes returns a map of the types of elements in complex fields in the extended +// ProviderConfigData struct. Container types (types.Map, types.List, types.Set) and +// object types (types.Object) do not carry the type information of their elements in the Go +// type system. This function provides a way to retrieve the type information of the elements in +// complex fields at runtime. The values of the map are the reflected types of the contained elements. +// They must be either primitive values from the plugin framework type system +// (types.String{}, types.Bool{}, types.Int64{}, types.Float64{}) or TF SDK values. +func (r ProviderConfigData) GetComplexFieldTypes(ctx context.Context) map[string]reflect.Type { + return map[string]reflect.Type{} +} + +// ToObjectValue returns the object value for the resource, combining attributes from the +// embedded TFSDK model and contains additional fields. +// +// TFSDK types cannot implement the ObjectValuable interface directly, as it would otherwise +// interfere with how the plugin framework retrieves and sets values in state. Thus, ProviderConfigData +// only implements ToObjectValue() and Type(). +func (r ProviderConfigData) ToObjectValue(ctx context.Context) basetypes.ObjectValue { + return types.ObjectValueMust( + r.Type(ctx).(basetypes.ObjectType).AttrTypes, + map[string]attr.Value{ + "workspace_id": r.WorkspaceID, + }, + ) +} + +// Type returns the object type with attributes from both the embedded TFSDK model +// and contains additional fields. +func (r ProviderConfigData) Type(ctx context.Context) attr.Type { + return types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "workspace_id": types.StringType, + }, + } +} + +// DataApiData extends the main model with additional fields. +type DataApiData struct { + // A timestamp indicating when the Data API was first enabled. + CreateTime timetypes.RFC3339 `tfsdk:"create_time"` + // Resource name: + // projects/{project_id}/branches/{branch_id}/databases/{database_id}/data-api + Name types.String `tfsdk:"name"` + // The database containing this Data API configuration. Format: + // projects/{project_id}/branches/{branch_id}/databases/{database_id} + Parent types.String `tfsdk:"parent"` + // The desired Data API configuration. + Spec types.Object `tfsdk:"spec"` + // The observed Data API state (read-only). + Status types.Object `tfsdk:"status"` + // A timestamp indicating when the Data API configuration was last updated. + UpdateTime timetypes.RFC3339 `tfsdk:"update_time"` + ProviderConfigData types.Object `tfsdk:"provider_config"` +} + +// GetComplexFieldTypes returns a map of the types of elements in complex fields in the extended +// DataApiData struct. Container types (types.Map, types.List, types.Set) and +// object types (types.Object) do not carry the type information of their elements in the Go +// type system. This function provides a way to retrieve the type information of the elements in +// complex fields at runtime. The values of the map are the reflected types of the contained elements. +// They must be either primitive values from the plugin framework type system +// (types.String{}, types.Bool{}, types.Int64{}, types.Float64{}) or TF SDK values. +func (m DataApiData) GetComplexFieldTypes(ctx context.Context) map[string]reflect.Type { + return map[string]reflect.Type{ + "spec": reflect.TypeOf(postgres_tf.DataApiDataApiSpec{}), + "status": reflect.TypeOf(postgres_tf.DataApiDataApiStatus{}), + "provider_config": reflect.TypeOf(ProviderConfigData{}), + } +} + +// ToObjectValue returns the object value for the resource, combining attributes from the +// embedded TFSDK model and contains additional fields. +// +// TFSDK types cannot implement the ObjectValuable interface directly, as it would otherwise +// interfere with how the plugin framework retrieves and sets values in state. Thus, DataApiData +// only implements ToObjectValue() and Type(). +func (m DataApiData) ToObjectValue(ctx context.Context) basetypes.ObjectValue { + return types.ObjectValueMust( + m.Type(ctx).(basetypes.ObjectType).AttrTypes, + map[string]attr.Value{ + "create_time": m.CreateTime, + "name": m.Name, + "parent": m.Parent, + "spec": m.Spec, + "status": m.Status, + "update_time": m.UpdateTime, + + "provider_config": m.ProviderConfigData, + }, + ) +} + +// Type returns the object type with attributes from both the embedded TFSDK model +// and contains additional fields. +func (m DataApiData) Type(ctx context.Context) attr.Type { + return types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "create_time": timetypes.RFC3339{}.Type(ctx), + "name": types.StringType, + "parent": types.StringType, + "spec": postgres_tf.DataApiDataApiSpec{}.Type(ctx), + "status": postgres_tf.DataApiDataApiStatus{}.Type(ctx), + "update_time": timetypes.RFC3339{}.Type(ctx), + + "provider_config": ProviderConfigData{}.Type(ctx), + }, + } +} + +func (m DataApiData) ApplySchemaCustomizations(attrs map[string]tfschema.AttributeBuilder) map[string]tfschema.AttributeBuilder { + attrs["create_time"] = attrs["create_time"].SetComputed() + attrs["name"] = attrs["name"].SetRequired() + attrs["parent"] = attrs["parent"].SetComputed() + attrs["spec"] = attrs["spec"].SetComputed() + attrs["status"] = attrs["status"].SetComputed() + attrs["update_time"] = attrs["update_time"].SetComputed() + + attrs["provider_config"] = attrs["provider_config"].SetOptional() + + return attrs +} + +func (r *DataApiDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = autogen.GetDatabricksProductionName(dataSourceName) +} + +func (r *DataApiDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + attrs, blocks := tfschema.DataSourceStructToSchemaMap(ctx, DataApiData{}, nil) + resp.Schema = schema.Schema{ + Description: "Terraform schema for Databricks DataApi", + Attributes: attrs, + Blocks: blocks, + } +} + +func (r *DataApiDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { + r.Client = autogen.ConfigureDataSource(req, resp) +} + +func (r *DataApiDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + ctx = pluginfwcontext.SetUserAgentInDataSourceContext(ctx, dataSourceName) + + var config DataApiData + resp.Diagnostics.Append(req.Config.Get(ctx, &config)...) + if resp.Diagnostics.HasError() { + return + } + + var readRequest postgres.GetDataApiRequest + resp.Diagnostics.Append(converters.TfSdkToGoSdkStruct(ctx, config, &readRequest)...) + if resp.Diagnostics.HasError() { + return + } + + var namespace ProviderConfigData + resp.Diagnostics.Append(config.ProviderConfigData.As(ctx, &namespace, basetypes.ObjectAsOptions{ + UnhandledNullAsEmpty: true, + UnhandledUnknownAsEmpty: true, + })...) + if resp.Diagnostics.HasError() { + return + } + client, clientDiags := r.Client.GetWorkspaceClientForUnifiedProviderWithDiagnostics(ctx, namespace.WorkspaceID.ValueString()) + + resp.Diagnostics.Append(clientDiags...) + if resp.Diagnostics.HasError() { + return + } + + response, err := client.Postgres.GetDataApi(ctx, readRequest) + if err != nil { + resp.Diagnostics.AddError("failed to get postgres_data_api", err.Error()) + return + } + + var newState DataApiData + resp.Diagnostics.Append(converters.GoSdkToTfSdkStruct(ctx, response, &newState)...) + if resp.Diagnostics.HasError() { + return + } + // Preserve provider_config from config so state.Set has the correct type info + newState.ProviderConfigData = config.ProviderConfigData + + resp.Diagnostics.Append(resp.State.Set(ctx, newState)...) + if resp.Diagnostics.HasError() { + return + } + resp.Diagnostics.Append(tfschema.PopulateProviderConfigInStateForDataSource(ctx, r.Client, config.ProviderConfigData, &resp.State)...) +} diff --git a/internal/providers/pluginfw/products/postgres_data_api/resource_postgres_data_api.go b/internal/providers/pluginfw/products/postgres_data_api/resource_postgres_data_api.go new file mode 100755 index 0000000000..ed05e11547 --- /dev/null +++ b/internal/providers/pluginfw/products/postgres_data_api/resource_postgres_data_api.go @@ -0,0 +1,597 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package postgres_data_api + +import ( + "context" + "fmt" + "reflect" + "strings" + + "github.com/databricks/databricks-sdk-go/apierr" + "github.com/databricks/databricks-sdk-go/common/types/fieldmask" + "github.com/databricks/databricks-sdk-go/service/postgres" + "github.com/databricks/terraform-provider-databricks/internal/providers/pluginfw/autogen" + pluginfwcommon "github.com/databricks/terraform-provider-databricks/internal/providers/pluginfw/common" + pluginfwcontext "github.com/databricks/terraform-provider-databricks/internal/providers/pluginfw/context" + "github.com/databricks/terraform-provider-databricks/internal/providers/pluginfw/converters" + "github.com/databricks/terraform-provider-databricks/internal/providers/pluginfw/declarative" + "github.com/databricks/terraform-provider-databricks/internal/providers/pluginfw/tfschema" + "github.com/databricks/terraform-provider-databricks/internal/service/postgres_tf" + "github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" + "github.com/hashicorp/terraform-plugin-framework/attr" + "github.com/hashicorp/terraform-plugin-framework/diag" + "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/objectplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-framework/types/basetypes" +) + +const resourceName = "postgres_data_api" + +var _ resource.ResourceWithConfigure = &DataApiResource{} +var _ resource.ResourceWithModifyPlan = &DataApiResource{} + +func ResourceDataApi() resource.Resource { + return &DataApiResource{} +} + +type DataApiResource struct { + Client *autogen.DatabricksClient +} + +// ProviderConfig contains the fields to configure the provider. +type ProviderConfig struct { + WorkspaceID types.String `tfsdk:"workspace_id"` +} + +// ApplySchemaCustomizations applies the schema customizations to the ProviderConfig type. +func (r ProviderConfig) ApplySchemaCustomizations(attrs map[string]tfschema.AttributeBuilder) map[string]tfschema.AttributeBuilder { + attrs["workspace_id"] = attrs["workspace_id"].SetOptional() + attrs["workspace_id"] = attrs["workspace_id"].SetComputed() + attrs["workspace_id"] = attrs["workspace_id"].(tfschema.StringAttributeBuilder).AddPlanModifier( + stringplanmodifier.RequiresReplaceIf(ProviderConfigWorkspaceIDPlanModifier, "", "")) + attrs["workspace_id"] = attrs["workspace_id"].(tfschema.StringAttributeBuilder).AddValidator(stringvalidator.LengthAtLeast(1)) + return attrs +} + +// ProviderConfigWorkspaceIDPlanModifier is plan modifier for the workspace_id field. +// Resource requires replacement if the workspace_id changes from one non-empty value to another. +func ProviderConfigWorkspaceIDPlanModifier(ctx context.Context, req planmodifier.StringRequest, resp *stringplanmodifier.RequiresReplaceIfFuncResponse) { + // Require replacement if workspace_id changes from one non-empty value to another + oldValue := req.StateValue.ValueString() + newValue := req.PlanValue.ValueString() + + if oldValue != "" && newValue != "" && oldValue != newValue { + resp.RequiresReplace = true + } +} + +// GetComplexFieldTypes returns a map of the types of elements in complex fields in the extended +// ProviderConfig struct. Container types (types.Map, types.List, types.Set) and +// object types (types.Object) do not carry the type information of their elements in the Go +// type system. This function provides a way to retrieve the type information of the elements in +// complex fields at runtime. The values of the map are the reflected types of the contained elements. +// They must be either primitive values from the plugin framework type system +// (types.String{}, types.Bool{}, types.Int64{}, types.Float64{}) or TF SDK values. +func (r ProviderConfig) GetComplexFieldTypes(ctx context.Context) map[string]reflect.Type { + return map[string]reflect.Type{} +} + +// ToObjectValue returns the object value for the resource, combining attributes from the +// embedded TFSDK model and contains additional fields. +// +// TFSDK types cannot implement the ObjectValuable interface directly, as it would otherwise +// interfere with how the plugin framework retrieves and sets values in state. Thus, ProviderConfig +// only implements ToObjectValue() and Type(). +func (r ProviderConfig) ToObjectValue(ctx context.Context) basetypes.ObjectValue { + return types.ObjectValueMust( + r.Type(ctx).(basetypes.ObjectType).AttrTypes, + map[string]attr.Value{ + "workspace_id": r.WorkspaceID, + }, + ) +} + +// Type returns the object type with attributes from both the embedded TFSDK model +// and contains additional fields. +func (r ProviderConfig) Type(ctx context.Context) attr.Type { + return types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "workspace_id": types.StringType, + }, + } +} + +// DataApi extends the main model with additional fields. +type DataApi struct { + // A timestamp indicating when the Data API was first enabled. + CreateTime timetypes.RFC3339 `tfsdk:"create_time"` + // Resource name: + // projects/{project_id}/branches/{branch_id}/databases/{database_id}/data-api + Name types.String `tfsdk:"name"` + // The database containing this Data API configuration. Format: + // projects/{project_id}/branches/{branch_id}/databases/{database_id} + Parent types.String `tfsdk:"parent"` + // The desired Data API configuration. + Spec types.Object `tfsdk:"spec"` + // The observed Data API state (read-only). + Status types.Object `tfsdk:"status"` + // A timestamp indicating when the Data API configuration was last updated. + UpdateTime timetypes.RFC3339 `tfsdk:"update_time"` + ProviderConfig types.Object `tfsdk:"provider_config"` +} + +// GetComplexFieldTypes returns a map of the types of elements in complex fields in the extended +// DataApi struct. Container types (types.Map, types.List, types.Set) and +// object types (types.Object) do not carry the type information of their elements in the Go +// type system. This function provides a way to retrieve the type information of the elements in +// complex fields at runtime. The values of the map are the reflected types of the contained elements. +// They must be either primitive values from the plugin framework type system +// (types.String{}, types.Bool{}, types.Int64{}, types.Float64{}) or TF SDK values. +func (m DataApi) GetComplexFieldTypes(ctx context.Context) map[string]reflect.Type { + return map[string]reflect.Type{ + "spec": reflect.TypeOf(postgres_tf.DataApiDataApiSpec{}), + "status": reflect.TypeOf(postgres_tf.DataApiDataApiStatus{}), + "provider_config": reflect.TypeOf(ProviderConfig{}), + } +} + +// ToObjectValue returns the object value for the resource, combining attributes from the +// embedded TFSDK model and contains additional fields. +// +// TFSDK types cannot implement the ObjectValuable interface directly, as it would otherwise +// interfere with how the plugin framework retrieves and sets values in state. Thus, DataApi +// only implements ToObjectValue() and Type(). +func (m DataApi) ToObjectValue(ctx context.Context) basetypes.ObjectValue { + return types.ObjectValueMust( + m.Type(ctx).(basetypes.ObjectType).AttrTypes, + map[string]attr.Value{"create_time": m.CreateTime, + "name": m.Name, + "parent": m.Parent, + "spec": m.Spec, + "status": m.Status, + "update_time": m.UpdateTime, + + "provider_config": m.ProviderConfig, + }, + ) +} + +// Type returns the object type with attributes from both the embedded TFSDK model +// and contains additional fields. +func (m DataApi) Type(ctx context.Context) attr.Type { + return types.ObjectType{ + AttrTypes: map[string]attr.Type{"create_time": timetypes.RFC3339{}.Type(ctx), + "name": types.StringType, + "parent": types.StringType, + "spec": postgres_tf.DataApiDataApiSpec{}.Type(ctx), + "status": postgres_tf.DataApiDataApiStatus{}.Type(ctx), + "update_time": timetypes.RFC3339{}.Type(ctx), + + "provider_config": ProviderConfig{}.Type(ctx), + }, + } +} + +// SyncFieldsDuringCreateOrUpdate copies values from the plan into the receiver, +// including both embedded model fields and additional fields. This method is called +// during create and update. +func (to *DataApi) SyncFieldsDuringCreateOrUpdate(ctx context.Context, from DataApi) { + if !from.Spec.IsUnknown() && !from.Spec.IsNull() { + // Spec is an input only field and not returned by the service, so we keep the value from the prior state. + to.Spec = from.Spec + } + if !from.Spec.IsNull() && !from.Spec.IsUnknown() { + if toSpec, ok := to.GetSpec(ctx); ok { + if fromSpec, ok := from.GetSpec(ctx); ok { + // Recursively sync the fields of Spec + toSpec.SyncFieldsDuringCreateOrUpdate(ctx, fromSpec) + to.SetSpec(ctx, toSpec) + } + } + } + if !from.Status.IsNull() && !from.Status.IsUnknown() { + if toStatus, ok := to.GetStatus(ctx); ok { + if fromStatus, ok := from.GetStatus(ctx); ok { + // Recursively sync the fields of Status + toStatus.SyncFieldsDuringCreateOrUpdate(ctx, fromStatus) + to.SetStatus(ctx, toStatus) + } + } + } + to.ProviderConfig = from.ProviderConfig + +} + +// SyncFieldsDuringRead copies values from the existing state into the receiver, +// including both embedded model fields and additional fields. This method is called +// during read. +func (to *DataApi) SyncFieldsDuringRead(ctx context.Context, from DataApi) { + if !from.Spec.IsUnknown() && !from.Spec.IsNull() { + // Spec is an input only field and not returned by the service, so we keep the value from the prior state. + to.Spec = from.Spec + } + if !from.Spec.IsNull() && !from.Spec.IsUnknown() { + if toSpec, ok := to.GetSpec(ctx); ok { + if fromSpec, ok := from.GetSpec(ctx); ok { + toSpec.SyncFieldsDuringRead(ctx, fromSpec) + to.SetSpec(ctx, toSpec) + } + } + } + if !from.Status.IsNull() && !from.Status.IsUnknown() { + if toStatus, ok := to.GetStatus(ctx); ok { + if fromStatus, ok := from.GetStatus(ctx); ok { + toStatus.SyncFieldsDuringRead(ctx, fromStatus) + to.SetStatus(ctx, toStatus) + } + } + } + to.ProviderConfig = from.ProviderConfig + +} + +func (m DataApi) ApplySchemaCustomizations(attrs map[string]tfschema.AttributeBuilder) map[string]tfschema.AttributeBuilder { + attrs["create_time"] = attrs["create_time"].SetComputed() + attrs["name"] = attrs["name"].SetComputed() + attrs["parent"] = attrs["parent"].SetRequired() + attrs["parent"] = attrs["parent"].(tfschema.StringAttributeBuilder).AddPlanModifier(stringplanmodifier.RequiresReplace()).(tfschema.AttributeBuilder) + attrs["spec"] = attrs["spec"].SetOptional() + attrs["spec"] = attrs["spec"].SetComputed() + attrs["spec"] = attrs["spec"].(tfschema.SingleNestedAttributeBuilder).AddPlanModifier(objectplanmodifier.UseStateForUnknown()).(tfschema.AttributeBuilder) + attrs["status"] = attrs["status"].SetComputed() + attrs["update_time"] = attrs["update_time"].SetComputed() + + attrs["name"] = attrs["name"].(tfschema.StringAttributeBuilder).AddPlanModifier(stringplanmodifier.UseStateForUnknown()).(tfschema.AttributeBuilder) + attrs["provider_config"] = attrs["provider_config"].SetOptional() + attrs["provider_config"] = attrs["provider_config"].SetComputed() + attrs["provider_config"] = attrs["provider_config"].(tfschema.SingleNestedAttributeBuilder).AddPlanModifier(tfschema.ProviderConfigPlanModifier{}) + + return attrs +} + +// GetSpec returns the value of the Spec field in DataApi as +// a postgres_tf.DataApiDataApiSpec value. +// If the field is unknown or null, the boolean return value is false. +func (m *DataApi) GetSpec(ctx context.Context) (postgres_tf.DataApiDataApiSpec, bool) { + var e postgres_tf.DataApiDataApiSpec + if m.Spec.IsNull() || m.Spec.IsUnknown() { + return e, false + } + var v postgres_tf.DataApiDataApiSpec + d := m.Spec.As(ctx, &v, basetypes.ObjectAsOptions{ + UnhandledNullAsEmpty: true, + UnhandledUnknownAsEmpty: true, + }) + if d.HasError() { + panic(pluginfwcommon.DiagToString(d)) + } + return v, true +} + +// SetSpec sets the value of the Spec field in DataApi. +func (m *DataApi) SetSpec(ctx context.Context, v postgres_tf.DataApiDataApiSpec) { + vs := v.ToObjectValue(ctx) + m.Spec = vs +} + +// GetStatus returns the value of the Status field in DataApi as +// a postgres_tf.DataApiDataApiStatus value. +// If the field is unknown or null, the boolean return value is false. +func (m *DataApi) GetStatus(ctx context.Context) (postgres_tf.DataApiDataApiStatus, bool) { + var e postgres_tf.DataApiDataApiStatus + if m.Status.IsNull() || m.Status.IsUnknown() { + return e, false + } + var v postgres_tf.DataApiDataApiStatus + d := m.Status.As(ctx, &v, basetypes.ObjectAsOptions{ + UnhandledNullAsEmpty: true, + UnhandledUnknownAsEmpty: true, + }) + if d.HasError() { + panic(pluginfwcommon.DiagToString(d)) + } + return v, true +} + +// SetStatus sets the value of the Status field in DataApi. +func (m *DataApi) SetStatus(ctx context.Context, v postgres_tf.DataApiDataApiStatus) { + vs := v.ToObjectValue(ctx) + m.Status = vs +} + +func (r *DataApiResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = autogen.GetDatabricksProductionName(resourceName) +} + +func (r *DataApiResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + attrs, blocks := tfschema.ResourceStructToSchemaMap(ctx, DataApi{}, nil) + resp.Schema = schema.Schema{ + Description: "Terraform schema for Databricks postgres_data_api", + Attributes: attrs, + Blocks: blocks, + } +} + +func (r *DataApiResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { + r.Client = autogen.ConfigureResource(req, resp) +} + +func (r *DataApiResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { + // Skip entirely on destroy (no plan state). + if req.Plan.Raw.IsNull() { + return + } + if r.Client == nil { + return + } + tfschema.WorkspaceDriftDetection(ctx, r.Client, req, resp) + if resp.Diagnostics.HasError() { + return + } + tfschema.ValidateWorkspaceID(ctx, r.Client, req, resp) +} + +func (r *DataApiResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + ctx = pluginfwcontext.SetUserAgentInResourceContext(ctx, resourceName) + + var plan DataApi + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + if resp.Diagnostics.HasError() { + return + } + var data_api postgres.DataApi + + resp.Diagnostics.Append(converters.TfSdkToGoSdkStruct(ctx, plan, &data_api)...) + if resp.Diagnostics.HasError() { + return + } + + createRequest := postgres.CreateDataApiRequest{ + DataApi: data_api, + Parent: plan.Parent.ValueString(), + } + + var namespace ProviderConfig + resp.Diagnostics.Append(plan.ProviderConfig.As(ctx, &namespace, basetypes.ObjectAsOptions{ + UnhandledNullAsEmpty: true, + UnhandledUnknownAsEmpty: true, + })...) + if resp.Diagnostics.HasError() { + return + } + client, clientDiags := r.Client.GetWorkspaceClientForUnifiedProviderWithDiagnostics(ctx, namespace.WorkspaceID.ValueString()) + + resp.Diagnostics.Append(clientDiags...) + if resp.Diagnostics.HasError() { + return + } + + response, err := client.Postgres.CreateDataApi(ctx, createRequest) + if err != nil { + resp.Diagnostics.AddError("failed to create postgres_data_api", err.Error()) + return + } + + var newState DataApi + + waitResponse, err := response.Wait(ctx) + if err != nil { + resp.Diagnostics.AddError("error waiting for postgres_data_api to be ready", err.Error()) + return + } + + resp.Diagnostics.Append(converters.GoSdkToTfSdkStruct(ctx, waitResponse, &newState)...) + + if resp.Diagnostics.HasError() { + return + } + + newState.SyncFieldsDuringCreateOrUpdate(ctx, plan) + + resp.Diagnostics.Append(resp.State.Set(ctx, newState)...) + if resp.Diagnostics.HasError() { + return + } + resp.Diagnostics.Append(tfschema.PopulateProviderConfigInState(ctx, r.Client, plan.ProviderConfig, &resp.State)...) +} + +func (r *DataApiResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + ctx = pluginfwcontext.SetUserAgentInResourceContext(ctx, resourceName) + + var existingState DataApi + resp.Diagnostics.Append(req.State.Get(ctx, &existingState)...) + if resp.Diagnostics.HasError() { + return + } + + var readRequest postgres.GetDataApiRequest + resp.Diagnostics.Append(converters.TfSdkToGoSdkStruct(ctx, existingState, &readRequest)...) + if resp.Diagnostics.HasError() { + return + } + + var namespace ProviderConfig + resp.Diagnostics.Append(existingState.ProviderConfig.As(ctx, &namespace, basetypes.ObjectAsOptions{ + UnhandledNullAsEmpty: true, + UnhandledUnknownAsEmpty: true, + })...) + if resp.Diagnostics.HasError() { + return + } + client, clientDiags := r.Client.GetWorkspaceClientForUnifiedProviderWithDiagnostics(ctx, namespace.WorkspaceID.ValueString()) + + resp.Diagnostics.Append(clientDiags...) + if resp.Diagnostics.HasError() { + return + } + response, err := client.Postgres.GetDataApi(ctx, readRequest) + if err != nil { + if apierr.IsMissing(err) { + resp.State.RemoveResource(ctx) + return + } + resp.Diagnostics.AddError("failed to get postgres_data_api", err.Error()) + return + } + + var newState DataApi + resp.Diagnostics.Append(converters.GoSdkToTfSdkStruct(ctx, response, &newState)...) + if resp.Diagnostics.HasError() { + return + } + + newState.SyncFieldsDuringRead(ctx, existingState) + + resp.Diagnostics.Append(resp.State.Set(ctx, newState)...) + if resp.Diagnostics.HasError() { + return + } + resp.Diagnostics.Append(tfschema.PopulateProviderConfigInState(ctx, r.Client, existingState.ProviderConfig, &resp.State)...) +} + +func (r *DataApiResource) update(ctx context.Context, plan DataApi, diags *diag.Diagnostics, state *tfsdk.State) { + var data_api postgres.DataApi + + diags.Append(converters.TfSdkToGoSdkStruct(ctx, plan, &data_api)...) + if diags.HasError() { + return + } + + updateRequest := postgres.UpdateDataApiRequest{ + DataApi: data_api, + Name: plan.Name.ValueString(), + UpdateMask: *fieldmask.New(strings.Split("spec", ",")), + } + + var namespace ProviderConfig + diags.Append(plan.ProviderConfig.As(ctx, &namespace, basetypes.ObjectAsOptions{ + UnhandledNullAsEmpty: true, + UnhandledUnknownAsEmpty: true, + })...) + if diags.HasError() { + return + } + client, clientDiags := r.Client.GetWorkspaceClientForUnifiedProviderWithDiagnostics(ctx, namespace.WorkspaceID.ValueString()) + + diags.Append(clientDiags...) + if diags.HasError() { + return + } + response, err := client.Postgres.UpdateDataApi(ctx, updateRequest) + if err != nil { + diags.AddError("failed to update postgres_data_api", err.Error()) + return + } + + var newState DataApi + + waitResponse, err := response.Wait(ctx) + if err != nil { + diags.AddError("error waiting for postgres_data_api update", err.Error()) + return + } + + diags.Append(converters.GoSdkToTfSdkStruct(ctx, waitResponse, &newState)...) + + if diags.HasError() { + return + } + + newState.SyncFieldsDuringCreateOrUpdate(ctx, plan) + diags.Append(state.Set(ctx, newState)...) +} + +func (r *DataApiResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + ctx = pluginfwcontext.SetUserAgentInResourceContext(ctx, resourceName) + + var plan DataApi + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + if resp.Diagnostics.HasError() { + return + } + + r.update(ctx, plan, &resp.Diagnostics, &resp.State) +} + +func (r *DataApiResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + ctx = pluginfwcontext.SetUserAgentInResourceContext(ctx, resourceName) + + var state DataApi + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + var deleteRequest postgres.DeleteDataApiRequest + resp.Diagnostics.Append(converters.TfSdkToGoSdkStruct(ctx, state, &deleteRequest)...) + if resp.Diagnostics.HasError() { + return + } + + var namespace ProviderConfig + resp.Diagnostics.Append(state.ProviderConfig.As(ctx, &namespace, basetypes.ObjectAsOptions{ + UnhandledNullAsEmpty: true, + UnhandledUnknownAsEmpty: true, + })...) + if resp.Diagnostics.HasError() { + return + } + client, clientDiags := r.Client.GetWorkspaceClientForUnifiedProviderWithDiagnostics(ctx, namespace.WorkspaceID.ValueString()) + + resp.Diagnostics.Append(clientDiags...) + if resp.Diagnostics.HasError() { + return + } + + response, err := client.Postgres.DeleteDataApi(ctx, deleteRequest) + if !declarative.IsDeleteError(err) { + err = nil + } + if err != nil { + resp.Diagnostics.AddError("failed to delete postgres_data_api", err.Error()) + return + } + if response == nil { + // MANAGED_BY_PARENT suppressed the initial Delete: skip Wait + // to avoid a nil-deref on response.Wait(ctx). + return + } + + err = response.Wait(ctx) + if !declarative.IsDeleteError(err) { + err = nil + } + if err != nil && !apierr.IsMissing(err) { + resp.Diagnostics.AddError("error waiting for postgres_data_api delete", err.Error()) + return + } + +} + +var _ resource.ResourceWithImportState = &DataApiResource{} + +func (r *DataApiResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + parts := strings.Split(req.ID, ",") + + if len(parts) != 1 || parts[0] == "" { + resp.Diagnostics.AddError( + "Unexpected Import Identifier", + fmt.Sprintf( + "Expected import identifier with format: name. Got: %q", + req.ID, + ), + ) + return + } + + name := parts[0] + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("name"), name)...) +} diff --git a/internal/service/postgres_tf/legacy_model.go b/internal/service/postgres_tf/legacy_model.go index 1e196afc95..d46bbbfae3 100755 --- a/internal/service/postgres_tf/legacy_model.go +++ b/internal/service/postgres_tf/legacy_model.go @@ -1075,6 +1075,108 @@ func (m *CreateCatalogRequest_SdkV2) SetCatalog(ctx context.Context, v Catalog_S m.Catalog = types.ListValueMust(t, vs) } +type CreateDataApiRequest_SdkV2 struct { + // The Data API configuration to create. + DataApi types.List `tfsdk:"data_api"` + // Parent database: + // projects/{project_id}/branches/{branch_id}/databases/{database_id} + Parent types.String `tfsdk:"-"` +} + +func (to *CreateDataApiRequest_SdkV2) SyncFieldsDuringCreateOrUpdate(ctx context.Context, from CreateDataApiRequest_SdkV2) { + if !from.DataApi.IsNull() && !from.DataApi.IsUnknown() { + if toDataApi, ok := to.GetDataApi(ctx); ok { + if fromDataApi, ok := from.GetDataApi(ctx); ok { + // Recursively sync the fields of DataApi + toDataApi.SyncFieldsDuringCreateOrUpdate(ctx, fromDataApi) + to.SetDataApi(ctx, toDataApi) + } + } + } +} + +func (to *CreateDataApiRequest_SdkV2) SyncFieldsDuringRead(ctx context.Context, from CreateDataApiRequest_SdkV2) { + if !from.DataApi.IsNull() && !from.DataApi.IsUnknown() { + if toDataApi, ok := to.GetDataApi(ctx); ok { + if fromDataApi, ok := from.GetDataApi(ctx); ok { + toDataApi.SyncFieldsDuringRead(ctx, fromDataApi) + to.SetDataApi(ctx, toDataApi) + } + } + } +} + +func (m CreateDataApiRequest_SdkV2) ApplySchemaCustomizations(attrs map[string]tfschema.AttributeBuilder) map[string]tfschema.AttributeBuilder { + attrs["data_api"] = attrs["data_api"].SetRequired() + attrs["data_api"] = attrs["data_api"].(tfschema.ListNestedAttributeBuilder).AddValidator(listvalidator.SizeAtMost(1)).(tfschema.AttributeBuilder) + attrs["parent"] = attrs["parent"].SetRequired() + + return attrs +} + +// GetComplexFieldTypes returns a map of the types of elements in complex fields in CreateDataApiRequest. +// Container types (types.Map, types.List, types.Set) and object types (types.Object) do not carry +// the type information of their elements in the Go type system. This function provides a way to +// retrieve the type information of the elements in complex fields at runtime. The values of the map +// are the reflected types of the contained elements. They must be either primitive values from the +// plugin framework type system (types.String{}, types.Bool{}, types.Int64{}, types.Float64{}) or TF +// SDK values. +func (m CreateDataApiRequest_SdkV2) GetComplexFieldTypes(ctx context.Context) map[string]reflect.Type { + return map[string]reflect.Type{ + "data_api": reflect.TypeOf(DataApi_SdkV2{}), + } +} + +// TFSDK types cannot implement the ObjectValuable interface directly, as it would otherwise +// interfere with how the plugin framework retrieves and sets values in state. Thus, CreateDataApiRequest_SdkV2 +// only implements ToObjectValue() and Type(). +func (m CreateDataApiRequest_SdkV2) ToObjectValue(ctx context.Context) basetypes.ObjectValue { + return types.ObjectValueMust( + m.Type(ctx).(basetypes.ObjectType).AttrTypes, + map[string]attr.Value{ + "data_api": m.DataApi, + "parent": m.Parent, + }) +} + +// Type implements basetypes.ObjectValuable. +func (m CreateDataApiRequest_SdkV2) Type(ctx context.Context) attr.Type { + return types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "data_api": basetypes.ListType{ + ElemType: DataApi_SdkV2{}.Type(ctx), + }, + "parent": types.StringType, + }, + } +} + +// GetDataApi returns the value of the DataApi field in CreateDataApiRequest_SdkV2 as +// a DataApi_SdkV2 value. +// If the field is unknown or null, the boolean return value is false. +func (m *CreateDataApiRequest_SdkV2) GetDataApi(ctx context.Context) (DataApi_SdkV2, bool) { + var e DataApi_SdkV2 + if m.DataApi.IsNull() || m.DataApi.IsUnknown() { + return e, false + } + var v []DataApi_SdkV2 + d := m.DataApi.ElementsAs(ctx, &v, true) + if d.HasError() { + panic(pluginfwcommon.DiagToString(d)) + } + if len(v) == 0 { + return e, false + } + return v[0], true +} + +// SetDataApi sets the value of the DataApi field in CreateDataApiRequest_SdkV2. +func (m *CreateDataApiRequest_SdkV2) SetDataApi(ctx context.Context, v DataApi_SdkV2) { + vs := []attr.Value{v.ToObjectValue(ctx)} + t := m.Type(ctx).(basetypes.ObjectType).AttrTypes["data_api"] + m.DataApi = types.ListValueMust(t, vs) +} + type CreateDatabaseRequest_SdkV2 struct { // The desired specification of a Database. Database types.List `tfsdk:"database"` @@ -1509,141 +1611,849 @@ func (m CreateRoleRequest_SdkV2) Type(ctx context.Context) attr.Type { } } -// GetRole returns the value of the Role field in CreateRoleRequest_SdkV2 as -// a Role_SdkV2 value. +// GetRole returns the value of the Role field in CreateRoleRequest_SdkV2 as +// a Role_SdkV2 value. +// If the field is unknown or null, the boolean return value is false. +func (m *CreateRoleRequest_SdkV2) GetRole(ctx context.Context) (Role_SdkV2, bool) { + var e Role_SdkV2 + if m.Role.IsNull() || m.Role.IsUnknown() { + return e, false + } + var v []Role_SdkV2 + d := m.Role.ElementsAs(ctx, &v, true) + if d.HasError() { + panic(pluginfwcommon.DiagToString(d)) + } + if len(v) == 0 { + return e, false + } + return v[0], true +} + +// SetRole sets the value of the Role field in CreateRoleRequest_SdkV2. +func (m *CreateRoleRequest_SdkV2) SetRole(ctx context.Context, v Role_SdkV2) { + vs := []attr.Value{v.ToObjectValue(ctx)} + t := m.Type(ctx).(basetypes.ObjectType).AttrTypes["role"] + m.Role = types.ListValueMust(t, vs) +} + +type CreateSyncedTableRequest_SdkV2 struct { + SyncedTable types.List `tfsdk:"synced_table"` + // The ID to use for the Synced Table. This becomes the final component of + // the SyncedTable's resource name. ID is required and is the synced table + // name, containing (catalog, schema, table) tuple. Elements of the tuple + // are the UC entity names. + // + // Example: "{catalog}.{schema}.{table}" + // + // synced_table_id represents both of the following: + // + // 1. An online VIEW virtual table in the Unity Catalog accessible via the + // Lakehouse Federation. 2. Postgres table named "{table}" in schema + // "{schema}" in the connected Postgres database + SyncedTableId types.String `tfsdk:"-"` +} + +func (to *CreateSyncedTableRequest_SdkV2) SyncFieldsDuringCreateOrUpdate(ctx context.Context, from CreateSyncedTableRequest_SdkV2) { + if !from.SyncedTable.IsNull() && !from.SyncedTable.IsUnknown() { + if toSyncedTable, ok := to.GetSyncedTable(ctx); ok { + if fromSyncedTable, ok := from.GetSyncedTable(ctx); ok { + // Recursively sync the fields of SyncedTable + toSyncedTable.SyncFieldsDuringCreateOrUpdate(ctx, fromSyncedTable) + to.SetSyncedTable(ctx, toSyncedTable) + } + } + } +} + +func (to *CreateSyncedTableRequest_SdkV2) SyncFieldsDuringRead(ctx context.Context, from CreateSyncedTableRequest_SdkV2) { + if !from.SyncedTable.IsNull() && !from.SyncedTable.IsUnknown() { + if toSyncedTable, ok := to.GetSyncedTable(ctx); ok { + if fromSyncedTable, ok := from.GetSyncedTable(ctx); ok { + toSyncedTable.SyncFieldsDuringRead(ctx, fromSyncedTable) + to.SetSyncedTable(ctx, toSyncedTable) + } + } + } +} + +func (m CreateSyncedTableRequest_SdkV2) ApplySchemaCustomizations(attrs map[string]tfschema.AttributeBuilder) map[string]tfschema.AttributeBuilder { + attrs["synced_table"] = attrs["synced_table"].SetRequired() + attrs["synced_table"] = attrs["synced_table"].(tfschema.ListNestedAttributeBuilder).AddValidator(listvalidator.SizeAtMost(1)).(tfschema.AttributeBuilder) + attrs["synced_table_id"] = attrs["synced_table_id"].SetRequired() + + return attrs +} + +// GetComplexFieldTypes returns a map of the types of elements in complex fields in CreateSyncedTableRequest. +// Container types (types.Map, types.List, types.Set) and object types (types.Object) do not carry +// the type information of their elements in the Go type system. This function provides a way to +// retrieve the type information of the elements in complex fields at runtime. The values of the map +// are the reflected types of the contained elements. They must be either primitive values from the +// plugin framework type system (types.String{}, types.Bool{}, types.Int64{}, types.Float64{}) or TF +// SDK values. +func (m CreateSyncedTableRequest_SdkV2) GetComplexFieldTypes(ctx context.Context) map[string]reflect.Type { + return map[string]reflect.Type{ + "synced_table": reflect.TypeOf(SyncedTable_SdkV2{}), + } +} + +// TFSDK types cannot implement the ObjectValuable interface directly, as it would otherwise +// interfere with how the plugin framework retrieves and sets values in state. Thus, CreateSyncedTableRequest_SdkV2 +// only implements ToObjectValue() and Type(). +func (m CreateSyncedTableRequest_SdkV2) ToObjectValue(ctx context.Context) basetypes.ObjectValue { + return types.ObjectValueMust( + m.Type(ctx).(basetypes.ObjectType).AttrTypes, + map[string]attr.Value{ + "synced_table": m.SyncedTable, + "synced_table_id": m.SyncedTableId, + }) +} + +// Type implements basetypes.ObjectValuable. +func (m CreateSyncedTableRequest_SdkV2) Type(ctx context.Context) attr.Type { + return types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "synced_table": basetypes.ListType{ + ElemType: SyncedTable_SdkV2{}.Type(ctx), + }, + "synced_table_id": types.StringType, + }, + } +} + +// GetSyncedTable returns the value of the SyncedTable field in CreateSyncedTableRequest_SdkV2 as +// a SyncedTable_SdkV2 value. +// If the field is unknown or null, the boolean return value is false. +func (m *CreateSyncedTableRequest_SdkV2) GetSyncedTable(ctx context.Context) (SyncedTable_SdkV2, bool) { + var e SyncedTable_SdkV2 + if m.SyncedTable.IsNull() || m.SyncedTable.IsUnknown() { + return e, false + } + var v []SyncedTable_SdkV2 + d := m.SyncedTable.ElementsAs(ctx, &v, true) + if d.HasError() { + panic(pluginfwcommon.DiagToString(d)) + } + if len(v) == 0 { + return e, false + } + return v[0], true +} + +// SetSyncedTable sets the value of the SyncedTable field in CreateSyncedTableRequest_SdkV2. +func (m *CreateSyncedTableRequest_SdkV2) SetSyncedTable(ctx context.Context, v SyncedTable_SdkV2) { + vs := []attr.Value{v.ToObjectValue(ctx)} + t := m.Type(ctx).(basetypes.ObjectType).AttrTypes["synced_table"] + m.SyncedTable = types.ListValueMust(t, vs) +} + +// DataApi represents the Data API (PostgREST) configuration for a Database. At +// most one DataApi per database. Create enables Data API, Delete disables it. +type DataApi_SdkV2 struct { + // A timestamp indicating when the Data API was first enabled. + CreateTime timetypes.RFC3339 `tfsdk:"create_time"` + // Resource name: + // projects/{project_id}/branches/{branch_id}/databases/{database_id}/data-api + Name types.String `tfsdk:"name"` + // The database containing this Data API configuration. Format: + // projects/{project_id}/branches/{branch_id}/databases/{database_id} + Parent types.String `tfsdk:"parent"` + // The desired Data API configuration. + Spec types.List `tfsdk:"spec"` + // The observed Data API state (read-only). + Status types.List `tfsdk:"status"` + // A timestamp indicating when the Data API configuration was last updated. + UpdateTime timetypes.RFC3339 `tfsdk:"update_time"` +} + +func (to *DataApi_SdkV2) SyncFieldsDuringCreateOrUpdate(ctx context.Context, from DataApi_SdkV2) { + if !from.Spec.IsUnknown() && !from.Spec.IsNull() { + // Spec is an input only field and not returned by the service, so we keep the value from the prior state. + to.Spec = from.Spec + } + if !from.Spec.IsNull() && !from.Spec.IsUnknown() { + if toSpec, ok := to.GetSpec(ctx); ok { + if fromSpec, ok := from.GetSpec(ctx); ok { + // Recursively sync the fields of Spec + toSpec.SyncFieldsDuringCreateOrUpdate(ctx, fromSpec) + to.SetSpec(ctx, toSpec) + } + } + } + if !from.Status.IsNull() && !from.Status.IsUnknown() { + if toStatus, ok := to.GetStatus(ctx); ok { + if fromStatus, ok := from.GetStatus(ctx); ok { + // Recursively sync the fields of Status + toStatus.SyncFieldsDuringCreateOrUpdate(ctx, fromStatus) + to.SetStatus(ctx, toStatus) + } + } + } +} + +func (to *DataApi_SdkV2) SyncFieldsDuringRead(ctx context.Context, from DataApi_SdkV2) { + if !from.Spec.IsUnknown() && !from.Spec.IsNull() { + // Spec is an input only field and not returned by the service, so we keep the value from the prior state. + to.Spec = from.Spec + } + if !from.Spec.IsNull() && !from.Spec.IsUnknown() { + if toSpec, ok := to.GetSpec(ctx); ok { + if fromSpec, ok := from.GetSpec(ctx); ok { + toSpec.SyncFieldsDuringRead(ctx, fromSpec) + to.SetSpec(ctx, toSpec) + } + } + } + if !from.Status.IsNull() && !from.Status.IsUnknown() { + if toStatus, ok := to.GetStatus(ctx); ok { + if fromStatus, ok := from.GetStatus(ctx); ok { + toStatus.SyncFieldsDuringRead(ctx, fromStatus) + to.SetStatus(ctx, toStatus) + } + } + } +} + +func (m DataApi_SdkV2) ApplySchemaCustomizations(attrs map[string]tfschema.AttributeBuilder) map[string]tfschema.AttributeBuilder { + attrs["create_time"] = attrs["create_time"].SetComputed() + attrs["name"] = attrs["name"].SetOptional() + attrs["parent"] = attrs["parent"].SetComputed() + attrs["spec"] = attrs["spec"].SetOptional() + attrs["spec"] = attrs["spec"].SetComputed() + attrs["spec"] = attrs["spec"].(tfschema.ListNestedAttributeBuilder).AddPlanModifier(listplanmodifier.UseStateForUnknown()).(tfschema.AttributeBuilder) + attrs["spec"] = attrs["spec"].(tfschema.ListNestedAttributeBuilder).AddValidator(listvalidator.SizeAtMost(1)).(tfschema.AttributeBuilder) + attrs["status"] = attrs["status"].SetComputed() + attrs["status"] = attrs["status"].(tfschema.ListNestedAttributeBuilder).AddValidator(listvalidator.SizeAtMost(1)).(tfschema.AttributeBuilder) + attrs["update_time"] = attrs["update_time"].SetComputed() + + return attrs +} + +// GetComplexFieldTypes returns a map of the types of elements in complex fields in DataApi. +// Container types (types.Map, types.List, types.Set) and object types (types.Object) do not carry +// the type information of their elements in the Go type system. This function provides a way to +// retrieve the type information of the elements in complex fields at runtime. The values of the map +// are the reflected types of the contained elements. They must be either primitive values from the +// plugin framework type system (types.String{}, types.Bool{}, types.Int64{}, types.Float64{}) or TF +// SDK values. +func (m DataApi_SdkV2) GetComplexFieldTypes(ctx context.Context) map[string]reflect.Type { + return map[string]reflect.Type{ + "spec": reflect.TypeOf(DataApiDataApiSpec_SdkV2{}), + "status": reflect.TypeOf(DataApiDataApiStatus_SdkV2{}), + } +} + +// TFSDK types cannot implement the ObjectValuable interface directly, as it would otherwise +// interfere with how the plugin framework retrieves and sets values in state. Thus, DataApi_SdkV2 +// only implements ToObjectValue() and Type(). +func (m DataApi_SdkV2) ToObjectValue(ctx context.Context) basetypes.ObjectValue { + return types.ObjectValueMust( + m.Type(ctx).(basetypes.ObjectType).AttrTypes, + map[string]attr.Value{ + "create_time": m.CreateTime, + "name": m.Name, + "parent": m.Parent, + "spec": m.Spec, + "status": m.Status, + "update_time": m.UpdateTime, + }) +} + +// Type implements basetypes.ObjectValuable. +func (m DataApi_SdkV2) Type(ctx context.Context) attr.Type { + return types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "create_time": timetypes.RFC3339{}.Type(ctx), + "name": types.StringType, + "parent": types.StringType, + "spec": basetypes.ListType{ + ElemType: DataApiDataApiSpec_SdkV2{}.Type(ctx), + }, + "status": basetypes.ListType{ + ElemType: DataApiDataApiStatus_SdkV2{}.Type(ctx), + }, + "update_time": timetypes.RFC3339{}.Type(ctx), + }, + } +} + +// GetSpec returns the value of the Spec field in DataApi_SdkV2 as +// a DataApiDataApiSpec_SdkV2 value. +// If the field is unknown or null, the boolean return value is false. +func (m *DataApi_SdkV2) GetSpec(ctx context.Context) (DataApiDataApiSpec_SdkV2, bool) { + var e DataApiDataApiSpec_SdkV2 + if m.Spec.IsNull() || m.Spec.IsUnknown() { + return e, false + } + var v []DataApiDataApiSpec_SdkV2 + d := m.Spec.ElementsAs(ctx, &v, true) + if d.HasError() { + panic(pluginfwcommon.DiagToString(d)) + } + if len(v) == 0 { + return e, false + } + return v[0], true +} + +// SetSpec sets the value of the Spec field in DataApi_SdkV2. +func (m *DataApi_SdkV2) SetSpec(ctx context.Context, v DataApiDataApiSpec_SdkV2) { + vs := []attr.Value{v.ToObjectValue(ctx)} + t := m.Type(ctx).(basetypes.ObjectType).AttrTypes["spec"] + m.Spec = types.ListValueMust(t, vs) +} + +// GetStatus returns the value of the Status field in DataApi_SdkV2 as +// a DataApiDataApiStatus_SdkV2 value. +// If the field is unknown or null, the boolean return value is false. +func (m *DataApi_SdkV2) GetStatus(ctx context.Context) (DataApiDataApiStatus_SdkV2, bool) { + var e DataApiDataApiStatus_SdkV2 + if m.Status.IsNull() || m.Status.IsUnknown() { + return e, false + } + var v []DataApiDataApiStatus_SdkV2 + d := m.Status.ElementsAs(ctx, &v, true) + if d.HasError() { + panic(pluginfwcommon.DiagToString(d)) + } + if len(v) == 0 { + return e, false + } + return v[0], true +} + +// SetStatus sets the value of the Status field in DataApi_SdkV2. +func (m *DataApi_SdkV2) SetStatus(ctx context.Context, v DataApiDataApiStatus_SdkV2) { + vs := []attr.Value{v.ToObjectValue(ctx)} + t := m.Type(ctx).(basetypes.ObjectType).AttrTypes["status"] + m.Status = types.ListValueMust(t, vs) +} + +// Desired PostgREST configuration (input). +type DataApiDataApiSpec_SdkV2 struct { + // Enable aggregate functions (count, sum, avg, etc.) in Data API responses. + // Default: true. + DbAggregatesEnabled types.Bool `tfsdk:"db_aggregates_enabled"` + // Additional schemas to include in the PostgreSQL search path. Each entry + // must be a valid PostgreSQL schema name. + DbExtraSearchPath types.List `tfsdk:"db_extra_search_path"` + // Maximum number of rows returned in a single Data API response. Must be a + // positive integer. + DbMaxRows types.Int64 `tfsdk:"db_max_rows"` + // Database schemas exposed through the Data API. Each entry must be a valid + // PostgreSQL schema name (1-63 chars, [a-zA-Z_][a-zA-Z0-9_$]*). Maximum 100 + // entries. Default: ["public"]. + DbSchemas types.List `tfsdk:"db_schemas"` + // Maximum lifetime for cached JWT tokens. Zero duration disables caching. + JwtCacheMaxLifetime timetypes.GoDuration `tfsdk:"jwt_cache_max_lifetime"` + // JSON path to the role claim in JWT tokens (e.g., ".sub"). Default: + // ".sub". + JwtRoleClaimKey types.String `tfsdk:"jwt_role_claim_key"` + // OpenAPI documentation mode for the Data API endpoint. + OpenapiMode types.String `tfsdk:"openapi_mode"` + // Allowed origins for CORS requests. Each entry should be a valid origin + // URL, or use "*" to allow all origins. + ServerCorsAllowedOrigins types.List `tfsdk:"server_cors_allowed_origins"` + // Enable the Server-Timing header in Data API responses. + ServerTimingEnabled types.Bool `tfsdk:"server_timing_enabled"` +} + +func (to *DataApiDataApiSpec_SdkV2) SyncFieldsDuringCreateOrUpdate(ctx context.Context, from DataApiDataApiSpec_SdkV2) { + if !from.DbExtraSearchPath.IsNull() && !from.DbExtraSearchPath.IsUnknown() && to.DbExtraSearchPath.IsNull() && len(from.DbExtraSearchPath.Elements()) == 0 { + // The default representation of an empty list for TF autogenerated resources in the resource state is Null. + // If a user specified a non-Null, empty list for DbExtraSearchPath, and the deserialized field value is Null, + // set the resulting resource state to the empty list to match the planned value. + to.DbExtraSearchPath = from.DbExtraSearchPath + } + if !from.DbSchemas.IsNull() && !from.DbSchemas.IsUnknown() && to.DbSchemas.IsNull() && len(from.DbSchemas.Elements()) == 0 { + // The default representation of an empty list for TF autogenerated resources in the resource state is Null. + // If a user specified a non-Null, empty list for DbSchemas, and the deserialized field value is Null, + // set the resulting resource state to the empty list to match the planned value. + to.DbSchemas = from.DbSchemas + } + if !from.ServerCorsAllowedOrigins.IsNull() && !from.ServerCorsAllowedOrigins.IsUnknown() && to.ServerCorsAllowedOrigins.IsNull() && len(from.ServerCorsAllowedOrigins.Elements()) == 0 { + // The default representation of an empty list for TF autogenerated resources in the resource state is Null. + // If a user specified a non-Null, empty list for ServerCorsAllowedOrigins, and the deserialized field value is Null, + // set the resulting resource state to the empty list to match the planned value. + to.ServerCorsAllowedOrigins = from.ServerCorsAllowedOrigins + } +} + +func (to *DataApiDataApiSpec_SdkV2) SyncFieldsDuringRead(ctx context.Context, from DataApiDataApiSpec_SdkV2) { + if !from.DbExtraSearchPath.IsNull() && !from.DbExtraSearchPath.IsUnknown() && to.DbExtraSearchPath.IsNull() && len(from.DbExtraSearchPath.Elements()) == 0 { + // The default representation of an empty list for TF autogenerated resources in the resource state is Null. + // If a user specified a non-Null, empty list for DbExtraSearchPath, and the deserialized field value is Null, + // set the resulting resource state to the empty list to match the planned value. + to.DbExtraSearchPath = from.DbExtraSearchPath + } + if !from.DbSchemas.IsNull() && !from.DbSchemas.IsUnknown() && to.DbSchemas.IsNull() && len(from.DbSchemas.Elements()) == 0 { + // The default representation of an empty list for TF autogenerated resources in the resource state is Null. + // If a user specified a non-Null, empty list for DbSchemas, and the deserialized field value is Null, + // set the resulting resource state to the empty list to match the planned value. + to.DbSchemas = from.DbSchemas + } + if !from.ServerCorsAllowedOrigins.IsNull() && !from.ServerCorsAllowedOrigins.IsUnknown() && to.ServerCorsAllowedOrigins.IsNull() && len(from.ServerCorsAllowedOrigins.Elements()) == 0 { + // The default representation of an empty list for TF autogenerated resources in the resource state is Null. + // If a user specified a non-Null, empty list for ServerCorsAllowedOrigins, and the deserialized field value is Null, + // set the resulting resource state to the empty list to match the planned value. + to.ServerCorsAllowedOrigins = from.ServerCorsAllowedOrigins + } +} + +func (m DataApiDataApiSpec_SdkV2) ApplySchemaCustomizations(attrs map[string]tfschema.AttributeBuilder) map[string]tfschema.AttributeBuilder { + attrs["db_aggregates_enabled"] = attrs["db_aggregates_enabled"].SetOptional() + attrs["db_extra_search_path"] = attrs["db_extra_search_path"].SetOptional() + attrs["db_max_rows"] = attrs["db_max_rows"].SetOptional() + attrs["db_schemas"] = attrs["db_schemas"].SetOptional() + attrs["jwt_cache_max_lifetime"] = attrs["jwt_cache_max_lifetime"].SetOptional() + attrs["jwt_role_claim_key"] = attrs["jwt_role_claim_key"].SetOptional() + attrs["openapi_mode"] = attrs["openapi_mode"].SetOptional() + attrs["server_cors_allowed_origins"] = attrs["server_cors_allowed_origins"].SetOptional() + attrs["server_timing_enabled"] = attrs["server_timing_enabled"].SetOptional() + + return attrs +} + +// GetComplexFieldTypes returns a map of the types of elements in complex fields in DataApiDataApiSpec. +// Container types (types.Map, types.List, types.Set) and object types (types.Object) do not carry +// the type information of their elements in the Go type system. This function provides a way to +// retrieve the type information of the elements in complex fields at runtime. The values of the map +// are the reflected types of the contained elements. They must be either primitive values from the +// plugin framework type system (types.String{}, types.Bool{}, types.Int64{}, types.Float64{}) or TF +// SDK values. +func (m DataApiDataApiSpec_SdkV2) GetComplexFieldTypes(ctx context.Context) map[string]reflect.Type { + return map[string]reflect.Type{ + "db_extra_search_path": reflect.TypeOf(types.String{}), + "db_schemas": reflect.TypeOf(types.String{}), + "server_cors_allowed_origins": reflect.TypeOf(types.String{}), + } +} + +// TFSDK types cannot implement the ObjectValuable interface directly, as it would otherwise +// interfere with how the plugin framework retrieves and sets values in state. Thus, DataApiDataApiSpec_SdkV2 +// only implements ToObjectValue() and Type(). +func (m DataApiDataApiSpec_SdkV2) ToObjectValue(ctx context.Context) basetypes.ObjectValue { + return types.ObjectValueMust( + m.Type(ctx).(basetypes.ObjectType).AttrTypes, + map[string]attr.Value{ + "db_aggregates_enabled": m.DbAggregatesEnabled, + "db_extra_search_path": m.DbExtraSearchPath, + "db_max_rows": m.DbMaxRows, + "db_schemas": m.DbSchemas, + "jwt_cache_max_lifetime": m.JwtCacheMaxLifetime, + "jwt_role_claim_key": m.JwtRoleClaimKey, + "openapi_mode": m.OpenapiMode, + "server_cors_allowed_origins": m.ServerCorsAllowedOrigins, + "server_timing_enabled": m.ServerTimingEnabled, + }) +} + +// Type implements basetypes.ObjectValuable. +func (m DataApiDataApiSpec_SdkV2) Type(ctx context.Context) attr.Type { + return types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "db_aggregates_enabled": types.BoolType, + "db_extra_search_path": basetypes.ListType{ + ElemType: types.StringType, + }, + "db_max_rows": types.Int64Type, + "db_schemas": basetypes.ListType{ + ElemType: types.StringType, + }, + "jwt_cache_max_lifetime": timetypes.GoDuration{}.Type(ctx), + "jwt_role_claim_key": types.StringType, + "openapi_mode": types.StringType, + "server_cors_allowed_origins": basetypes.ListType{ + ElemType: types.StringType, + }, + "server_timing_enabled": types.BoolType, + }, + } +} + +// GetDbExtraSearchPath returns the value of the DbExtraSearchPath field in DataApiDataApiSpec_SdkV2 as +// a slice of types.String values. +// If the field is unknown or null, the boolean return value is false. +func (m *DataApiDataApiSpec_SdkV2) GetDbExtraSearchPath(ctx context.Context) ([]types.String, bool) { + if m.DbExtraSearchPath.IsNull() || m.DbExtraSearchPath.IsUnknown() { + return nil, false + } + var v []types.String + d := m.DbExtraSearchPath.ElementsAs(ctx, &v, true) + if d.HasError() { + panic(pluginfwcommon.DiagToString(d)) + } + return v, true +} + +// SetDbExtraSearchPath sets the value of the DbExtraSearchPath field in DataApiDataApiSpec_SdkV2. +func (m *DataApiDataApiSpec_SdkV2) SetDbExtraSearchPath(ctx context.Context, v []types.String) { + vs := make([]attr.Value, 0, len(v)) + for _, e := range v { + vs = append(vs, e) + } + t := m.Type(ctx).(basetypes.ObjectType).AttrTypes["db_extra_search_path"] + t = t.(attr.TypeWithElementType).ElementType() + m.DbExtraSearchPath = types.ListValueMust(t, vs) +} + +// GetDbSchemas returns the value of the DbSchemas field in DataApiDataApiSpec_SdkV2 as +// a slice of types.String values. +// If the field is unknown or null, the boolean return value is false. +func (m *DataApiDataApiSpec_SdkV2) GetDbSchemas(ctx context.Context) ([]types.String, bool) { + if m.DbSchemas.IsNull() || m.DbSchemas.IsUnknown() { + return nil, false + } + var v []types.String + d := m.DbSchemas.ElementsAs(ctx, &v, true) + if d.HasError() { + panic(pluginfwcommon.DiagToString(d)) + } + return v, true +} + +// SetDbSchemas sets the value of the DbSchemas field in DataApiDataApiSpec_SdkV2. +func (m *DataApiDataApiSpec_SdkV2) SetDbSchemas(ctx context.Context, v []types.String) { + vs := make([]attr.Value, 0, len(v)) + for _, e := range v { + vs = append(vs, e) + } + t := m.Type(ctx).(basetypes.ObjectType).AttrTypes["db_schemas"] + t = t.(attr.TypeWithElementType).ElementType() + m.DbSchemas = types.ListValueMust(t, vs) +} + +// GetServerCorsAllowedOrigins returns the value of the ServerCorsAllowedOrigins field in DataApiDataApiSpec_SdkV2 as +// a slice of types.String values. +// If the field is unknown or null, the boolean return value is false. +func (m *DataApiDataApiSpec_SdkV2) GetServerCorsAllowedOrigins(ctx context.Context) ([]types.String, bool) { + if m.ServerCorsAllowedOrigins.IsNull() || m.ServerCorsAllowedOrigins.IsUnknown() { + return nil, false + } + var v []types.String + d := m.ServerCorsAllowedOrigins.ElementsAs(ctx, &v, true) + if d.HasError() { + panic(pluginfwcommon.DiagToString(d)) + } + return v, true +} + +// SetServerCorsAllowedOrigins sets the value of the ServerCorsAllowedOrigins field in DataApiDataApiSpec_SdkV2. +func (m *DataApiDataApiSpec_SdkV2) SetServerCorsAllowedOrigins(ctx context.Context, v []types.String) { + vs := make([]attr.Value, 0, len(v)) + for _, e := range v { + vs = append(vs, e) + } + t := m.Type(ctx).(basetypes.ObjectType).AttrTypes["server_cors_allowed_origins"] + t = t.(attr.TypeWithElementType).ElementType() + m.ServerCorsAllowedOrigins = types.ListValueMust(t, vs) +} + +// Observed state (output-only). +type DataApiDataApiStatus_SdkV2 struct { + // Schemas available in the database (for reference when configuring + // db_schemas). + AvailableSchemas types.List `tfsdk:"available_schemas"` + // Actual aggregate function setting read from the database. + DbAggregatesEnabled types.Bool `tfsdk:"db_aggregates_enabled"` + // Actual extra search path schemas read from the database. + DbExtraSearchPath types.List `tfsdk:"db_extra_search_path"` + // Actual max rows setting read from the database. + DbMaxRows types.Int64 `tfsdk:"db_max_rows"` + // Actual exposed schemas read from the database. + DbSchemas types.List `tfsdk:"db_schemas"` + // Actual JWT cache max lifetime read from the database. + JwtCacheMaxLifetime timetypes.GoDuration `tfsdk:"jwt_cache_max_lifetime"` + // Actual JWT role claim key read from the database. + JwtRoleClaimKey types.String `tfsdk:"jwt_role_claim_key"` + // Actual OpenAPI mode read from the database. + OpenapiMode types.String `tfsdk:"openapi_mode"` + // Actual CORS allowed origins read from the database. + ServerCorsAllowedOrigins types.List `tfsdk:"server_cors_allowed_origins"` + // Actual Server-Timing header setting read from the database. + ServerTimingEnabled types.Bool `tfsdk:"server_timing_enabled"` + // Data API endpoint URL. + Url types.String `tfsdk:"url"` +} + +func (to *DataApiDataApiStatus_SdkV2) SyncFieldsDuringCreateOrUpdate(ctx context.Context, from DataApiDataApiStatus_SdkV2) { + if !from.AvailableSchemas.IsNull() && !from.AvailableSchemas.IsUnknown() && to.AvailableSchemas.IsNull() && len(from.AvailableSchemas.Elements()) == 0 { + // The default representation of an empty list for TF autogenerated resources in the resource state is Null. + // If a user specified a non-Null, empty list for AvailableSchemas, and the deserialized field value is Null, + // set the resulting resource state to the empty list to match the planned value. + to.AvailableSchemas = from.AvailableSchemas + } + if !from.DbExtraSearchPath.IsNull() && !from.DbExtraSearchPath.IsUnknown() && to.DbExtraSearchPath.IsNull() && len(from.DbExtraSearchPath.Elements()) == 0 { + // The default representation of an empty list for TF autogenerated resources in the resource state is Null. + // If a user specified a non-Null, empty list for DbExtraSearchPath, and the deserialized field value is Null, + // set the resulting resource state to the empty list to match the planned value. + to.DbExtraSearchPath = from.DbExtraSearchPath + } + if !from.DbSchemas.IsNull() && !from.DbSchemas.IsUnknown() && to.DbSchemas.IsNull() && len(from.DbSchemas.Elements()) == 0 { + // The default representation of an empty list for TF autogenerated resources in the resource state is Null. + // If a user specified a non-Null, empty list for DbSchemas, and the deserialized field value is Null, + // set the resulting resource state to the empty list to match the planned value. + to.DbSchemas = from.DbSchemas + } + if !from.ServerCorsAllowedOrigins.IsNull() && !from.ServerCorsAllowedOrigins.IsUnknown() && to.ServerCorsAllowedOrigins.IsNull() && len(from.ServerCorsAllowedOrigins.Elements()) == 0 { + // The default representation of an empty list for TF autogenerated resources in the resource state is Null. + // If a user specified a non-Null, empty list for ServerCorsAllowedOrigins, and the deserialized field value is Null, + // set the resulting resource state to the empty list to match the planned value. + to.ServerCorsAllowedOrigins = from.ServerCorsAllowedOrigins + } +} + +func (to *DataApiDataApiStatus_SdkV2) SyncFieldsDuringRead(ctx context.Context, from DataApiDataApiStatus_SdkV2) { + if !from.AvailableSchemas.IsNull() && !from.AvailableSchemas.IsUnknown() && to.AvailableSchemas.IsNull() && len(from.AvailableSchemas.Elements()) == 0 { + // The default representation of an empty list for TF autogenerated resources in the resource state is Null. + // If a user specified a non-Null, empty list for AvailableSchemas, and the deserialized field value is Null, + // set the resulting resource state to the empty list to match the planned value. + to.AvailableSchemas = from.AvailableSchemas + } + if !from.DbExtraSearchPath.IsNull() && !from.DbExtraSearchPath.IsUnknown() && to.DbExtraSearchPath.IsNull() && len(from.DbExtraSearchPath.Elements()) == 0 { + // The default representation of an empty list for TF autogenerated resources in the resource state is Null. + // If a user specified a non-Null, empty list for DbExtraSearchPath, and the deserialized field value is Null, + // set the resulting resource state to the empty list to match the planned value. + to.DbExtraSearchPath = from.DbExtraSearchPath + } + if !from.DbSchemas.IsNull() && !from.DbSchemas.IsUnknown() && to.DbSchemas.IsNull() && len(from.DbSchemas.Elements()) == 0 { + // The default representation of an empty list for TF autogenerated resources in the resource state is Null. + // If a user specified a non-Null, empty list for DbSchemas, and the deserialized field value is Null, + // set the resulting resource state to the empty list to match the planned value. + to.DbSchemas = from.DbSchemas + } + if !from.ServerCorsAllowedOrigins.IsNull() && !from.ServerCorsAllowedOrigins.IsUnknown() && to.ServerCorsAllowedOrigins.IsNull() && len(from.ServerCorsAllowedOrigins.Elements()) == 0 { + // The default representation of an empty list for TF autogenerated resources in the resource state is Null. + // If a user specified a non-Null, empty list for ServerCorsAllowedOrigins, and the deserialized field value is Null, + // set the resulting resource state to the empty list to match the planned value. + to.ServerCorsAllowedOrigins = from.ServerCorsAllowedOrigins + } +} + +func (m DataApiDataApiStatus_SdkV2) ApplySchemaCustomizations(attrs map[string]tfschema.AttributeBuilder) map[string]tfschema.AttributeBuilder { + attrs["available_schemas"] = attrs["available_schemas"].SetComputed() + attrs["db_aggregates_enabled"] = attrs["db_aggregates_enabled"].SetComputed() + attrs["db_extra_search_path"] = attrs["db_extra_search_path"].SetComputed() + attrs["db_max_rows"] = attrs["db_max_rows"].SetComputed() + attrs["db_schemas"] = attrs["db_schemas"].SetComputed() + attrs["jwt_cache_max_lifetime"] = attrs["jwt_cache_max_lifetime"].SetComputed() + attrs["jwt_role_claim_key"] = attrs["jwt_role_claim_key"].SetComputed() + attrs["openapi_mode"] = attrs["openapi_mode"].SetComputed() + attrs["server_cors_allowed_origins"] = attrs["server_cors_allowed_origins"].SetComputed() + attrs["server_timing_enabled"] = attrs["server_timing_enabled"].SetComputed() + attrs["url"] = attrs["url"].SetComputed() + + return attrs +} + +// GetComplexFieldTypes returns a map of the types of elements in complex fields in DataApiDataApiStatus. +// Container types (types.Map, types.List, types.Set) and object types (types.Object) do not carry +// the type information of their elements in the Go type system. This function provides a way to +// retrieve the type information of the elements in complex fields at runtime. The values of the map +// are the reflected types of the contained elements. They must be either primitive values from the +// plugin framework type system (types.String{}, types.Bool{}, types.Int64{}, types.Float64{}) or TF +// SDK values. +func (m DataApiDataApiStatus_SdkV2) GetComplexFieldTypes(ctx context.Context) map[string]reflect.Type { + return map[string]reflect.Type{ + "available_schemas": reflect.TypeOf(types.String{}), + "db_extra_search_path": reflect.TypeOf(types.String{}), + "db_schemas": reflect.TypeOf(types.String{}), + "server_cors_allowed_origins": reflect.TypeOf(types.String{}), + } +} + +// TFSDK types cannot implement the ObjectValuable interface directly, as it would otherwise +// interfere with how the plugin framework retrieves and sets values in state. Thus, DataApiDataApiStatus_SdkV2 +// only implements ToObjectValue() and Type(). +func (m DataApiDataApiStatus_SdkV2) ToObjectValue(ctx context.Context) basetypes.ObjectValue { + return types.ObjectValueMust( + m.Type(ctx).(basetypes.ObjectType).AttrTypes, + map[string]attr.Value{ + "available_schemas": m.AvailableSchemas, + "db_aggregates_enabled": m.DbAggregatesEnabled, + "db_extra_search_path": m.DbExtraSearchPath, + "db_max_rows": m.DbMaxRows, + "db_schemas": m.DbSchemas, + "jwt_cache_max_lifetime": m.JwtCacheMaxLifetime, + "jwt_role_claim_key": m.JwtRoleClaimKey, + "openapi_mode": m.OpenapiMode, + "server_cors_allowed_origins": m.ServerCorsAllowedOrigins, + "server_timing_enabled": m.ServerTimingEnabled, + "url": m.Url, + }) +} + +// Type implements basetypes.ObjectValuable. +func (m DataApiDataApiStatus_SdkV2) Type(ctx context.Context) attr.Type { + return types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "available_schemas": basetypes.ListType{ + ElemType: types.StringType, + }, + "db_aggregates_enabled": types.BoolType, + "db_extra_search_path": basetypes.ListType{ + ElemType: types.StringType, + }, + "db_max_rows": types.Int64Type, + "db_schemas": basetypes.ListType{ + ElemType: types.StringType, + }, + "jwt_cache_max_lifetime": timetypes.GoDuration{}.Type(ctx), + "jwt_role_claim_key": types.StringType, + "openapi_mode": types.StringType, + "server_cors_allowed_origins": basetypes.ListType{ + ElemType: types.StringType, + }, + "server_timing_enabled": types.BoolType, + "url": types.StringType, + }, + } +} + +// GetAvailableSchemas returns the value of the AvailableSchemas field in DataApiDataApiStatus_SdkV2 as +// a slice of types.String values. +// If the field is unknown or null, the boolean return value is false. +func (m *DataApiDataApiStatus_SdkV2) GetAvailableSchemas(ctx context.Context) ([]types.String, bool) { + if m.AvailableSchemas.IsNull() || m.AvailableSchemas.IsUnknown() { + return nil, false + } + var v []types.String + d := m.AvailableSchemas.ElementsAs(ctx, &v, true) + if d.HasError() { + panic(pluginfwcommon.DiagToString(d)) + } + return v, true +} + +// SetAvailableSchemas sets the value of the AvailableSchemas field in DataApiDataApiStatus_SdkV2. +func (m *DataApiDataApiStatus_SdkV2) SetAvailableSchemas(ctx context.Context, v []types.String) { + vs := make([]attr.Value, 0, len(v)) + for _, e := range v { + vs = append(vs, e) + } + t := m.Type(ctx).(basetypes.ObjectType).AttrTypes["available_schemas"] + t = t.(attr.TypeWithElementType).ElementType() + m.AvailableSchemas = types.ListValueMust(t, vs) +} + +// GetDbExtraSearchPath returns the value of the DbExtraSearchPath field in DataApiDataApiStatus_SdkV2 as +// a slice of types.String values. +// If the field is unknown or null, the boolean return value is false. +func (m *DataApiDataApiStatus_SdkV2) GetDbExtraSearchPath(ctx context.Context) ([]types.String, bool) { + if m.DbExtraSearchPath.IsNull() || m.DbExtraSearchPath.IsUnknown() { + return nil, false + } + var v []types.String + d := m.DbExtraSearchPath.ElementsAs(ctx, &v, true) + if d.HasError() { + panic(pluginfwcommon.DiagToString(d)) + } + return v, true +} + +// SetDbExtraSearchPath sets the value of the DbExtraSearchPath field in DataApiDataApiStatus_SdkV2. +func (m *DataApiDataApiStatus_SdkV2) SetDbExtraSearchPath(ctx context.Context, v []types.String) { + vs := make([]attr.Value, 0, len(v)) + for _, e := range v { + vs = append(vs, e) + } + t := m.Type(ctx).(basetypes.ObjectType).AttrTypes["db_extra_search_path"] + t = t.(attr.TypeWithElementType).ElementType() + m.DbExtraSearchPath = types.ListValueMust(t, vs) +} + +// GetDbSchemas returns the value of the DbSchemas field in DataApiDataApiStatus_SdkV2 as +// a slice of types.String values. +// If the field is unknown or null, the boolean return value is false. +func (m *DataApiDataApiStatus_SdkV2) GetDbSchemas(ctx context.Context) ([]types.String, bool) { + if m.DbSchemas.IsNull() || m.DbSchemas.IsUnknown() { + return nil, false + } + var v []types.String + d := m.DbSchemas.ElementsAs(ctx, &v, true) + if d.HasError() { + panic(pluginfwcommon.DiagToString(d)) + } + return v, true +} + +// SetDbSchemas sets the value of the DbSchemas field in DataApiDataApiStatus_SdkV2. +func (m *DataApiDataApiStatus_SdkV2) SetDbSchemas(ctx context.Context, v []types.String) { + vs := make([]attr.Value, 0, len(v)) + for _, e := range v { + vs = append(vs, e) + } + t := m.Type(ctx).(basetypes.ObjectType).AttrTypes["db_schemas"] + t = t.(attr.TypeWithElementType).ElementType() + m.DbSchemas = types.ListValueMust(t, vs) +} + +// GetServerCorsAllowedOrigins returns the value of the ServerCorsAllowedOrigins field in DataApiDataApiStatus_SdkV2 as +// a slice of types.String values. // If the field is unknown or null, the boolean return value is false. -func (m *CreateRoleRequest_SdkV2) GetRole(ctx context.Context) (Role_SdkV2, bool) { - var e Role_SdkV2 - if m.Role.IsNull() || m.Role.IsUnknown() { - return e, false +func (m *DataApiDataApiStatus_SdkV2) GetServerCorsAllowedOrigins(ctx context.Context) ([]types.String, bool) { + if m.ServerCorsAllowedOrigins.IsNull() || m.ServerCorsAllowedOrigins.IsUnknown() { + return nil, false } - var v []Role_SdkV2 - d := m.Role.ElementsAs(ctx, &v, true) + var v []types.String + d := m.ServerCorsAllowedOrigins.ElementsAs(ctx, &v, true) if d.HasError() { panic(pluginfwcommon.DiagToString(d)) } - if len(v) == 0 { - return e, false - } - return v[0], true + return v, true } -// SetRole sets the value of the Role field in CreateRoleRequest_SdkV2. -func (m *CreateRoleRequest_SdkV2) SetRole(ctx context.Context, v Role_SdkV2) { - vs := []attr.Value{v.ToObjectValue(ctx)} - t := m.Type(ctx).(basetypes.ObjectType).AttrTypes["role"] - m.Role = types.ListValueMust(t, vs) +// SetServerCorsAllowedOrigins sets the value of the ServerCorsAllowedOrigins field in DataApiDataApiStatus_SdkV2. +func (m *DataApiDataApiStatus_SdkV2) SetServerCorsAllowedOrigins(ctx context.Context, v []types.String) { + vs := make([]attr.Value, 0, len(v)) + for _, e := range v { + vs = append(vs, e) + } + t := m.Type(ctx).(basetypes.ObjectType).AttrTypes["server_cors_allowed_origins"] + t = t.(attr.TypeWithElementType).ElementType() + m.ServerCorsAllowedOrigins = types.ListValueMust(t, vs) } -type CreateSyncedTableRequest_SdkV2 struct { - SyncedTable types.List `tfsdk:"synced_table"` - // The ID to use for the Synced Table. This becomes the final component of - // the SyncedTable's resource name. ID is required and is the synced table - // name, containing (catalog, schema, table) tuple. Elements of the tuple - // are the UC entity names. - // - // Example: "{catalog}.{schema}.{table}" - // - // synced_table_id represents both of the following: - // - // 1. An online VIEW virtual table in the Unity Catalog accessible via the - // Lakehouse Federation. 2. Postgres table named "{table}" in schema - // "{schema}" in the connected Postgres database - SyncedTableId types.String `tfsdk:"-"` +type DataApiOperationMetadata_SdkV2 struct { } -func (to *CreateSyncedTableRequest_SdkV2) SyncFieldsDuringCreateOrUpdate(ctx context.Context, from CreateSyncedTableRequest_SdkV2) { - if !from.SyncedTable.IsNull() && !from.SyncedTable.IsUnknown() { - if toSyncedTable, ok := to.GetSyncedTable(ctx); ok { - if fromSyncedTable, ok := from.GetSyncedTable(ctx); ok { - // Recursively sync the fields of SyncedTable - toSyncedTable.SyncFieldsDuringCreateOrUpdate(ctx, fromSyncedTable) - to.SetSyncedTable(ctx, toSyncedTable) - } - } - } +func (to *DataApiOperationMetadata_SdkV2) SyncFieldsDuringCreateOrUpdate(ctx context.Context, from DataApiOperationMetadata_SdkV2) { } -func (to *CreateSyncedTableRequest_SdkV2) SyncFieldsDuringRead(ctx context.Context, from CreateSyncedTableRequest_SdkV2) { - if !from.SyncedTable.IsNull() && !from.SyncedTable.IsUnknown() { - if toSyncedTable, ok := to.GetSyncedTable(ctx); ok { - if fromSyncedTable, ok := from.GetSyncedTable(ctx); ok { - toSyncedTable.SyncFieldsDuringRead(ctx, fromSyncedTable) - to.SetSyncedTable(ctx, toSyncedTable) - } - } - } +func (to *DataApiOperationMetadata_SdkV2) SyncFieldsDuringRead(ctx context.Context, from DataApiOperationMetadata_SdkV2) { } -func (m CreateSyncedTableRequest_SdkV2) ApplySchemaCustomizations(attrs map[string]tfschema.AttributeBuilder) map[string]tfschema.AttributeBuilder { - attrs["synced_table"] = attrs["synced_table"].SetRequired() - attrs["synced_table"] = attrs["synced_table"].(tfschema.ListNestedAttributeBuilder).AddValidator(listvalidator.SizeAtMost(1)).(tfschema.AttributeBuilder) - attrs["synced_table_id"] = attrs["synced_table_id"].SetRequired() +func (m DataApiOperationMetadata_SdkV2) ApplySchemaCustomizations(attrs map[string]tfschema.AttributeBuilder) map[string]tfschema.AttributeBuilder { return attrs } -// GetComplexFieldTypes returns a map of the types of elements in complex fields in CreateSyncedTableRequest. +// GetComplexFieldTypes returns a map of the types of elements in complex fields in DataApiOperationMetadata. // Container types (types.Map, types.List, types.Set) and object types (types.Object) do not carry // the type information of their elements in the Go type system. This function provides a way to // retrieve the type information of the elements in complex fields at runtime. The values of the map // are the reflected types of the contained elements. They must be either primitive values from the // plugin framework type system (types.String{}, types.Bool{}, types.Int64{}, types.Float64{}) or TF // SDK values. -func (m CreateSyncedTableRequest_SdkV2) GetComplexFieldTypes(ctx context.Context) map[string]reflect.Type { - return map[string]reflect.Type{ - "synced_table": reflect.TypeOf(SyncedTable_SdkV2{}), - } +func (m DataApiOperationMetadata_SdkV2) GetComplexFieldTypes(ctx context.Context) map[string]reflect.Type { + return map[string]reflect.Type{} } // TFSDK types cannot implement the ObjectValuable interface directly, as it would otherwise -// interfere with how the plugin framework retrieves and sets values in state. Thus, CreateSyncedTableRequest_SdkV2 +// interfere with how the plugin framework retrieves and sets values in state. Thus, DataApiOperationMetadata_SdkV2 // only implements ToObjectValue() and Type(). -func (m CreateSyncedTableRequest_SdkV2) ToObjectValue(ctx context.Context) basetypes.ObjectValue { +func (m DataApiOperationMetadata_SdkV2) ToObjectValue(ctx context.Context) basetypes.ObjectValue { return types.ObjectValueMust( m.Type(ctx).(basetypes.ObjectType).AttrTypes, - map[string]attr.Value{ - "synced_table": m.SyncedTable, - "synced_table_id": m.SyncedTableId, - }) + map[string]attr.Value{}) } // Type implements basetypes.ObjectValuable. -func (m CreateSyncedTableRequest_SdkV2) Type(ctx context.Context) attr.Type { +func (m DataApiOperationMetadata_SdkV2) Type(ctx context.Context) attr.Type { return types.ObjectType{ - AttrTypes: map[string]attr.Type{ - "synced_table": basetypes.ListType{ - ElemType: SyncedTable_SdkV2{}.Type(ctx), - }, - "synced_table_id": types.StringType, - }, - } -} - -// GetSyncedTable returns the value of the SyncedTable field in CreateSyncedTableRequest_SdkV2 as -// a SyncedTable_SdkV2 value. -// If the field is unknown or null, the boolean return value is false. -func (m *CreateSyncedTableRequest_SdkV2) GetSyncedTable(ctx context.Context) (SyncedTable_SdkV2, bool) { - var e SyncedTable_SdkV2 - if m.SyncedTable.IsNull() || m.SyncedTable.IsUnknown() { - return e, false - } - var v []SyncedTable_SdkV2 - d := m.SyncedTable.ElementsAs(ctx, &v, true) - if d.HasError() { - panic(pluginfwcommon.DiagToString(d)) - } - if len(v) == 0 { - return e, false + AttrTypes: map[string]attr.Type{}, } - return v[0], true -} - -// SetSyncedTable sets the value of the SyncedTable field in CreateSyncedTableRequest_SdkV2. -func (m *CreateSyncedTableRequest_SdkV2) SetSyncedTable(ctx context.Context, v SyncedTable_SdkV2) { - vs := []attr.Value{v.ToObjectValue(ctx)} - t := m.Type(ctx).(basetypes.ObjectType).AttrTypes["synced_table"] - m.SyncedTable = types.ListValueMust(t, vs) } // Database represents a Postgres database within a Branch. @@ -2260,6 +3070,55 @@ func (m DeleteCatalogRequest_SdkV2) Type(ctx context.Context) attr.Type { } } +type DeleteDataApiRequest_SdkV2 struct { + // Resource name: + // projects/{project_id}/branches/{branch_id}/databases/{database_id}/data-api + Name types.String `tfsdk:"-"` +} + +func (to *DeleteDataApiRequest_SdkV2) SyncFieldsDuringCreateOrUpdate(ctx context.Context, from DeleteDataApiRequest_SdkV2) { +} + +func (to *DeleteDataApiRequest_SdkV2) SyncFieldsDuringRead(ctx context.Context, from DeleteDataApiRequest_SdkV2) { +} + +func (m DeleteDataApiRequest_SdkV2) ApplySchemaCustomizations(attrs map[string]tfschema.AttributeBuilder) map[string]tfschema.AttributeBuilder { + attrs["name"] = attrs["name"].SetRequired() + + return attrs +} + +// GetComplexFieldTypes returns a map of the types of elements in complex fields in DeleteDataApiRequest. +// Container types (types.Map, types.List, types.Set) and object types (types.Object) do not carry +// the type information of their elements in the Go type system. This function provides a way to +// retrieve the type information of the elements in complex fields at runtime. The values of the map +// are the reflected types of the contained elements. They must be either primitive values from the +// plugin framework type system (types.String{}, types.Bool{}, types.Int64{}, types.Float64{}) or TF +// SDK values. +func (m DeleteDataApiRequest_SdkV2) GetComplexFieldTypes(ctx context.Context) map[string]reflect.Type { + return map[string]reflect.Type{} +} + +// TFSDK types cannot implement the ObjectValuable interface directly, as it would otherwise +// interfere with how the plugin framework retrieves and sets values in state. Thus, DeleteDataApiRequest_SdkV2 +// only implements ToObjectValue() and Type(). +func (m DeleteDataApiRequest_SdkV2) ToObjectValue(ctx context.Context) basetypes.ObjectValue { + return types.ObjectValueMust( + m.Type(ctx).(basetypes.ObjectType).AttrTypes, + map[string]attr.Value{ + "name": m.Name, + }) +} + +// Type implements basetypes.ObjectValuable. +func (m DeleteDataApiRequest_SdkV2) Type(ctx context.Context) attr.Type { + return types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "name": types.StringType, + }, + } +} + type DeleteDatabaseRequest_SdkV2 struct { // The resource name of the postgres database. Format: // projects/{project_id}/branches/{branch_id}/databases/{database_id} @@ -3707,6 +4566,55 @@ func (m GetCatalogRequest_SdkV2) Type(ctx context.Context) attr.Type { } } +type GetDataApiRequest_SdkV2 struct { + // Resource name: + // projects/{project_id}/branches/{branch_id}/databases/{database_id}/data-api + Name types.String `tfsdk:"-"` +} + +func (to *GetDataApiRequest_SdkV2) SyncFieldsDuringCreateOrUpdate(ctx context.Context, from GetDataApiRequest_SdkV2) { +} + +func (to *GetDataApiRequest_SdkV2) SyncFieldsDuringRead(ctx context.Context, from GetDataApiRequest_SdkV2) { +} + +func (m GetDataApiRequest_SdkV2) ApplySchemaCustomizations(attrs map[string]tfschema.AttributeBuilder) map[string]tfschema.AttributeBuilder { + attrs["name"] = attrs["name"].SetRequired() + + return attrs +} + +// GetComplexFieldTypes returns a map of the types of elements in complex fields in GetDataApiRequest. +// Container types (types.Map, types.List, types.Set) and object types (types.Object) do not carry +// the type information of their elements in the Go type system. This function provides a way to +// retrieve the type information of the elements in complex fields at runtime. The values of the map +// are the reflected types of the contained elements. They must be either primitive values from the +// plugin framework type system (types.String{}, types.Bool{}, types.Int64{}, types.Float64{}) or TF +// SDK values. +func (m GetDataApiRequest_SdkV2) GetComplexFieldTypes(ctx context.Context) map[string]reflect.Type { + return map[string]reflect.Type{} +} + +// TFSDK types cannot implement the ObjectValuable interface directly, as it would otherwise +// interfere with how the plugin framework retrieves and sets values in state. Thus, GetDataApiRequest_SdkV2 +// only implements ToObjectValue() and Type(). +func (m GetDataApiRequest_SdkV2) ToObjectValue(ctx context.Context) basetypes.ObjectValue { + return types.ObjectValueMust( + m.Type(ctx).(basetypes.ObjectType).AttrTypes, + map[string]attr.Value{ + "name": m.Name, + }) +} + +// Type implements basetypes.ObjectValuable. +func (m GetDataApiRequest_SdkV2) Type(ctx context.Context) attr.Type { + return types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "name": types.StringType, + }, + } +} + type GetDatabaseRequest_SdkV2 struct { // The name of the Database to retrieve. Format: // projects/{project_id}/branches/{branch_id}/databases/{database_id} @@ -7835,6 +8743,115 @@ func (m *UpdateBranchRequest_SdkV2) SetBranch(ctx context.Context, v Branch_SdkV m.Branch = types.ListValueMust(t, vs) } +type UpdateDataApiRequest_SdkV2 struct { + // The Data API configuration to update. The data_api's `name` field + // identifies the resource. + DataApi types.List `tfsdk:"data_api"` + // Resource name: + // projects/{project_id}/branches/{branch_id}/databases/{database_id}/data-api + Name types.String `tfsdk:"-"` + // The list of fields to update. If unspecified, all fields will be updated + // when possible. + UpdateMask types.String `tfsdk:"-"` +} + +func (to *UpdateDataApiRequest_SdkV2) SyncFieldsDuringCreateOrUpdate(ctx context.Context, from UpdateDataApiRequest_SdkV2) { + if !from.DataApi.IsNull() && !from.DataApi.IsUnknown() { + if toDataApi, ok := to.GetDataApi(ctx); ok { + if fromDataApi, ok := from.GetDataApi(ctx); ok { + // Recursively sync the fields of DataApi + toDataApi.SyncFieldsDuringCreateOrUpdate(ctx, fromDataApi) + to.SetDataApi(ctx, toDataApi) + } + } + } +} + +func (to *UpdateDataApiRequest_SdkV2) SyncFieldsDuringRead(ctx context.Context, from UpdateDataApiRequest_SdkV2) { + if !from.DataApi.IsNull() && !from.DataApi.IsUnknown() { + if toDataApi, ok := to.GetDataApi(ctx); ok { + if fromDataApi, ok := from.GetDataApi(ctx); ok { + toDataApi.SyncFieldsDuringRead(ctx, fromDataApi) + to.SetDataApi(ctx, toDataApi) + } + } + } +} + +func (m UpdateDataApiRequest_SdkV2) ApplySchemaCustomizations(attrs map[string]tfschema.AttributeBuilder) map[string]tfschema.AttributeBuilder { + attrs["data_api"] = attrs["data_api"].SetRequired() + attrs["data_api"] = attrs["data_api"].(tfschema.ListNestedAttributeBuilder).AddValidator(listvalidator.SizeAtMost(1)).(tfschema.AttributeBuilder) + attrs["name"] = attrs["name"].SetRequired() + attrs["update_mask"] = attrs["update_mask"].SetRequired() + + return attrs +} + +// GetComplexFieldTypes returns a map of the types of elements in complex fields in UpdateDataApiRequest. +// Container types (types.Map, types.List, types.Set) and object types (types.Object) do not carry +// the type information of their elements in the Go type system. This function provides a way to +// retrieve the type information of the elements in complex fields at runtime. The values of the map +// are the reflected types of the contained elements. They must be either primitive values from the +// plugin framework type system (types.String{}, types.Bool{}, types.Int64{}, types.Float64{}) or TF +// SDK values. +func (m UpdateDataApiRequest_SdkV2) GetComplexFieldTypes(ctx context.Context) map[string]reflect.Type { + return map[string]reflect.Type{ + "data_api": reflect.TypeOf(DataApi_SdkV2{}), + } +} + +// TFSDK types cannot implement the ObjectValuable interface directly, as it would otherwise +// interfere with how the plugin framework retrieves and sets values in state. Thus, UpdateDataApiRequest_SdkV2 +// only implements ToObjectValue() and Type(). +func (m UpdateDataApiRequest_SdkV2) ToObjectValue(ctx context.Context) basetypes.ObjectValue { + return types.ObjectValueMust( + m.Type(ctx).(basetypes.ObjectType).AttrTypes, + map[string]attr.Value{ + "data_api": m.DataApi, + "name": m.Name, + "update_mask": m.UpdateMask, + }) +} + +// Type implements basetypes.ObjectValuable. +func (m UpdateDataApiRequest_SdkV2) Type(ctx context.Context) attr.Type { + return types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "data_api": basetypes.ListType{ + ElemType: DataApi_SdkV2{}.Type(ctx), + }, + "name": types.StringType, + "update_mask": types.StringType, + }, + } +} + +// GetDataApi returns the value of the DataApi field in UpdateDataApiRequest_SdkV2 as +// a DataApi_SdkV2 value. +// If the field is unknown or null, the boolean return value is false. +func (m *UpdateDataApiRequest_SdkV2) GetDataApi(ctx context.Context) (DataApi_SdkV2, bool) { + var e DataApi_SdkV2 + if m.DataApi.IsNull() || m.DataApi.IsUnknown() { + return e, false + } + var v []DataApi_SdkV2 + d := m.DataApi.ElementsAs(ctx, &v, true) + if d.HasError() { + panic(pluginfwcommon.DiagToString(d)) + } + if len(v) == 0 { + return e, false + } + return v[0], true +} + +// SetDataApi sets the value of the DataApi field in UpdateDataApiRequest_SdkV2. +func (m *UpdateDataApiRequest_SdkV2) SetDataApi(ctx context.Context, v DataApi_SdkV2) { + vs := []attr.Value{v.ToObjectValue(ctx)} + t := m.Type(ctx).(basetypes.ObjectType).AttrTypes["data_api"] + m.DataApi = types.ListValueMust(t, vs) +} + type UpdateDatabaseRequest_SdkV2 struct { // The Database to update. // diff --git a/internal/service/postgres_tf/model.go b/internal/service/postgres_tf/model.go index c018840a7f..06df824b02 100755 --- a/internal/service/postgres_tf/model.go +++ b/internal/service/postgres_tf/model.go @@ -1050,6 +1050,104 @@ func (m *CreateCatalogRequest) SetCatalog(ctx context.Context, v Catalog) { m.Catalog = vs } +type CreateDataApiRequest struct { + // The Data API configuration to create. + DataApi types.Object `tfsdk:"data_api"` + // Parent database: + // projects/{project_id}/branches/{branch_id}/databases/{database_id} + Parent types.String `tfsdk:"-"` +} + +func (to *CreateDataApiRequest) SyncFieldsDuringCreateOrUpdate(ctx context.Context, from CreateDataApiRequest) { + if !from.DataApi.IsNull() && !from.DataApi.IsUnknown() { + if toDataApi, ok := to.GetDataApi(ctx); ok { + if fromDataApi, ok := from.GetDataApi(ctx); ok { + // Recursively sync the fields of DataApi + toDataApi.SyncFieldsDuringCreateOrUpdate(ctx, fromDataApi) + to.SetDataApi(ctx, toDataApi) + } + } + } +} + +func (to *CreateDataApiRequest) SyncFieldsDuringRead(ctx context.Context, from CreateDataApiRequest) { + if !from.DataApi.IsNull() && !from.DataApi.IsUnknown() { + if toDataApi, ok := to.GetDataApi(ctx); ok { + if fromDataApi, ok := from.GetDataApi(ctx); ok { + toDataApi.SyncFieldsDuringRead(ctx, fromDataApi) + to.SetDataApi(ctx, toDataApi) + } + } + } +} + +func (m CreateDataApiRequest) ApplySchemaCustomizations(attrs map[string]tfschema.AttributeBuilder) map[string]tfschema.AttributeBuilder { + attrs["data_api"] = attrs["data_api"].SetRequired() + attrs["parent"] = attrs["parent"].SetRequired() + + return attrs +} + +// GetComplexFieldTypes returns a map of the types of elements in complex fields in CreateDataApiRequest. +// Container types (types.Map, types.List, types.Set) and object types (types.Object) do not carry +// the type information of their elements in the Go type system. This function provides a way to +// retrieve the type information of the elements in complex fields at runtime. The values of the map +// are the reflected types of the contained elements. They must be either primitive values from the +// plugin framework type system (types.String{}, types.Bool{}, types.Int64{}, types.Float64{}) or TF +// SDK values. +func (m CreateDataApiRequest) GetComplexFieldTypes(ctx context.Context) map[string]reflect.Type { + return map[string]reflect.Type{ + "data_api": reflect.TypeOf(DataApi{}), + } +} + +// TFSDK types cannot implement the ObjectValuable interface directly, as it would otherwise +// interfere with how the plugin framework retrieves and sets values in state. Thus, CreateDataApiRequest +// only implements ToObjectValue() and Type(). +func (m CreateDataApiRequest) ToObjectValue(ctx context.Context) basetypes.ObjectValue { + return types.ObjectValueMust( + m.Type(ctx).(basetypes.ObjectType).AttrTypes, + map[string]attr.Value{ + "data_api": m.DataApi, + "parent": m.Parent, + }) +} + +// Type implements basetypes.ObjectValuable. +func (m CreateDataApiRequest) Type(ctx context.Context) attr.Type { + return types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "data_api": DataApi{}.Type(ctx), + "parent": types.StringType, + }, + } +} + +// GetDataApi returns the value of the DataApi field in CreateDataApiRequest as +// a DataApi value. +// If the field is unknown or null, the boolean return value is false. +func (m *CreateDataApiRequest) GetDataApi(ctx context.Context) (DataApi, bool) { + var e DataApi + if m.DataApi.IsNull() || m.DataApi.IsUnknown() { + return e, false + } + var v DataApi + d := m.DataApi.As(ctx, &v, basetypes.ObjectAsOptions{ + UnhandledNullAsEmpty: true, + UnhandledUnknownAsEmpty: true, + }) + if d.HasError() { + panic(pluginfwcommon.DiagToString(d)) + } + return v, true +} + +// SetDataApi sets the value of the DataApi field in CreateDataApiRequest. +func (m *CreateDataApiRequest) SetDataApi(ctx context.Context, v DataApi) { + vs := v.ToObjectValue(ctx) + m.DataApi = vs +} + type CreateDatabaseRequest struct { // The desired specification of a Database. Database types.Object `tfsdk:"database"` @@ -1469,136 +1567,836 @@ func (m CreateRoleRequest) Type(ctx context.Context) attr.Type { } } -// GetRole returns the value of the Role field in CreateRoleRequest as -// a Role value. +// GetRole returns the value of the Role field in CreateRoleRequest as +// a Role value. +// If the field is unknown or null, the boolean return value is false. +func (m *CreateRoleRequest) GetRole(ctx context.Context) (Role, bool) { + var e Role + if m.Role.IsNull() || m.Role.IsUnknown() { + return e, false + } + var v Role + d := m.Role.As(ctx, &v, basetypes.ObjectAsOptions{ + UnhandledNullAsEmpty: true, + UnhandledUnknownAsEmpty: true, + }) + if d.HasError() { + panic(pluginfwcommon.DiagToString(d)) + } + return v, true +} + +// SetRole sets the value of the Role field in CreateRoleRequest. +func (m *CreateRoleRequest) SetRole(ctx context.Context, v Role) { + vs := v.ToObjectValue(ctx) + m.Role = vs +} + +type CreateSyncedTableRequest struct { + SyncedTable types.Object `tfsdk:"synced_table"` + // The ID to use for the Synced Table. This becomes the final component of + // the SyncedTable's resource name. ID is required and is the synced table + // name, containing (catalog, schema, table) tuple. Elements of the tuple + // are the UC entity names. + // + // Example: "{catalog}.{schema}.{table}" + // + // synced_table_id represents both of the following: + // + // 1. An online VIEW virtual table in the Unity Catalog accessible via the + // Lakehouse Federation. 2. Postgres table named "{table}" in schema + // "{schema}" in the connected Postgres database + SyncedTableId types.String `tfsdk:"-"` +} + +func (to *CreateSyncedTableRequest) SyncFieldsDuringCreateOrUpdate(ctx context.Context, from CreateSyncedTableRequest) { + if !from.SyncedTable.IsNull() && !from.SyncedTable.IsUnknown() { + if toSyncedTable, ok := to.GetSyncedTable(ctx); ok { + if fromSyncedTable, ok := from.GetSyncedTable(ctx); ok { + // Recursively sync the fields of SyncedTable + toSyncedTable.SyncFieldsDuringCreateOrUpdate(ctx, fromSyncedTable) + to.SetSyncedTable(ctx, toSyncedTable) + } + } + } +} + +func (to *CreateSyncedTableRequest) SyncFieldsDuringRead(ctx context.Context, from CreateSyncedTableRequest) { + if !from.SyncedTable.IsNull() && !from.SyncedTable.IsUnknown() { + if toSyncedTable, ok := to.GetSyncedTable(ctx); ok { + if fromSyncedTable, ok := from.GetSyncedTable(ctx); ok { + toSyncedTable.SyncFieldsDuringRead(ctx, fromSyncedTable) + to.SetSyncedTable(ctx, toSyncedTable) + } + } + } +} + +func (m CreateSyncedTableRequest) ApplySchemaCustomizations(attrs map[string]tfschema.AttributeBuilder) map[string]tfschema.AttributeBuilder { + attrs["synced_table"] = attrs["synced_table"].SetRequired() + attrs["synced_table_id"] = attrs["synced_table_id"].SetRequired() + + return attrs +} + +// GetComplexFieldTypes returns a map of the types of elements in complex fields in CreateSyncedTableRequest. +// Container types (types.Map, types.List, types.Set) and object types (types.Object) do not carry +// the type information of their elements in the Go type system. This function provides a way to +// retrieve the type information of the elements in complex fields at runtime. The values of the map +// are the reflected types of the contained elements. They must be either primitive values from the +// plugin framework type system (types.String{}, types.Bool{}, types.Int64{}, types.Float64{}) or TF +// SDK values. +func (m CreateSyncedTableRequest) GetComplexFieldTypes(ctx context.Context) map[string]reflect.Type { + return map[string]reflect.Type{ + "synced_table": reflect.TypeOf(SyncedTable{}), + } +} + +// TFSDK types cannot implement the ObjectValuable interface directly, as it would otherwise +// interfere with how the plugin framework retrieves and sets values in state. Thus, CreateSyncedTableRequest +// only implements ToObjectValue() and Type(). +func (m CreateSyncedTableRequest) ToObjectValue(ctx context.Context) basetypes.ObjectValue { + return types.ObjectValueMust( + m.Type(ctx).(basetypes.ObjectType).AttrTypes, + map[string]attr.Value{ + "synced_table": m.SyncedTable, + "synced_table_id": m.SyncedTableId, + }) +} + +// Type implements basetypes.ObjectValuable. +func (m CreateSyncedTableRequest) Type(ctx context.Context) attr.Type { + return types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "synced_table": SyncedTable{}.Type(ctx), + "synced_table_id": types.StringType, + }, + } +} + +// GetSyncedTable returns the value of the SyncedTable field in CreateSyncedTableRequest as +// a SyncedTable value. +// If the field is unknown or null, the boolean return value is false. +func (m *CreateSyncedTableRequest) GetSyncedTable(ctx context.Context) (SyncedTable, bool) { + var e SyncedTable + if m.SyncedTable.IsNull() || m.SyncedTable.IsUnknown() { + return e, false + } + var v SyncedTable + d := m.SyncedTable.As(ctx, &v, basetypes.ObjectAsOptions{ + UnhandledNullAsEmpty: true, + UnhandledUnknownAsEmpty: true, + }) + if d.HasError() { + panic(pluginfwcommon.DiagToString(d)) + } + return v, true +} + +// SetSyncedTable sets the value of the SyncedTable field in CreateSyncedTableRequest. +func (m *CreateSyncedTableRequest) SetSyncedTable(ctx context.Context, v SyncedTable) { + vs := v.ToObjectValue(ctx) + m.SyncedTable = vs +} + +// DataApi represents the Data API (PostgREST) configuration for a Database. At +// most one DataApi per database. Create enables Data API, Delete disables it. +type DataApi struct { + // A timestamp indicating when the Data API was first enabled. + CreateTime timetypes.RFC3339 `tfsdk:"create_time"` + // Resource name: + // projects/{project_id}/branches/{branch_id}/databases/{database_id}/data-api + Name types.String `tfsdk:"name"` + // The database containing this Data API configuration. Format: + // projects/{project_id}/branches/{branch_id}/databases/{database_id} + Parent types.String `tfsdk:"parent"` + // The desired Data API configuration. + Spec types.Object `tfsdk:"spec"` + // The observed Data API state (read-only). + Status types.Object `tfsdk:"status"` + // A timestamp indicating when the Data API configuration was last updated. + UpdateTime timetypes.RFC3339 `tfsdk:"update_time"` +} + +func (to *DataApi) SyncFieldsDuringCreateOrUpdate(ctx context.Context, from DataApi) { + if !from.Spec.IsUnknown() && !from.Spec.IsNull() { + // Spec is an input only field and not returned by the service, so we keep the value from the prior state. + to.Spec = from.Spec + } + if !from.Spec.IsNull() && !from.Spec.IsUnknown() { + if toSpec, ok := to.GetSpec(ctx); ok { + if fromSpec, ok := from.GetSpec(ctx); ok { + // Recursively sync the fields of Spec + toSpec.SyncFieldsDuringCreateOrUpdate(ctx, fromSpec) + to.SetSpec(ctx, toSpec) + } + } + } + if !from.Status.IsNull() && !from.Status.IsUnknown() { + if toStatus, ok := to.GetStatus(ctx); ok { + if fromStatus, ok := from.GetStatus(ctx); ok { + // Recursively sync the fields of Status + toStatus.SyncFieldsDuringCreateOrUpdate(ctx, fromStatus) + to.SetStatus(ctx, toStatus) + } + } + } +} + +func (to *DataApi) SyncFieldsDuringRead(ctx context.Context, from DataApi) { + if !from.Spec.IsUnknown() && !from.Spec.IsNull() { + // Spec is an input only field and not returned by the service, so we keep the value from the prior state. + to.Spec = from.Spec + } + if !from.Spec.IsNull() && !from.Spec.IsUnknown() { + if toSpec, ok := to.GetSpec(ctx); ok { + if fromSpec, ok := from.GetSpec(ctx); ok { + toSpec.SyncFieldsDuringRead(ctx, fromSpec) + to.SetSpec(ctx, toSpec) + } + } + } + if !from.Status.IsNull() && !from.Status.IsUnknown() { + if toStatus, ok := to.GetStatus(ctx); ok { + if fromStatus, ok := from.GetStatus(ctx); ok { + toStatus.SyncFieldsDuringRead(ctx, fromStatus) + to.SetStatus(ctx, toStatus) + } + } + } +} + +func (m DataApi) ApplySchemaCustomizations(attrs map[string]tfschema.AttributeBuilder) map[string]tfschema.AttributeBuilder { + attrs["create_time"] = attrs["create_time"].SetComputed() + attrs["name"] = attrs["name"].SetOptional() + attrs["parent"] = attrs["parent"].SetComputed() + attrs["spec"] = attrs["spec"].SetOptional() + attrs["spec"] = attrs["spec"].SetComputed() + attrs["spec"] = attrs["spec"].(tfschema.SingleNestedAttributeBuilder).AddPlanModifier(objectplanmodifier.UseStateForUnknown()).(tfschema.AttributeBuilder) + attrs["status"] = attrs["status"].SetComputed() + attrs["update_time"] = attrs["update_time"].SetComputed() + + return attrs +} + +// GetComplexFieldTypes returns a map of the types of elements in complex fields in DataApi. +// Container types (types.Map, types.List, types.Set) and object types (types.Object) do not carry +// the type information of their elements in the Go type system. This function provides a way to +// retrieve the type information of the elements in complex fields at runtime. The values of the map +// are the reflected types of the contained elements. They must be either primitive values from the +// plugin framework type system (types.String{}, types.Bool{}, types.Int64{}, types.Float64{}) or TF +// SDK values. +func (m DataApi) GetComplexFieldTypes(ctx context.Context) map[string]reflect.Type { + return map[string]reflect.Type{ + "spec": reflect.TypeOf(DataApiDataApiSpec{}), + "status": reflect.TypeOf(DataApiDataApiStatus{}), + } +} + +// TFSDK types cannot implement the ObjectValuable interface directly, as it would otherwise +// interfere with how the plugin framework retrieves and sets values in state. Thus, DataApi +// only implements ToObjectValue() and Type(). +func (m DataApi) ToObjectValue(ctx context.Context) basetypes.ObjectValue { + return types.ObjectValueMust( + m.Type(ctx).(basetypes.ObjectType).AttrTypes, + map[string]attr.Value{ + "create_time": m.CreateTime, + "name": m.Name, + "parent": m.Parent, + "spec": m.Spec, + "status": m.Status, + "update_time": m.UpdateTime, + }) +} + +// Type implements basetypes.ObjectValuable. +func (m DataApi) Type(ctx context.Context) attr.Type { + return types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "create_time": timetypes.RFC3339{}.Type(ctx), + "name": types.StringType, + "parent": types.StringType, + "spec": DataApiDataApiSpec{}.Type(ctx), + "status": DataApiDataApiStatus{}.Type(ctx), + "update_time": timetypes.RFC3339{}.Type(ctx), + }, + } +} + +// GetSpec returns the value of the Spec field in DataApi as +// a DataApiDataApiSpec value. +// If the field is unknown or null, the boolean return value is false. +func (m *DataApi) GetSpec(ctx context.Context) (DataApiDataApiSpec, bool) { + var e DataApiDataApiSpec + if m.Spec.IsNull() || m.Spec.IsUnknown() { + return e, false + } + var v DataApiDataApiSpec + d := m.Spec.As(ctx, &v, basetypes.ObjectAsOptions{ + UnhandledNullAsEmpty: true, + UnhandledUnknownAsEmpty: true, + }) + if d.HasError() { + panic(pluginfwcommon.DiagToString(d)) + } + return v, true +} + +// SetSpec sets the value of the Spec field in DataApi. +func (m *DataApi) SetSpec(ctx context.Context, v DataApiDataApiSpec) { + vs := v.ToObjectValue(ctx) + m.Spec = vs +} + +// GetStatus returns the value of the Status field in DataApi as +// a DataApiDataApiStatus value. +// If the field is unknown or null, the boolean return value is false. +func (m *DataApi) GetStatus(ctx context.Context) (DataApiDataApiStatus, bool) { + var e DataApiDataApiStatus + if m.Status.IsNull() || m.Status.IsUnknown() { + return e, false + } + var v DataApiDataApiStatus + d := m.Status.As(ctx, &v, basetypes.ObjectAsOptions{ + UnhandledNullAsEmpty: true, + UnhandledUnknownAsEmpty: true, + }) + if d.HasError() { + panic(pluginfwcommon.DiagToString(d)) + } + return v, true +} + +// SetStatus sets the value of the Status field in DataApi. +func (m *DataApi) SetStatus(ctx context.Context, v DataApiDataApiStatus) { + vs := v.ToObjectValue(ctx) + m.Status = vs +} + +// Desired PostgREST configuration (input). +type DataApiDataApiSpec struct { + // Enable aggregate functions (count, sum, avg, etc.) in Data API responses. + // Default: true. + DbAggregatesEnabled types.Bool `tfsdk:"db_aggregates_enabled"` + // Additional schemas to include in the PostgreSQL search path. Each entry + // must be a valid PostgreSQL schema name. + DbExtraSearchPath types.List `tfsdk:"db_extra_search_path"` + // Maximum number of rows returned in a single Data API response. Must be a + // positive integer. + DbMaxRows types.Int64 `tfsdk:"db_max_rows"` + // Database schemas exposed through the Data API. Each entry must be a valid + // PostgreSQL schema name (1-63 chars, [a-zA-Z_][a-zA-Z0-9_$]*). Maximum 100 + // entries. Default: ["public"]. + DbSchemas types.List `tfsdk:"db_schemas"` + // Maximum lifetime for cached JWT tokens. Zero duration disables caching. + JwtCacheMaxLifetime timetypes.GoDuration `tfsdk:"jwt_cache_max_lifetime"` + // JSON path to the role claim in JWT tokens (e.g., ".sub"). Default: + // ".sub". + JwtRoleClaimKey types.String `tfsdk:"jwt_role_claim_key"` + // OpenAPI documentation mode for the Data API endpoint. + OpenapiMode types.String `tfsdk:"openapi_mode"` + // Allowed origins for CORS requests. Each entry should be a valid origin + // URL, or use "*" to allow all origins. + ServerCorsAllowedOrigins types.List `tfsdk:"server_cors_allowed_origins"` + // Enable the Server-Timing header in Data API responses. + ServerTimingEnabled types.Bool `tfsdk:"server_timing_enabled"` +} + +func (to *DataApiDataApiSpec) SyncFieldsDuringCreateOrUpdate(ctx context.Context, from DataApiDataApiSpec) { + if !from.DbExtraSearchPath.IsNull() && !from.DbExtraSearchPath.IsUnknown() && to.DbExtraSearchPath.IsNull() && len(from.DbExtraSearchPath.Elements()) == 0 { + // The default representation of an empty list for TF autogenerated resources in the resource state is Null. + // If a user specified a non-Null, empty list for DbExtraSearchPath, and the deserialized field value is Null, + // set the resulting resource state to the empty list to match the planned value. + to.DbExtraSearchPath = from.DbExtraSearchPath + } + if !from.DbSchemas.IsNull() && !from.DbSchemas.IsUnknown() && to.DbSchemas.IsNull() && len(from.DbSchemas.Elements()) == 0 { + // The default representation of an empty list for TF autogenerated resources in the resource state is Null. + // If a user specified a non-Null, empty list for DbSchemas, and the deserialized field value is Null, + // set the resulting resource state to the empty list to match the planned value. + to.DbSchemas = from.DbSchemas + } + if !from.ServerCorsAllowedOrigins.IsNull() && !from.ServerCorsAllowedOrigins.IsUnknown() && to.ServerCorsAllowedOrigins.IsNull() && len(from.ServerCorsAllowedOrigins.Elements()) == 0 { + // The default representation of an empty list for TF autogenerated resources in the resource state is Null. + // If a user specified a non-Null, empty list for ServerCorsAllowedOrigins, and the deserialized field value is Null, + // set the resulting resource state to the empty list to match the planned value. + to.ServerCorsAllowedOrigins = from.ServerCorsAllowedOrigins + } +} + +func (to *DataApiDataApiSpec) SyncFieldsDuringRead(ctx context.Context, from DataApiDataApiSpec) { + if !from.DbExtraSearchPath.IsNull() && !from.DbExtraSearchPath.IsUnknown() && to.DbExtraSearchPath.IsNull() && len(from.DbExtraSearchPath.Elements()) == 0 { + // The default representation of an empty list for TF autogenerated resources in the resource state is Null. + // If a user specified a non-Null, empty list for DbExtraSearchPath, and the deserialized field value is Null, + // set the resulting resource state to the empty list to match the planned value. + to.DbExtraSearchPath = from.DbExtraSearchPath + } + if !from.DbSchemas.IsNull() && !from.DbSchemas.IsUnknown() && to.DbSchemas.IsNull() && len(from.DbSchemas.Elements()) == 0 { + // The default representation of an empty list for TF autogenerated resources in the resource state is Null. + // If a user specified a non-Null, empty list for DbSchemas, and the deserialized field value is Null, + // set the resulting resource state to the empty list to match the planned value. + to.DbSchemas = from.DbSchemas + } + if !from.ServerCorsAllowedOrigins.IsNull() && !from.ServerCorsAllowedOrigins.IsUnknown() && to.ServerCorsAllowedOrigins.IsNull() && len(from.ServerCorsAllowedOrigins.Elements()) == 0 { + // The default representation of an empty list for TF autogenerated resources in the resource state is Null. + // If a user specified a non-Null, empty list for ServerCorsAllowedOrigins, and the deserialized field value is Null, + // set the resulting resource state to the empty list to match the planned value. + to.ServerCorsAllowedOrigins = from.ServerCorsAllowedOrigins + } +} + +func (m DataApiDataApiSpec) ApplySchemaCustomizations(attrs map[string]tfschema.AttributeBuilder) map[string]tfschema.AttributeBuilder { + attrs["db_aggregates_enabled"] = attrs["db_aggregates_enabled"].SetOptional() + attrs["db_extra_search_path"] = attrs["db_extra_search_path"].SetOptional() + attrs["db_max_rows"] = attrs["db_max_rows"].SetOptional() + attrs["db_schemas"] = attrs["db_schemas"].SetOptional() + attrs["jwt_cache_max_lifetime"] = attrs["jwt_cache_max_lifetime"].SetOptional() + attrs["jwt_role_claim_key"] = attrs["jwt_role_claim_key"].SetOptional() + attrs["openapi_mode"] = attrs["openapi_mode"].SetOptional() + attrs["server_cors_allowed_origins"] = attrs["server_cors_allowed_origins"].SetOptional() + attrs["server_timing_enabled"] = attrs["server_timing_enabled"].SetOptional() + + return attrs +} + +// GetComplexFieldTypes returns a map of the types of elements in complex fields in DataApiDataApiSpec. +// Container types (types.Map, types.List, types.Set) and object types (types.Object) do not carry +// the type information of their elements in the Go type system. This function provides a way to +// retrieve the type information of the elements in complex fields at runtime. The values of the map +// are the reflected types of the contained elements. They must be either primitive values from the +// plugin framework type system (types.String{}, types.Bool{}, types.Int64{}, types.Float64{}) or TF +// SDK values. +func (m DataApiDataApiSpec) GetComplexFieldTypes(ctx context.Context) map[string]reflect.Type { + return map[string]reflect.Type{ + "db_extra_search_path": reflect.TypeOf(types.String{}), + "db_schemas": reflect.TypeOf(types.String{}), + "server_cors_allowed_origins": reflect.TypeOf(types.String{}), + } +} + +// TFSDK types cannot implement the ObjectValuable interface directly, as it would otherwise +// interfere with how the plugin framework retrieves and sets values in state. Thus, DataApiDataApiSpec +// only implements ToObjectValue() and Type(). +func (m DataApiDataApiSpec) ToObjectValue(ctx context.Context) basetypes.ObjectValue { + return types.ObjectValueMust( + m.Type(ctx).(basetypes.ObjectType).AttrTypes, + map[string]attr.Value{ + "db_aggregates_enabled": m.DbAggregatesEnabled, + "db_extra_search_path": m.DbExtraSearchPath, + "db_max_rows": m.DbMaxRows, + "db_schemas": m.DbSchemas, + "jwt_cache_max_lifetime": m.JwtCacheMaxLifetime, + "jwt_role_claim_key": m.JwtRoleClaimKey, + "openapi_mode": m.OpenapiMode, + "server_cors_allowed_origins": m.ServerCorsAllowedOrigins, + "server_timing_enabled": m.ServerTimingEnabled, + }) +} + +// Type implements basetypes.ObjectValuable. +func (m DataApiDataApiSpec) Type(ctx context.Context) attr.Type { + return types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "db_aggregates_enabled": types.BoolType, + "db_extra_search_path": basetypes.ListType{ + ElemType: types.StringType, + }, + "db_max_rows": types.Int64Type, + "db_schemas": basetypes.ListType{ + ElemType: types.StringType, + }, + "jwt_cache_max_lifetime": timetypes.GoDuration{}.Type(ctx), + "jwt_role_claim_key": types.StringType, + "openapi_mode": types.StringType, + "server_cors_allowed_origins": basetypes.ListType{ + ElemType: types.StringType, + }, + "server_timing_enabled": types.BoolType, + }, + } +} + +// GetDbExtraSearchPath returns the value of the DbExtraSearchPath field in DataApiDataApiSpec as +// a slice of types.String values. +// If the field is unknown or null, the boolean return value is false. +func (m *DataApiDataApiSpec) GetDbExtraSearchPath(ctx context.Context) ([]types.String, bool) { + if m.DbExtraSearchPath.IsNull() || m.DbExtraSearchPath.IsUnknown() { + return nil, false + } + var v []types.String + d := m.DbExtraSearchPath.ElementsAs(ctx, &v, true) + if d.HasError() { + panic(pluginfwcommon.DiagToString(d)) + } + return v, true +} + +// SetDbExtraSearchPath sets the value of the DbExtraSearchPath field in DataApiDataApiSpec. +func (m *DataApiDataApiSpec) SetDbExtraSearchPath(ctx context.Context, v []types.String) { + vs := make([]attr.Value, 0, len(v)) + for _, e := range v { + vs = append(vs, e) + } + t := m.Type(ctx).(basetypes.ObjectType).AttrTypes["db_extra_search_path"] + t = t.(attr.TypeWithElementType).ElementType() + m.DbExtraSearchPath = types.ListValueMust(t, vs) +} + +// GetDbSchemas returns the value of the DbSchemas field in DataApiDataApiSpec as +// a slice of types.String values. +// If the field is unknown or null, the boolean return value is false. +func (m *DataApiDataApiSpec) GetDbSchemas(ctx context.Context) ([]types.String, bool) { + if m.DbSchemas.IsNull() || m.DbSchemas.IsUnknown() { + return nil, false + } + var v []types.String + d := m.DbSchemas.ElementsAs(ctx, &v, true) + if d.HasError() { + panic(pluginfwcommon.DiagToString(d)) + } + return v, true +} + +// SetDbSchemas sets the value of the DbSchemas field in DataApiDataApiSpec. +func (m *DataApiDataApiSpec) SetDbSchemas(ctx context.Context, v []types.String) { + vs := make([]attr.Value, 0, len(v)) + for _, e := range v { + vs = append(vs, e) + } + t := m.Type(ctx).(basetypes.ObjectType).AttrTypes["db_schemas"] + t = t.(attr.TypeWithElementType).ElementType() + m.DbSchemas = types.ListValueMust(t, vs) +} + +// GetServerCorsAllowedOrigins returns the value of the ServerCorsAllowedOrigins field in DataApiDataApiSpec as +// a slice of types.String values. +// If the field is unknown or null, the boolean return value is false. +func (m *DataApiDataApiSpec) GetServerCorsAllowedOrigins(ctx context.Context) ([]types.String, bool) { + if m.ServerCorsAllowedOrigins.IsNull() || m.ServerCorsAllowedOrigins.IsUnknown() { + return nil, false + } + var v []types.String + d := m.ServerCorsAllowedOrigins.ElementsAs(ctx, &v, true) + if d.HasError() { + panic(pluginfwcommon.DiagToString(d)) + } + return v, true +} + +// SetServerCorsAllowedOrigins sets the value of the ServerCorsAllowedOrigins field in DataApiDataApiSpec. +func (m *DataApiDataApiSpec) SetServerCorsAllowedOrigins(ctx context.Context, v []types.String) { + vs := make([]attr.Value, 0, len(v)) + for _, e := range v { + vs = append(vs, e) + } + t := m.Type(ctx).(basetypes.ObjectType).AttrTypes["server_cors_allowed_origins"] + t = t.(attr.TypeWithElementType).ElementType() + m.ServerCorsAllowedOrigins = types.ListValueMust(t, vs) +} + +// Observed state (output-only). +type DataApiDataApiStatus struct { + // Schemas available in the database (for reference when configuring + // db_schemas). + AvailableSchemas types.List `tfsdk:"available_schemas"` + // Actual aggregate function setting read from the database. + DbAggregatesEnabled types.Bool `tfsdk:"db_aggregates_enabled"` + // Actual extra search path schemas read from the database. + DbExtraSearchPath types.List `tfsdk:"db_extra_search_path"` + // Actual max rows setting read from the database. + DbMaxRows types.Int64 `tfsdk:"db_max_rows"` + // Actual exposed schemas read from the database. + DbSchemas types.List `tfsdk:"db_schemas"` + // Actual JWT cache max lifetime read from the database. + JwtCacheMaxLifetime timetypes.GoDuration `tfsdk:"jwt_cache_max_lifetime"` + // Actual JWT role claim key read from the database. + JwtRoleClaimKey types.String `tfsdk:"jwt_role_claim_key"` + // Actual OpenAPI mode read from the database. + OpenapiMode types.String `tfsdk:"openapi_mode"` + // Actual CORS allowed origins read from the database. + ServerCorsAllowedOrigins types.List `tfsdk:"server_cors_allowed_origins"` + // Actual Server-Timing header setting read from the database. + ServerTimingEnabled types.Bool `tfsdk:"server_timing_enabled"` + // Data API endpoint URL. + Url types.String `tfsdk:"url"` +} + +func (to *DataApiDataApiStatus) SyncFieldsDuringCreateOrUpdate(ctx context.Context, from DataApiDataApiStatus) { + if !from.AvailableSchemas.IsNull() && !from.AvailableSchemas.IsUnknown() && to.AvailableSchemas.IsNull() && len(from.AvailableSchemas.Elements()) == 0 { + // The default representation of an empty list for TF autogenerated resources in the resource state is Null. + // If a user specified a non-Null, empty list for AvailableSchemas, and the deserialized field value is Null, + // set the resulting resource state to the empty list to match the planned value. + to.AvailableSchemas = from.AvailableSchemas + } + if !from.DbExtraSearchPath.IsNull() && !from.DbExtraSearchPath.IsUnknown() && to.DbExtraSearchPath.IsNull() && len(from.DbExtraSearchPath.Elements()) == 0 { + // The default representation of an empty list for TF autogenerated resources in the resource state is Null. + // If a user specified a non-Null, empty list for DbExtraSearchPath, and the deserialized field value is Null, + // set the resulting resource state to the empty list to match the planned value. + to.DbExtraSearchPath = from.DbExtraSearchPath + } + if !from.DbSchemas.IsNull() && !from.DbSchemas.IsUnknown() && to.DbSchemas.IsNull() && len(from.DbSchemas.Elements()) == 0 { + // The default representation of an empty list for TF autogenerated resources in the resource state is Null. + // If a user specified a non-Null, empty list for DbSchemas, and the deserialized field value is Null, + // set the resulting resource state to the empty list to match the planned value. + to.DbSchemas = from.DbSchemas + } + if !from.ServerCorsAllowedOrigins.IsNull() && !from.ServerCorsAllowedOrigins.IsUnknown() && to.ServerCorsAllowedOrigins.IsNull() && len(from.ServerCorsAllowedOrigins.Elements()) == 0 { + // The default representation of an empty list for TF autogenerated resources in the resource state is Null. + // If a user specified a non-Null, empty list for ServerCorsAllowedOrigins, and the deserialized field value is Null, + // set the resulting resource state to the empty list to match the planned value. + to.ServerCorsAllowedOrigins = from.ServerCorsAllowedOrigins + } +} + +func (to *DataApiDataApiStatus) SyncFieldsDuringRead(ctx context.Context, from DataApiDataApiStatus) { + if !from.AvailableSchemas.IsNull() && !from.AvailableSchemas.IsUnknown() && to.AvailableSchemas.IsNull() && len(from.AvailableSchemas.Elements()) == 0 { + // The default representation of an empty list for TF autogenerated resources in the resource state is Null. + // If a user specified a non-Null, empty list for AvailableSchemas, and the deserialized field value is Null, + // set the resulting resource state to the empty list to match the planned value. + to.AvailableSchemas = from.AvailableSchemas + } + if !from.DbExtraSearchPath.IsNull() && !from.DbExtraSearchPath.IsUnknown() && to.DbExtraSearchPath.IsNull() && len(from.DbExtraSearchPath.Elements()) == 0 { + // The default representation of an empty list for TF autogenerated resources in the resource state is Null. + // If a user specified a non-Null, empty list for DbExtraSearchPath, and the deserialized field value is Null, + // set the resulting resource state to the empty list to match the planned value. + to.DbExtraSearchPath = from.DbExtraSearchPath + } + if !from.DbSchemas.IsNull() && !from.DbSchemas.IsUnknown() && to.DbSchemas.IsNull() && len(from.DbSchemas.Elements()) == 0 { + // The default representation of an empty list for TF autogenerated resources in the resource state is Null. + // If a user specified a non-Null, empty list for DbSchemas, and the deserialized field value is Null, + // set the resulting resource state to the empty list to match the planned value. + to.DbSchemas = from.DbSchemas + } + if !from.ServerCorsAllowedOrigins.IsNull() && !from.ServerCorsAllowedOrigins.IsUnknown() && to.ServerCorsAllowedOrigins.IsNull() && len(from.ServerCorsAllowedOrigins.Elements()) == 0 { + // The default representation of an empty list for TF autogenerated resources in the resource state is Null. + // If a user specified a non-Null, empty list for ServerCorsAllowedOrigins, and the deserialized field value is Null, + // set the resulting resource state to the empty list to match the planned value. + to.ServerCorsAllowedOrigins = from.ServerCorsAllowedOrigins + } +} + +func (m DataApiDataApiStatus) ApplySchemaCustomizations(attrs map[string]tfschema.AttributeBuilder) map[string]tfschema.AttributeBuilder { + attrs["available_schemas"] = attrs["available_schemas"].SetComputed() + attrs["db_aggregates_enabled"] = attrs["db_aggregates_enabled"].SetComputed() + attrs["db_extra_search_path"] = attrs["db_extra_search_path"].SetComputed() + attrs["db_max_rows"] = attrs["db_max_rows"].SetComputed() + attrs["db_schemas"] = attrs["db_schemas"].SetComputed() + attrs["jwt_cache_max_lifetime"] = attrs["jwt_cache_max_lifetime"].SetComputed() + attrs["jwt_role_claim_key"] = attrs["jwt_role_claim_key"].SetComputed() + attrs["openapi_mode"] = attrs["openapi_mode"].SetComputed() + attrs["server_cors_allowed_origins"] = attrs["server_cors_allowed_origins"].SetComputed() + attrs["server_timing_enabled"] = attrs["server_timing_enabled"].SetComputed() + attrs["url"] = attrs["url"].SetComputed() + + return attrs +} + +// GetComplexFieldTypes returns a map of the types of elements in complex fields in DataApiDataApiStatus. +// Container types (types.Map, types.List, types.Set) and object types (types.Object) do not carry +// the type information of their elements in the Go type system. This function provides a way to +// retrieve the type information of the elements in complex fields at runtime. The values of the map +// are the reflected types of the contained elements. They must be either primitive values from the +// plugin framework type system (types.String{}, types.Bool{}, types.Int64{}, types.Float64{}) or TF +// SDK values. +func (m DataApiDataApiStatus) GetComplexFieldTypes(ctx context.Context) map[string]reflect.Type { + return map[string]reflect.Type{ + "available_schemas": reflect.TypeOf(types.String{}), + "db_extra_search_path": reflect.TypeOf(types.String{}), + "db_schemas": reflect.TypeOf(types.String{}), + "server_cors_allowed_origins": reflect.TypeOf(types.String{}), + } +} + +// TFSDK types cannot implement the ObjectValuable interface directly, as it would otherwise +// interfere with how the plugin framework retrieves and sets values in state. Thus, DataApiDataApiStatus +// only implements ToObjectValue() and Type(). +func (m DataApiDataApiStatus) ToObjectValue(ctx context.Context) basetypes.ObjectValue { + return types.ObjectValueMust( + m.Type(ctx).(basetypes.ObjectType).AttrTypes, + map[string]attr.Value{ + "available_schemas": m.AvailableSchemas, + "db_aggregates_enabled": m.DbAggregatesEnabled, + "db_extra_search_path": m.DbExtraSearchPath, + "db_max_rows": m.DbMaxRows, + "db_schemas": m.DbSchemas, + "jwt_cache_max_lifetime": m.JwtCacheMaxLifetime, + "jwt_role_claim_key": m.JwtRoleClaimKey, + "openapi_mode": m.OpenapiMode, + "server_cors_allowed_origins": m.ServerCorsAllowedOrigins, + "server_timing_enabled": m.ServerTimingEnabled, + "url": m.Url, + }) +} + +// Type implements basetypes.ObjectValuable. +func (m DataApiDataApiStatus) Type(ctx context.Context) attr.Type { + return types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "available_schemas": basetypes.ListType{ + ElemType: types.StringType, + }, + "db_aggregates_enabled": types.BoolType, + "db_extra_search_path": basetypes.ListType{ + ElemType: types.StringType, + }, + "db_max_rows": types.Int64Type, + "db_schemas": basetypes.ListType{ + ElemType: types.StringType, + }, + "jwt_cache_max_lifetime": timetypes.GoDuration{}.Type(ctx), + "jwt_role_claim_key": types.StringType, + "openapi_mode": types.StringType, + "server_cors_allowed_origins": basetypes.ListType{ + ElemType: types.StringType, + }, + "server_timing_enabled": types.BoolType, + "url": types.StringType, + }, + } +} + +// GetAvailableSchemas returns the value of the AvailableSchemas field in DataApiDataApiStatus as +// a slice of types.String values. +// If the field is unknown or null, the boolean return value is false. +func (m *DataApiDataApiStatus) GetAvailableSchemas(ctx context.Context) ([]types.String, bool) { + if m.AvailableSchemas.IsNull() || m.AvailableSchemas.IsUnknown() { + return nil, false + } + var v []types.String + d := m.AvailableSchemas.ElementsAs(ctx, &v, true) + if d.HasError() { + panic(pluginfwcommon.DiagToString(d)) + } + return v, true +} + +// SetAvailableSchemas sets the value of the AvailableSchemas field in DataApiDataApiStatus. +func (m *DataApiDataApiStatus) SetAvailableSchemas(ctx context.Context, v []types.String) { + vs := make([]attr.Value, 0, len(v)) + for _, e := range v { + vs = append(vs, e) + } + t := m.Type(ctx).(basetypes.ObjectType).AttrTypes["available_schemas"] + t = t.(attr.TypeWithElementType).ElementType() + m.AvailableSchemas = types.ListValueMust(t, vs) +} + +// GetDbExtraSearchPath returns the value of the DbExtraSearchPath field in DataApiDataApiStatus as +// a slice of types.String values. +// If the field is unknown or null, the boolean return value is false. +func (m *DataApiDataApiStatus) GetDbExtraSearchPath(ctx context.Context) ([]types.String, bool) { + if m.DbExtraSearchPath.IsNull() || m.DbExtraSearchPath.IsUnknown() { + return nil, false + } + var v []types.String + d := m.DbExtraSearchPath.ElementsAs(ctx, &v, true) + if d.HasError() { + panic(pluginfwcommon.DiagToString(d)) + } + return v, true +} + +// SetDbExtraSearchPath sets the value of the DbExtraSearchPath field in DataApiDataApiStatus. +func (m *DataApiDataApiStatus) SetDbExtraSearchPath(ctx context.Context, v []types.String) { + vs := make([]attr.Value, 0, len(v)) + for _, e := range v { + vs = append(vs, e) + } + t := m.Type(ctx).(basetypes.ObjectType).AttrTypes["db_extra_search_path"] + t = t.(attr.TypeWithElementType).ElementType() + m.DbExtraSearchPath = types.ListValueMust(t, vs) +} + +// GetDbSchemas returns the value of the DbSchemas field in DataApiDataApiStatus as +// a slice of types.String values. +// If the field is unknown or null, the boolean return value is false. +func (m *DataApiDataApiStatus) GetDbSchemas(ctx context.Context) ([]types.String, bool) { + if m.DbSchemas.IsNull() || m.DbSchemas.IsUnknown() { + return nil, false + } + var v []types.String + d := m.DbSchemas.ElementsAs(ctx, &v, true) + if d.HasError() { + panic(pluginfwcommon.DiagToString(d)) + } + return v, true +} + +// SetDbSchemas sets the value of the DbSchemas field in DataApiDataApiStatus. +func (m *DataApiDataApiStatus) SetDbSchemas(ctx context.Context, v []types.String) { + vs := make([]attr.Value, 0, len(v)) + for _, e := range v { + vs = append(vs, e) + } + t := m.Type(ctx).(basetypes.ObjectType).AttrTypes["db_schemas"] + t = t.(attr.TypeWithElementType).ElementType() + m.DbSchemas = types.ListValueMust(t, vs) +} + +// GetServerCorsAllowedOrigins returns the value of the ServerCorsAllowedOrigins field in DataApiDataApiStatus as +// a slice of types.String values. // If the field is unknown or null, the boolean return value is false. -func (m *CreateRoleRequest) GetRole(ctx context.Context) (Role, bool) { - var e Role - if m.Role.IsNull() || m.Role.IsUnknown() { - return e, false +func (m *DataApiDataApiStatus) GetServerCorsAllowedOrigins(ctx context.Context) ([]types.String, bool) { + if m.ServerCorsAllowedOrigins.IsNull() || m.ServerCorsAllowedOrigins.IsUnknown() { + return nil, false } - var v Role - d := m.Role.As(ctx, &v, basetypes.ObjectAsOptions{ - UnhandledNullAsEmpty: true, - UnhandledUnknownAsEmpty: true, - }) + var v []types.String + d := m.ServerCorsAllowedOrigins.ElementsAs(ctx, &v, true) if d.HasError() { panic(pluginfwcommon.DiagToString(d)) } return v, true } -// SetRole sets the value of the Role field in CreateRoleRequest. -func (m *CreateRoleRequest) SetRole(ctx context.Context, v Role) { - vs := v.ToObjectValue(ctx) - m.Role = vs +// SetServerCorsAllowedOrigins sets the value of the ServerCorsAllowedOrigins field in DataApiDataApiStatus. +func (m *DataApiDataApiStatus) SetServerCorsAllowedOrigins(ctx context.Context, v []types.String) { + vs := make([]attr.Value, 0, len(v)) + for _, e := range v { + vs = append(vs, e) + } + t := m.Type(ctx).(basetypes.ObjectType).AttrTypes["server_cors_allowed_origins"] + t = t.(attr.TypeWithElementType).ElementType() + m.ServerCorsAllowedOrigins = types.ListValueMust(t, vs) } -type CreateSyncedTableRequest struct { - SyncedTable types.Object `tfsdk:"synced_table"` - // The ID to use for the Synced Table. This becomes the final component of - // the SyncedTable's resource name. ID is required and is the synced table - // name, containing (catalog, schema, table) tuple. Elements of the tuple - // are the UC entity names. - // - // Example: "{catalog}.{schema}.{table}" - // - // synced_table_id represents both of the following: - // - // 1. An online VIEW virtual table in the Unity Catalog accessible via the - // Lakehouse Federation. 2. Postgres table named "{table}" in schema - // "{schema}" in the connected Postgres database - SyncedTableId types.String `tfsdk:"-"` +type DataApiOperationMetadata struct { } -func (to *CreateSyncedTableRequest) SyncFieldsDuringCreateOrUpdate(ctx context.Context, from CreateSyncedTableRequest) { - if !from.SyncedTable.IsNull() && !from.SyncedTable.IsUnknown() { - if toSyncedTable, ok := to.GetSyncedTable(ctx); ok { - if fromSyncedTable, ok := from.GetSyncedTable(ctx); ok { - // Recursively sync the fields of SyncedTable - toSyncedTable.SyncFieldsDuringCreateOrUpdate(ctx, fromSyncedTable) - to.SetSyncedTable(ctx, toSyncedTable) - } - } - } +func (to *DataApiOperationMetadata) SyncFieldsDuringCreateOrUpdate(ctx context.Context, from DataApiOperationMetadata) { } -func (to *CreateSyncedTableRequest) SyncFieldsDuringRead(ctx context.Context, from CreateSyncedTableRequest) { - if !from.SyncedTable.IsNull() && !from.SyncedTable.IsUnknown() { - if toSyncedTable, ok := to.GetSyncedTable(ctx); ok { - if fromSyncedTable, ok := from.GetSyncedTable(ctx); ok { - toSyncedTable.SyncFieldsDuringRead(ctx, fromSyncedTable) - to.SetSyncedTable(ctx, toSyncedTable) - } - } - } +func (to *DataApiOperationMetadata) SyncFieldsDuringRead(ctx context.Context, from DataApiOperationMetadata) { } -func (m CreateSyncedTableRequest) ApplySchemaCustomizations(attrs map[string]tfschema.AttributeBuilder) map[string]tfschema.AttributeBuilder { - attrs["synced_table"] = attrs["synced_table"].SetRequired() - attrs["synced_table_id"] = attrs["synced_table_id"].SetRequired() +func (m DataApiOperationMetadata) ApplySchemaCustomizations(attrs map[string]tfschema.AttributeBuilder) map[string]tfschema.AttributeBuilder { return attrs } -// GetComplexFieldTypes returns a map of the types of elements in complex fields in CreateSyncedTableRequest. +// GetComplexFieldTypes returns a map of the types of elements in complex fields in DataApiOperationMetadata. // Container types (types.Map, types.List, types.Set) and object types (types.Object) do not carry // the type information of their elements in the Go type system. This function provides a way to // retrieve the type information of the elements in complex fields at runtime. The values of the map // are the reflected types of the contained elements. They must be either primitive values from the // plugin framework type system (types.String{}, types.Bool{}, types.Int64{}, types.Float64{}) or TF // SDK values. -func (m CreateSyncedTableRequest) GetComplexFieldTypes(ctx context.Context) map[string]reflect.Type { - return map[string]reflect.Type{ - "synced_table": reflect.TypeOf(SyncedTable{}), - } +func (m DataApiOperationMetadata) GetComplexFieldTypes(ctx context.Context) map[string]reflect.Type { + return map[string]reflect.Type{} } // TFSDK types cannot implement the ObjectValuable interface directly, as it would otherwise -// interfere with how the plugin framework retrieves and sets values in state. Thus, CreateSyncedTableRequest +// interfere with how the plugin framework retrieves and sets values in state. Thus, DataApiOperationMetadata // only implements ToObjectValue() and Type(). -func (m CreateSyncedTableRequest) ToObjectValue(ctx context.Context) basetypes.ObjectValue { +func (m DataApiOperationMetadata) ToObjectValue(ctx context.Context) basetypes.ObjectValue { return types.ObjectValueMust( m.Type(ctx).(basetypes.ObjectType).AttrTypes, - map[string]attr.Value{ - "synced_table": m.SyncedTable, - "synced_table_id": m.SyncedTableId, - }) + map[string]attr.Value{}) } // Type implements basetypes.ObjectValuable. -func (m CreateSyncedTableRequest) Type(ctx context.Context) attr.Type { +func (m DataApiOperationMetadata) Type(ctx context.Context) attr.Type { return types.ObjectType{ - AttrTypes: map[string]attr.Type{ - "synced_table": SyncedTable{}.Type(ctx), - "synced_table_id": types.StringType, - }, - } -} - -// GetSyncedTable returns the value of the SyncedTable field in CreateSyncedTableRequest as -// a SyncedTable value. -// If the field is unknown or null, the boolean return value is false. -func (m *CreateSyncedTableRequest) GetSyncedTable(ctx context.Context) (SyncedTable, bool) { - var e SyncedTable - if m.SyncedTable.IsNull() || m.SyncedTable.IsUnknown() { - return e, false - } - var v SyncedTable - d := m.SyncedTable.As(ctx, &v, basetypes.ObjectAsOptions{ - UnhandledNullAsEmpty: true, - UnhandledUnknownAsEmpty: true, - }) - if d.HasError() { - panic(pluginfwcommon.DiagToString(d)) + AttrTypes: map[string]attr.Type{}, } - return v, true -} - -// SetSyncedTable sets the value of the SyncedTable field in CreateSyncedTableRequest. -func (m *CreateSyncedTableRequest) SetSyncedTable(ctx context.Context, v SyncedTable) { - vs := v.ToObjectValue(ctx) - m.SyncedTable = vs } // Database represents a Postgres database within a Branch. @@ -2207,6 +3005,55 @@ func (m DeleteCatalogRequest) Type(ctx context.Context) attr.Type { } } +type DeleteDataApiRequest struct { + // Resource name: + // projects/{project_id}/branches/{branch_id}/databases/{database_id}/data-api + Name types.String `tfsdk:"-"` +} + +func (to *DeleteDataApiRequest) SyncFieldsDuringCreateOrUpdate(ctx context.Context, from DeleteDataApiRequest) { +} + +func (to *DeleteDataApiRequest) SyncFieldsDuringRead(ctx context.Context, from DeleteDataApiRequest) { +} + +func (m DeleteDataApiRequest) ApplySchemaCustomizations(attrs map[string]tfschema.AttributeBuilder) map[string]tfschema.AttributeBuilder { + attrs["name"] = attrs["name"].SetRequired() + + return attrs +} + +// GetComplexFieldTypes returns a map of the types of elements in complex fields in DeleteDataApiRequest. +// Container types (types.Map, types.List, types.Set) and object types (types.Object) do not carry +// the type information of their elements in the Go type system. This function provides a way to +// retrieve the type information of the elements in complex fields at runtime. The values of the map +// are the reflected types of the contained elements. They must be either primitive values from the +// plugin framework type system (types.String{}, types.Bool{}, types.Int64{}, types.Float64{}) or TF +// SDK values. +func (m DeleteDataApiRequest) GetComplexFieldTypes(ctx context.Context) map[string]reflect.Type { + return map[string]reflect.Type{} +} + +// TFSDK types cannot implement the ObjectValuable interface directly, as it would otherwise +// interfere with how the plugin framework retrieves and sets values in state. Thus, DeleteDataApiRequest +// only implements ToObjectValue() and Type(). +func (m DeleteDataApiRequest) ToObjectValue(ctx context.Context) basetypes.ObjectValue { + return types.ObjectValueMust( + m.Type(ctx).(basetypes.ObjectType).AttrTypes, + map[string]attr.Value{ + "name": m.Name, + }) +} + +// Type implements basetypes.ObjectValuable. +func (m DeleteDataApiRequest) Type(ctx context.Context) attr.Type { + return types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "name": types.StringType, + }, + } +} + type DeleteDatabaseRequest struct { // The resource name of the postgres database. Format: // projects/{project_id}/branches/{branch_id}/databases/{database_id} @@ -3626,6 +4473,55 @@ func (m GetCatalogRequest) Type(ctx context.Context) attr.Type { } } +type GetDataApiRequest struct { + // Resource name: + // projects/{project_id}/branches/{branch_id}/databases/{database_id}/data-api + Name types.String `tfsdk:"-"` +} + +func (to *GetDataApiRequest) SyncFieldsDuringCreateOrUpdate(ctx context.Context, from GetDataApiRequest) { +} + +func (to *GetDataApiRequest) SyncFieldsDuringRead(ctx context.Context, from GetDataApiRequest) { +} + +func (m GetDataApiRequest) ApplySchemaCustomizations(attrs map[string]tfschema.AttributeBuilder) map[string]tfschema.AttributeBuilder { + attrs["name"] = attrs["name"].SetRequired() + + return attrs +} + +// GetComplexFieldTypes returns a map of the types of elements in complex fields in GetDataApiRequest. +// Container types (types.Map, types.List, types.Set) and object types (types.Object) do not carry +// the type information of their elements in the Go type system. This function provides a way to +// retrieve the type information of the elements in complex fields at runtime. The values of the map +// are the reflected types of the contained elements. They must be either primitive values from the +// plugin framework type system (types.String{}, types.Bool{}, types.Int64{}, types.Float64{}) or TF +// SDK values. +func (m GetDataApiRequest) GetComplexFieldTypes(ctx context.Context) map[string]reflect.Type { + return map[string]reflect.Type{} +} + +// TFSDK types cannot implement the ObjectValuable interface directly, as it would otherwise +// interfere with how the plugin framework retrieves and sets values in state. Thus, GetDataApiRequest +// only implements ToObjectValue() and Type(). +func (m GetDataApiRequest) ToObjectValue(ctx context.Context) basetypes.ObjectValue { + return types.ObjectValueMust( + m.Type(ctx).(basetypes.ObjectType).AttrTypes, + map[string]attr.Value{ + "name": m.Name, + }) +} + +// Type implements basetypes.ObjectValuable. +func (m GetDataApiRequest) Type(ctx context.Context) attr.Type { + return types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "name": types.StringType, + }, + } +} + type GetDatabaseRequest struct { // The name of the Database to retrieve. Format: // projects/{project_id}/branches/{branch_id}/databases/{database_id} @@ -7682,6 +8578,111 @@ func (m *UpdateBranchRequest) SetBranch(ctx context.Context, v Branch) { m.Branch = vs } +type UpdateDataApiRequest struct { + // The Data API configuration to update. The data_api's `name` field + // identifies the resource. + DataApi types.Object `tfsdk:"data_api"` + // Resource name: + // projects/{project_id}/branches/{branch_id}/databases/{database_id}/data-api + Name types.String `tfsdk:"-"` + // The list of fields to update. If unspecified, all fields will be updated + // when possible. + UpdateMask types.String `tfsdk:"-"` +} + +func (to *UpdateDataApiRequest) SyncFieldsDuringCreateOrUpdate(ctx context.Context, from UpdateDataApiRequest) { + if !from.DataApi.IsNull() && !from.DataApi.IsUnknown() { + if toDataApi, ok := to.GetDataApi(ctx); ok { + if fromDataApi, ok := from.GetDataApi(ctx); ok { + // Recursively sync the fields of DataApi + toDataApi.SyncFieldsDuringCreateOrUpdate(ctx, fromDataApi) + to.SetDataApi(ctx, toDataApi) + } + } + } +} + +func (to *UpdateDataApiRequest) SyncFieldsDuringRead(ctx context.Context, from UpdateDataApiRequest) { + if !from.DataApi.IsNull() && !from.DataApi.IsUnknown() { + if toDataApi, ok := to.GetDataApi(ctx); ok { + if fromDataApi, ok := from.GetDataApi(ctx); ok { + toDataApi.SyncFieldsDuringRead(ctx, fromDataApi) + to.SetDataApi(ctx, toDataApi) + } + } + } +} + +func (m UpdateDataApiRequest) ApplySchemaCustomizations(attrs map[string]tfschema.AttributeBuilder) map[string]tfschema.AttributeBuilder { + attrs["data_api"] = attrs["data_api"].SetRequired() + attrs["name"] = attrs["name"].SetRequired() + attrs["update_mask"] = attrs["update_mask"].SetRequired() + + return attrs +} + +// GetComplexFieldTypes returns a map of the types of elements in complex fields in UpdateDataApiRequest. +// Container types (types.Map, types.List, types.Set) and object types (types.Object) do not carry +// the type information of their elements in the Go type system. This function provides a way to +// retrieve the type information of the elements in complex fields at runtime. The values of the map +// are the reflected types of the contained elements. They must be either primitive values from the +// plugin framework type system (types.String{}, types.Bool{}, types.Int64{}, types.Float64{}) or TF +// SDK values. +func (m UpdateDataApiRequest) GetComplexFieldTypes(ctx context.Context) map[string]reflect.Type { + return map[string]reflect.Type{ + "data_api": reflect.TypeOf(DataApi{}), + } +} + +// TFSDK types cannot implement the ObjectValuable interface directly, as it would otherwise +// interfere with how the plugin framework retrieves and sets values in state. Thus, UpdateDataApiRequest +// only implements ToObjectValue() and Type(). +func (m UpdateDataApiRequest) ToObjectValue(ctx context.Context) basetypes.ObjectValue { + return types.ObjectValueMust( + m.Type(ctx).(basetypes.ObjectType).AttrTypes, + map[string]attr.Value{ + "data_api": m.DataApi, + "name": m.Name, + "update_mask": m.UpdateMask, + }) +} + +// Type implements basetypes.ObjectValuable. +func (m UpdateDataApiRequest) Type(ctx context.Context) attr.Type { + return types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "data_api": DataApi{}.Type(ctx), + "name": types.StringType, + "update_mask": types.StringType, + }, + } +} + +// GetDataApi returns the value of the DataApi field in UpdateDataApiRequest as +// a DataApi value. +// If the field is unknown or null, the boolean return value is false. +func (m *UpdateDataApiRequest) GetDataApi(ctx context.Context) (DataApi, bool) { + var e DataApi + if m.DataApi.IsNull() || m.DataApi.IsUnknown() { + return e, false + } + var v DataApi + d := m.DataApi.As(ctx, &v, basetypes.ObjectAsOptions{ + UnhandledNullAsEmpty: true, + UnhandledUnknownAsEmpty: true, + }) + if d.HasError() { + panic(pluginfwcommon.DiagToString(d)) + } + return v, true +} + +// SetDataApi sets the value of the DataApi field in UpdateDataApiRequest. +func (m *UpdateDataApiRequest) SetDataApi(ctx context.Context, v DataApi) { + vs := v.ToObjectValue(ctx) + m.DataApi = vs +} + type UpdateDatabaseRequest struct { // The Database to update. // diff --git a/internal/service/settings_tf/legacy_model.go b/internal/service/settings_tf/legacy_model.go index 4f4b1359c3..15459751b6 100755 --- a/internal/service/settings_tf/legacy_model.go +++ b/internal/service/settings_tf/legacy_model.go @@ -3589,6 +3589,8 @@ func (m *CustomerFacingIngressNetworkPolicy_SdkV2) SetPublicAccess(ctx context.C m.PublicAccess = types.ListValueMust(t, vs) } +// Matches account-level Databricks API endpoints for an ingress network policy +// rule. type CustomerFacingIngressNetworkPolicyAccountApiDestination_SdkV2 struct { // Qualifies the breadth of API access for the listed scopes. See // ApiScopeQualifier. @@ -6016,6 +6018,8 @@ func (m *CustomerFacingIngressNetworkPolicyRequestDestination_SdkV2) SetWorkspac m.WorkspaceUi = types.ListValueMust(t, vs) } +// Matches workspace-level Databricks API endpoints for an ingress network +// policy rule. type CustomerFacingIngressNetworkPolicyWorkspaceApiDestination_SdkV2 struct { // Qualifies the breadth of API access for the listed scopes. See // ApiScopeQualifier. diff --git a/internal/service/settings_tf/model.go b/internal/service/settings_tf/model.go index 33fb6d2ec5..936eaf8522 100755 --- a/internal/service/settings_tf/model.go +++ b/internal/service/settings_tf/model.go @@ -3472,6 +3472,8 @@ func (m *CustomerFacingIngressNetworkPolicy) SetPublicAccess(ctx context.Context m.PublicAccess = vs } +// Matches account-level Databricks API endpoints for an ingress network policy +// rule. type CustomerFacingIngressNetworkPolicyAccountApiDestination struct { // Qualifies the breadth of API access for the listed scopes. See // ApiScopeQualifier. @@ -5819,6 +5821,8 @@ func (m *CustomerFacingIngressNetworkPolicyRequestDestination) SetWorkspaceUi(ct m.WorkspaceUi = vs } +// Matches workspace-level Databricks API endpoints for an ingress network +// policy rule. type CustomerFacingIngressNetworkPolicyWorkspaceApiDestination struct { // Qualifies the breadth of API access for the listed scopes. See // ApiScopeQualifier.