Skip to content

Commit

Permalink
docs: add missing examples for kql_database and ml_model (#258)
Browse files Browse the repository at this point in the history
# 📥 Pull Request

## ❓ What are you trying to address

- Add missing examples for `fabric_kql_database`
- Add missing examples for `fabric_ml_model`
- Misc: standardize pointers for model setters
  • Loading branch information
DariuszPorowski authored Feb 20, 2025
1 parent 6f5618d commit 0688b44
Show file tree
Hide file tree
Showing 36 changed files with 227 additions and 68 deletions.
5 changes: 5 additions & 0 deletions .changes/unreleased/changed-20250214-162024.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: changed
body: Added missing example for `fabric_ml_model` resource.
time: 2025-02-14T16:20:24.7564261+01:00
custom:
Issue: "258"
5 changes: 5 additions & 0 deletions .changes/unreleased/changed-20250214-162108.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: changed
body: Added missing example for `fabric_kql_database` resource/data-source.
time: 2025-02-14T16:21:08.4928042+01:00
custom:
Issue: "258"
21 changes: 21 additions & 0 deletions docs/data-sources/kql_database.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,37 @@ Use this data source to fetch a [KQL Database](https://learn.microsoft.com/fabri
## Example Usage

```terraform
# Get item details by id
data "fabric_kql_database" "example_by_id" {
id = "11111111-1111-1111-1111-111111111111"
workspace_id = "00000000-0000-0000-0000-000000000000"
}
# Get item details by name
data "fabric_kql_database" "example_by_name" {
display_name = "example"
workspace_id = "00000000-0000-0000-0000-000000000000"
}
# Get item details with definition
# Examples uses `id` but `display_name` can be used as well
data "fabric_kql_database" "example_definition" {
id = "11111111-1111-1111-1111-111111111111"
workspace_id = "00000000-0000-0000-0000-000000000000"
format = "Default"
output_definition = true
}
# Access the content of the definition with JSONPath expression
output "example_definition_content_jsonpath" {
value = provider::fabric::content_decode(data.fabric_kql_database.example_definition.definition["DatabaseProperties.json"].content, ".")
}
# Access the content of the definition as JSON object
output "example_definition_content_object" {
value = provider::fabric::content_decode(data.fabric_kql_database.example_definition.definition["DatabaseProperties.json"].content)
}
# This is an invalid data source
# Do not specify `id` and `display_name` in the same data source block
# data "fabric_kql_database" "example" {
Expand Down
12 changes: 6 additions & 6 deletions docs/data-sources/notebook.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ Use this data source to fetch a [Notebook](https://learn.microsoft.com/fabric/da
## Example Usage

```terraform
# Get item details by name
data "fabric_notebook" "example_by_name" {
display_name = "example"
workspace_id = "00000000-0000-0000-0000-000000000000"
}
# Get item details by id
data "fabric_notebook" "example_by_id" {
id = "11111111-1111-1111-1111-111111111111"
workspace_id = "00000000-0000-0000-0000-000000000000"
}
# Get item details by name
data "fabric_notebook" "example_by_name" {
display_name = "example"
workspace_id = "00000000-0000-0000-0000-000000000000"
}
# Get item details with definition
# Examples uses `id` but `display_name` can be used as well
data "fabric_notebook" "example_definition" {
Expand Down
39 changes: 35 additions & 4 deletions docs/resources/kql_database.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Use this resource to manage a [KQL Database](https://learn.microsoft.com/fabric/
## Example Usage

```terraform
# Example 1 - Create a ReadWrite KQL database
# Example 1 - Item with configuration, no definition - create a ReadWrite KQL database
resource "fabric_kql_database" "example1" {
display_name = "example1"
workspace_id = "00000000-0000-0000-0000-000000000000"
Expand All @@ -30,7 +30,7 @@ resource "fabric_kql_database" "example1" {
}
}
# Example 2 - Create a Shortcut KQL database to source Azure Data Explorer cluster
# Example 2 - Item with configuration, no definition - create a Shortcut KQL database to source Azure Data Explorer cluster
resource "fabric_kql_database" "example2" {
display_name = "example2"
workspace_id = "00000000-0000-0000-0000-000000000000"
Expand All @@ -43,7 +43,7 @@ resource "fabric_kql_database" "example2" {
}
}
# Example 3 - Create a Shortcut KQL database to source Azure Data Explorer cluster with invitation token
# Example 3 - Item with configuration, no definition - create a Shortcut KQL database to source Azure Data Explorer cluster with invitation token
resource "fabric_kql_database" "example3" {
display_name = "example3"
workspace_id = "00000000-0000-0000-0000-000000000000"
Expand All @@ -55,7 +55,7 @@ resource "fabric_kql_database" "example3" {
}
}
# Example 4 - Create a Shortcut KQL database to source KQL database
# Example 4 - Item with configuration, no definition - create a Shortcut KQL database to source KQL database
resource "fabric_kql_database" "example4" {
display_name = "example4"
workspace_id = "00000000-0000-0000-0000-000000000000"
Expand All @@ -66,6 +66,37 @@ resource "fabric_kql_database" "example4" {
source_database_name = "MyDatabase"
}
}
# Example 5 - Item with definition bootstrapping only
resource "fabric_kql_database" "example5" {
display_name = "example5"
description = "example with definition bootstrapping"
workspace_id = "00000000-0000-0000-0000-000000000000"
format = "Default"
definition_update_enabled = false # <-- Disable definition update
definition = {
"DatabaseProperties.json" = {
source = "${local.path}/DatabaseProperties.json.tmpl"
}
}
}
# Example 6 - Item with definition update when source or tokens changed
resource "fabric_kql_database" "example6" {
display_name = "example6"
description = "example with definition update when source or tokens changed"
workspace_id = "00000000-0000-0000-0000-000000000000"
format = "Default"
definition = {
"DatabaseProperties.json" = {
source = "${local.path}/DatabaseProperties.json.tmpl"
tokens = {
"MyKey" = "MyValue"
}
}
}
}
```

<!-- schema generated by tfplugindocs -->
Expand Down
18 changes: 18 additions & 0 deletions docs/resources/ml_model.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ Use this resource to manage [ML Model](https://learn.microsoft.com/fabric/data-s

~> 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_ml_model" "example" {
display_name = "example"
workspace_id = "00000000-0000-0000-0000-000000000000"
}
```

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

Expand Down Expand Up @@ -46,3 +55,12 @@ Optional:
- `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_ml_model.example "<WorkspaceID>/<MLModelID>"
terraform import fabric_ml_model.example "00000000-0000-0000-0000-000000000000/11111111-1111-1111-1111-111111111111"
```
21 changes: 21 additions & 0 deletions examples/data-sources/fabric_kql_database/data-source.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
# Get item details by id
data "fabric_kql_database" "example_by_id" {
id = "11111111-1111-1111-1111-111111111111"
workspace_id = "00000000-0000-0000-0000-000000000000"
}

# Get item details by name
data "fabric_kql_database" "example_by_name" {
display_name = "example"
workspace_id = "00000000-0000-0000-0000-000000000000"
}

# Get item details with definition
# Examples uses `id` but `display_name` can be used as well
data "fabric_kql_database" "example_definition" {
id = "11111111-1111-1111-1111-111111111111"
workspace_id = "00000000-0000-0000-0000-000000000000"
format = "Default"
output_definition = true
}

# Access the content of the definition with JSONPath expression
output "example_definition_content_jsonpath" {
value = provider::fabric::content_decode(data.fabric_kql_database.example_definition.definition["DatabaseProperties.json"].content, ".")
}

# Access the content of the definition as JSON object
output "example_definition_content_object" {
value = provider::fabric::content_decode(data.fabric_kql_database.example_definition.definition["DatabaseProperties.json"].content)
}

# This is an invalid data source
# Do not specify `id` and `display_name` in the same data source block
# data "fabric_kql_database" "example" {
Expand Down
12 changes: 6 additions & 6 deletions examples/data-sources/fabric_notebook/data-source.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Get item details by name
data "fabric_notebook" "example_by_name" {
display_name = "example"
workspace_id = "00000000-0000-0000-0000-000000000000"
}

# Get item details by id
data "fabric_notebook" "example_by_id" {
id = "11111111-1111-1111-1111-111111111111"
workspace_id = "00000000-0000-0000-0000-000000000000"
}

# Get item details by name
data "fabric_notebook" "example_by_name" {
display_name = "example"
workspace_id = "00000000-0000-0000-0000-000000000000"
}

# Get item details with definition
# Examples uses `id` but `display_name` can be used as well
data "fabric_notebook" "example_definition" {
Expand Down
4 changes: 4 additions & 0 deletions examples/resources/fabric_eventhouse/providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ terraform {
}

provider "fabric" {}

locals {
path = abspath(join("/", [path.root, "..", "..", "..", "internal", "testhelp", "fixtures", "eventhouse"]))
}
4 changes: 4 additions & 0 deletions examples/resources/fabric_kql_database/providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ terraform {
}

provider "fabric" {}

locals {
path = abspath(join("/", [path.root, "..", "..", "..", "internal", "testhelp", "fixtures", "kql_database"]))
}
39 changes: 35 additions & 4 deletions examples/resources/fabric_kql_database/resource.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Example 1 - Create a ReadWrite KQL database
# Example 1 - Item with configuration, no definition - create a ReadWrite KQL database
resource "fabric_kql_database" "example1" {
display_name = "example1"
workspace_id = "00000000-0000-0000-0000-000000000000"
Expand All @@ -9,7 +9,7 @@ resource "fabric_kql_database" "example1" {
}
}

# Example 2 - Create a Shortcut KQL database to source Azure Data Explorer cluster
# Example 2 - Item with configuration, no definition - create a Shortcut KQL database to source Azure Data Explorer cluster
resource "fabric_kql_database" "example2" {
display_name = "example2"
workspace_id = "00000000-0000-0000-0000-000000000000"
Expand All @@ -22,7 +22,7 @@ resource "fabric_kql_database" "example2" {
}
}

# Example 3 - Create a Shortcut KQL database to source Azure Data Explorer cluster with invitation token
# Example 3 - Item with configuration, no definition - create a Shortcut KQL database to source Azure Data Explorer cluster with invitation token
resource "fabric_kql_database" "example3" {
display_name = "example3"
workspace_id = "00000000-0000-0000-0000-000000000000"
Expand All @@ -34,7 +34,7 @@ resource "fabric_kql_database" "example3" {
}
}

# Example 4 - Create a Shortcut KQL database to source KQL database
# Example 4 - Item with configuration, no definition - create a Shortcut KQL database to source KQL database
resource "fabric_kql_database" "example4" {
display_name = "example4"
workspace_id = "00000000-0000-0000-0000-000000000000"
Expand All @@ -45,3 +45,34 @@ resource "fabric_kql_database" "example4" {
source_database_name = "MyDatabase"
}
}


# Example 5 - Item with definition bootstrapping only
resource "fabric_kql_database" "example5" {
display_name = "example5"
description = "example with definition bootstrapping"
workspace_id = "00000000-0000-0000-0000-000000000000"
format = "Default"
definition_update_enabled = false # <-- Disable definition update
definition = {
"DatabaseProperties.json" = {
source = "${local.path}/DatabaseProperties.json.tmpl"
}
}
}

# Example 6 - Item with definition update when source or tokens changed
resource "fabric_kql_database" "example6" {
display_name = "example6"
description = "example with definition update when source or tokens changed"
workspace_id = "00000000-0000-0000-0000-000000000000"
format = "Default"
definition = {
"DatabaseProperties.json" = {
source = "${local.path}/DatabaseProperties.json.tmpl"
tokens = {
"MyKey" = "MyValue"
}
}
}
}
2 changes: 2 additions & 0 deletions examples/resources/fabric_ml_model/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# terraform import fabric_ml_model.example "<WorkspaceID>/<MLModelID>"
terraform import fabric_ml_model.example "00000000-0000-0000-0000-000000000000/11111111-1111-1111-1111-111111111111"
3 changes: 3 additions & 0 deletions examples/resources/fabric_ml_model/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "example" {
value = resource.fabric_ml_model.example
}
11 changes: 11 additions & 0 deletions examples/resources/fabric_ml_model/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_ml_model/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "fabric_ml_model" "example" {
display_name = "example"
workspace_id = "00000000-0000-0000-0000-000000000000"
}
3 changes: 1 addition & 2 deletions internal/provider/client/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ func NewFabricSDKLoggerSubsystem(ctx context.Context) (context.Context, hclog.Le

// Enable azcore logging if the target level is not "off"
if targetLevel != hclog.Off {
err := os.Setenv(AzureSDKLoggingEnvVar, AzureSDKLoggingAll)
if err != nil {
if err := os.Setenv(AzureSDKLoggingEnvVar, AzureSDKLoggingAll); err != nil {
return ctx, targetLevel, err
}
}
Expand Down
8 changes: 4 additions & 4 deletions internal/services/environment/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (to *environmentComponentPublishInfoModel) set(ctx context.Context, from *f

if from.SparkLibraries != nil {
sparkLibrariesModel := &environmentSparkLibrariesModel{}
sparkLibrariesModel.set(from.SparkLibraries)
sparkLibrariesModel.set(*from.SparkLibraries)

if diags := sparkLibraries.Set(ctx, sparkLibrariesModel); diags.HasError() {
return diags
Expand All @@ -95,7 +95,7 @@ func (to *environmentComponentPublishInfoModel) set(ctx context.Context, from *f

if from.SparkSettings != nil {
sparkSettingsModel := &environmentSparkSettingsModel{}
sparkSettingsModel.set(from.SparkSettings)
sparkSettingsModel.set(*from.SparkSettings)

if diags := sparkSettings.Set(ctx, sparkSettingsModel); diags.HasError() {
return diags
Expand All @@ -111,14 +111,14 @@ type environmentSparkLibrariesModel struct {
State types.String `tfsdk:"state"`
}

func (to *environmentSparkLibrariesModel) set(from *fabenvironment.SparkLibraries) {
func (to *environmentSparkLibrariesModel) set(from fabenvironment.SparkLibraries) {
to.State = types.StringPointerValue((*string)(from.State))
}

type environmentSparkSettingsModel struct {
State types.String `tfsdk:"state"`
}

func (to *environmentSparkSettingsModel) set(from *fabenvironment.SparkSettings) {
func (to *environmentSparkSettingsModel) set(from fabenvironment.SparkSettings) {
to.State = types.StringPointerValue((*string)(from.State))
}
2 changes: 1 addition & 1 deletion internal/services/kqldatabase/data_kql_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func NewDataSourceKQLDatabase() datasource.DataSource {

if from != nil {
propertiesModel := &kqlDatabasePropertiesModel{}
propertiesModel.set(from)
propertiesModel.set(*from)

if diags := properties.Set(ctx, propertiesModel); diags.HasError() {
return diags
Expand Down
Loading

0 comments on commit 0688b44

Please sign in to comment.