Skip to content

Commit

Permalink
feat(sql_database): onboard new resource/data-source (#277)
Browse files Browse the repository at this point in the history
# 📥 Pull Request

close #255

## ❓ What are you trying to address

Add new resource `fabric_sql_database`
Add new data-source `fabric_sql_database`
Add new data-source `fabric_sql_databases`
  • Loading branch information
DariuszPorowski authored Feb 28, 2025
1 parent 7bb751d commit 16fcf4d
Show file tree
Hide file tree
Showing 24 changed files with 960 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changes/unreleased/added-20250228-092631.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: added
body: Onboard new resource/data-source `fabric_sql_database`.
time: 2025-02-28T09:26:31.2402351-08:00
custom:
Issue: "255"
67 changes: 67 additions & 0 deletions docs/data-sources/sql_database.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "fabric_sql_database Data Source - terraform-provider-fabric"
subcategory: ""
description: |-
Get a Fabric SQL Database.
Use this data source to fetch a SQL Database https://learn.microsoft.com/fabric/database/sql/overview.
-> This item supports Service Principal authentication.
~> This data-source is in preview. To access it, you must explicitly enable the preview mode in the provider level configuration.
---

# fabric_sql_database (Data Source)

Get a Fabric SQL Database.

Use this data source to fetch a [SQL Database](https://learn.microsoft.com/fabric/database/sql/overview).

-> This item supports Service Principal authentication.

~> This data-source is in **preview**. To access it, you must explicitly enable the `preview` mode in the provider level configuration.

## Example Usage

```terraform
data "fabric_sql_database" "example_by_id" {
id = "11111111-1111-1111-1111-111111111111"
workspace_id = "00000000-0000-0000-0000-000000000000"
}
data "fabric_sql_database" "example_by_name" {
display_name = "example"
workspace_id = "00000000-0000-0000-0000-000000000000"
}
# This is an invalid data source
# Do not specify `id` and `display_name` in the same data source block
# data "fabric_sql_database" "example" {
# display_name = "example"
# id = "11111111-1111-1111-1111-111111111111"
# workspace_id = "00000000-0000-0000-0000-000000000000"
# }
```

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

### Required

- `workspace_id` (String) The Workspace ID.

### Optional

- `display_name` (String) The SQL Database display name.
- `id` (String) The SQL Database ID.
- `timeouts` (Attributes) (see [below for nested schema](#nestedatt--timeouts))

### Read-Only

- `description` (String) The SQL Database description.

<a id="nestedatt--timeouts"></a>

### Nested Schema for `timeouts`

Optional:

- `read` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours).
62 changes: 62 additions & 0 deletions docs/data-sources/sql_databases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "fabric_sql_databases Data Source - terraform-provider-fabric"
subcategory: ""
description: |-
List a Fabric SQL Databases.
Use this data source to list SQL Databases https://learn.microsoft.com/fabric/database/sql/overview.
-> This item supports Service Principal authentication.
~> This data-source is in preview. To access it, you must explicitly enable the preview mode in the provider level configuration.
---

# fabric_sql_databases (Data Source)

List a Fabric SQL Databases.

Use this data source to list [SQL Databases](https://learn.microsoft.com/fabric/database/sql/overview).

-> This item supports Service Principal authentication.

~> This data-source is in **preview**. To access it, you must explicitly enable the `preview` mode in the provider level configuration.

## Example Usage

```terraform
data "fabric_sql_databases" "example" {
workspace_id = "00000000-0000-0000-0000-000000000000"
}
```

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

### Required

- `workspace_id` (String) The Workspace ID.

### Optional

- `timeouts` (Attributes) (see [below for nested schema](#nestedatt--timeouts))

### Read-Only

- `values` (Attributes List) The list of SQL Databases. (see [below for nested schema](#nestedatt--values))

<a id="nestedatt--timeouts"></a>

### Nested Schema for `timeouts`

Optional:

- `read` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours).

<a id="nestedatt--values"></a>

### Nested Schema for `values`

Read-Only:

- `description` (String) The SQL Database description.
- `display_name` (String) The SQL Database display name.
- `id` (String) The SQL Database ID.
- `workspace_id` (String) The Workspace ID.
66 changes: 66 additions & 0 deletions docs/resources/sql_database.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "fabric_sql_database Resource - terraform-provider-fabric"
subcategory: ""
description: |-
Manage a Fabric SQL Database.
Use this resource to manage SQL Database https://learn.microsoft.com/fabric/database/sql/overview.
-> This item supports Service Principal authentication.
~> This resource is in preview. To access it, you must explicitly enable the preview mode in the provider level configuration.
---

# fabric_sql_database (Resource)

Manage a Fabric SQL Database.

Use this resource to manage [SQL Database](https://learn.microsoft.com/fabric/database/sql/overview).

-> This item supports Service Principal authentication.

~> This resource is in **preview**. To access it, you must explicitly enable the `preview` mode in the provider level configuration.

## Example Usage

```terraform
resource "fabric_sql_database" "example" {
display_name = "example"
workspace_id = "00000000-0000-0000-0000-000000000000"
}
```

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

### Required

- `display_name` (String) The SQL Database display name.
- `workspace_id` (String) The Workspace ID.

### Optional

- `description` (String) The SQL Database description.
- `timeouts` (Attributes) (see [below for nested schema](#nestedatt--timeouts))

### Read-Only

- `id` (String) The SQL Database ID.

<a id="nestedatt--timeouts"></a>

### Nested Schema for `timeouts`

Optional:

- `create` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours).
- `delete` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours). Setting a timeout for a Delete operation is only applicable if changes are saved into state before the destroy operation occurs.
- `read` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours). Read operations occur during any refresh or planning operation when refresh is enabled.
- `update` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours).

## Import

Import is supported using the following syntax:

```shell
# terraform import fabric_sql_database.example "<WorkspaceID>/<SQLDatabaseID>"
terraform import fabric_sql_database.example "00000000-0000-0000-0000-000000000000/11111111-1111-1111-1111-111111111111"
```
17 changes: 17 additions & 0 deletions examples/data-sources/fabric_sql_database/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
data "fabric_sql_database" "example_by_id" {
id = "11111111-1111-1111-1111-111111111111"
workspace_id = "00000000-0000-0000-0000-000000000000"
}

data "fabric_sql_database" "example_by_name" {
display_name = "example"
workspace_id = "00000000-0000-0000-0000-000000000000"
}

# This is an invalid data source
# Do not specify `id` and `display_name` in the same data source block
# data "fabric_sql_database" "example" {
# display_name = "example"
# id = "11111111-1111-1111-1111-111111111111"
# workspace_id = "00000000-0000-0000-0000-000000000000"
# }
7 changes: 7 additions & 0 deletions examples/data-sources/fabric_sql_database/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "example_by_id" {
value = data.fabric_sql_database.example_by_id
}

output "example_by_name" {
value = data.fabric_sql_database.example_by_name
}
11 changes: 11 additions & 0 deletions examples/data-sources/fabric_sql_database/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
terraform {
required_version = ">= 1.8, < 2.0"
required_providers {
fabric = {
source = "microsoft/fabric"
version = "0.0.0" # Check for the latest version on the Terraform Registry
}
}
}

provider "fabric" {}
3 changes: 3 additions & 0 deletions examples/data-sources/fabric_sql_databases/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "fabric_sql_databases" "example" {
workspace_id = "00000000-0000-0000-0000-000000000000"
}
3 changes: 3 additions & 0 deletions examples/data-sources/fabric_sql_databases/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "example" {
value = data.fabric_sql_databases.example
}
11 changes: 11 additions & 0 deletions examples/data-sources/fabric_sql_databases/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
terraform {
required_version = ">= 1.8, < 2.0"
required_providers {
fabric = {
source = "microsoft/fabric"
version = "0.0.0" # Check for the latest version on the Terraform Registry
}
}
}

provider "fabric" {}
2 changes: 2 additions & 0 deletions examples/resources/fabric_sql_database/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# terraform import fabric_sql_database.example "<WorkspaceID>/<SQLDatabaseID>"
terraform import fabric_sql_database.example "00000000-0000-0000-0000-000000000000/11111111-1111-1111-1111-111111111111"
3 changes: 3 additions & 0 deletions examples/resources/fabric_sql_database/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "example" {
value = resource.fabric_sql_database.example
}
11 changes: 11 additions & 0 deletions examples/resources/fabric_sql_database/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
terraform {
required_version = ">= 1.8, < 2.0"
required_providers {
fabric = {
source = "microsoft/fabric"
version = "0.0.0" # Check for the latest version on the Terraform Registry
}
}
}

provider "fabric" {}
4 changes: 4 additions & 0 deletions examples/resources/fabric_sql_database/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "fabric_sql_database" "example" {
display_name = "example"
workspace_id = "00000000-0000-0000-0000-000000000000"
}
4 changes: 4 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import (
"github.com/microsoft/terraform-provider-fabric/internal/services/semanticmodel"
"github.com/microsoft/terraform-provider-fabric/internal/services/spark"
"github.com/microsoft/terraform-provider-fabric/internal/services/sparkjobdefinition"
"github.com/microsoft/terraform-provider-fabric/internal/services/sqldatabase"
"github.com/microsoft/terraform-provider-fabric/internal/services/sqlendpoint"
"github.com/microsoft/terraform-provider-fabric/internal/services/warehouse"
"github.com/microsoft/terraform-provider-fabric/internal/services/workspace"
Expand Down Expand Up @@ -404,6 +405,7 @@ func (p *FabricProvider) Resources(ctx context.Context) []func() resource.Resour
spark.NewResourceSparkEnvironmentSettings,
spark.NewResourceSparkWorkspaceSettings,
sparkjobdefinition.NewResourceSparkJobDefinition,
sqldatabase.NewResourceSQLDatabase,
warehouse.NewResourceWarehouse,
workspace.NewResourceWorkspace,
workspace.NewResourceWorkspaceRoleAssignment,
Expand Down Expand Up @@ -459,6 +461,8 @@ func (p *FabricProvider) DataSources(ctx context.Context) []func() datasource.Da
spark.NewDataSourceSparkWorkspaceSettings,
sparkjobdefinition.NewDataSourceSparkJobDefinition,
sparkjobdefinition.NewDataSourceSparkJobDefinitions,
sqldatabase.NewDataSourceSQLDatabase,
sqldatabase.NewDataSourceSQLDatabases,
sqlendpoint.NewDataSourceSQLEndpoints,
warehouse.NewDataSourceWarehouse,
warehouse.NewDataSourceWarehouses,
Expand Down
21 changes: 21 additions & 0 deletions internal/services/sqldatabase/base.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation
// SPDX-License-Identifier: MPL-2.0

package sqldatabase

import (
fabcore "github.com/microsoft/fabric-sdk-go/fabric/core"

"github.com/microsoft/terraform-provider-fabric/internal/common"
)

const (
ItemName = "SQL Database"
ItemTFName = "sql_database"
ItemsName = "SQL Databases"
ItemsTFName = "sql_databases"
ItemType = fabcore.ItemTypeSQLDatabase
ItemDocsSPNSupport = common.DocsSPNSupported
ItemDocsURL = "https://learn.microsoft.com/fabric/database/sql/overview"
ItemPreview = true
)
14 changes: 14 additions & 0 deletions internal/services/sqldatabase/base_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) Microsoft Corporation
// SPDX-License-Identifier: MPL-2.0

package sqldatabase_test

import (
"github.com/microsoft/terraform-provider-fabric/internal/services/sqldatabase"
)

const (
itemTFName = sqldatabase.ItemTFName
itemsTFName = sqldatabase.ItemsTFName
itemType = sqldatabase.ItemType
)
25 changes: 25 additions & 0 deletions internal/services/sqldatabase/data_sql_database.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) Microsoft Corporation
// SPDX-License-Identifier: MPL-2.0

package sqldatabase

import (
"github.com/hashicorp/terraform-plugin-framework/datasource"

"github.com/microsoft/terraform-provider-fabric/internal/pkg/fabricitem"
)

func NewDataSourceSQLDatabase() datasource.DataSource {
config := fabricitem.DataSourceFabricItem{
Type: ItemType,
Name: ItemName,
TFName: ItemTFName,
MarkdownDescription: "Get a Fabric " + ItemName + ".\n\n" +
"Use this data source to fetch a [" + ItemName + "](" + ItemDocsURL + ").\n\n" +
ItemDocsSPNSupport,
IsDisplayNameUnique: true,
IsPreview: ItemPreview,
}

return fabricitem.NewDataSourceFabricItem(config)
}
Loading

0 comments on commit 16fcf4d

Please sign in to comment.