Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(fabricitem): enable multi-format support #171

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changes/unreleased/added-20241223-094847.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: added
body: |
Added support for multi-format Notebook Resource/Data-Source.
By using `format` attribute, you can now define the format of the Notebook Resource/Data-Source. Accepted values are `jpynb`, and `py`.
time: 2024-12-23T09:48:47.1324573-08:00
custom:
Issue: "168"
7 changes: 7 additions & 0 deletions .changes/unreleased/breaking-20241223-094847.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: breaking
body: |
The `format` attribute is now REQUIRED for Resources/Data-Sources with definition support.
Currently applicable to the following Resources/Data-Sources: Report, Notebook, Semantic Model, and Spark Job Definition.
time: 2024-12-23T09:48:47.1324573-08:00
custom:
Issue: "111"
5 changes: 3 additions & 2 deletions docs/data-sources/notebook.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ data "fabric_notebook" "example_by_id" {
data "fabric_notebook" "example_definition" {
id = "11111111-1111-1111-1111-111111111111"
workspace_id = "00000000-0000-0000-0000-000000000000"
format = "ipynb"
output_definition = true
}

Expand Down Expand Up @@ -68,6 +69,7 @@ output "example_definition_content_object" {
### Optional

- `display_name` (String) The Notebook display name.
- `format` (String) The Notebook format. Possible values: `ipynb`, `py`
- `id` (String) The Notebook ID.
- `output_definition` (Boolean) Output definition parts as gzip base64 content? Default: `false`

Expand All @@ -77,9 +79,8 @@ output "example_definition_content_object" {

### Read-Only

- `definition` (Attributes Map) Definition parts. Possible path keys: `notebook-content.ipynb`. (see [below for nested schema](#nestedatt--definition))
- `definition` (Attributes Map) Definition parts. Possible path keys: `notebook-content.ipynb`, `notebook-content.py`. (see [below for nested schema](#nestedatt--definition))
- `description` (String) The Notebook description.
- `format` (String) The Notebook format. Possible values: `ipynb`.

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

Expand Down
3 changes: 2 additions & 1 deletion docs/data-sources/report.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ data "fabric_report" "example" {
data "fabric_report" "example_definition" {
id = "11111111-1111-1111-1111-111111111111"
workspace_id = "00000000-0000-0000-0000-000000000000"
format = "PBIR-Legacy"
output_definition = true
}

Expand Down Expand Up @@ -56,6 +57,7 @@ output "example_definition_report_object" {

### Optional

- `format` (String) The Report format. Possible values: `PBIR-Legacy`
- `output_definition` (Boolean) Output definition parts as gzip base64 content? Default: `false`

!> Your terraform state file may grow a lot if you output definition content. Only use it when you must use data from the definition.
Expand All @@ -67,7 +69,6 @@ output "example_definition_report_object" {
- `definition` (Attributes Map) Definition parts. Possible path keys: `report.json`, `definition.pbir`, `StaticResources/RegisteredResources/*`, `StaticResources/SharedResources/*`. (see [below for nested schema](#nestedatt--definition))
- `description` (String) The Report description.
- `display_name` (String) The Report display name.
- `format` (String) The Report format. Possible values: `PBIR-Legacy`.

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

Expand Down
3 changes: 2 additions & 1 deletion docs/data-sources/semantic_model.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ data "fabric_semantic_model" "example" {
data "fabric_semantic_model" "example_definition" {
id = "11111111-1111-1111-1111-111111111111"
workspace_id = "00000000-0000-0000-0000-000000000000"
format = "TMSL"
output_definition = true
}

Expand All @@ -53,6 +54,7 @@ output "example_definition_bim_object" {

### Optional

- `format` (String) The Semantic Model format. Possible values: `TMSL`
- `output_definition` (Boolean) Output definition parts as gzip base64 content? Default: `false`

!> Your terraform state file may grow a lot if you output definition content. Only use it when you must use data from the definition.
Expand All @@ -64,7 +66,6 @@ output "example_definition_bim_object" {
- `definition` (Attributes Map) Definition parts. Possible path keys: `model.bim`, `definition.pbism`, `diagramLayout.json`. (see [below for nested schema](#nestedatt--definition))
- `description` (String) The Semantic Model description.
- `display_name` (String) The Semantic Model display name.
- `format` (String) The Semantic Model format. Possible values: `TMSL`.

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

Expand Down
3 changes: 2 additions & 1 deletion docs/data-sources/spark_job_definition.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ data "fabric_spark_job_definition" "example_by_name" {
data "fabric_spark_job_definition" "example_definition" {
id = "11111111-1111-1111-1111-111111111111"
workspace_id = "00000000-0000-0000-0000-000000000000"
format = "SparkJobDefinitionV1"
output_definition = true
}

Expand Down Expand Up @@ -68,6 +69,7 @@ output "example_definition_content_object" {
### Optional

- `display_name` (String) The Spark Job Definition display name.
- `format` (String) The Spark Job Definition format. Possible values: `SparkJobDefinitionV1`
- `id` (String) The Spark Job Definition ID.
- `output_definition` (Boolean) Output definition parts as gzip base64 content? Default: `false`

Expand All @@ -79,7 +81,6 @@ output "example_definition_content_object" {

- `definition` (Attributes Map) Definition parts. Possible path keys: `SparkJobDefinitionV1.json`. (see [below for nested schema](#nestedatt--definition))
- `description` (String) The Spark Job Definition description.
- `format` (String) The Spark Job Definition format. Possible values: `SparkJobDefinitionV1`.
- `properties` (Attributes) The Spark Job Definition properties. (see [below for nested schema](#nestedatt--properties))

<a id="nestedatt--timeouts"></a>
Expand Down
6 changes: 4 additions & 2 deletions docs/resources/notebook.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ resource "fabric_notebook" "example_definition_bootstrap" {
description = "example with definition bootstrapping"
workspace_id = "00000000-0000-0000-0000-000000000000"
definition_update_enabled = false
format = "ipynb"
definition = {
"notebook-content.ipynb" = {
source = "${local.path}/notebook.ipynb.tmpl"
Expand All @@ -43,6 +44,7 @@ resource "fabric_notebook" "example_definition_update" {
display_name = "example"
description = "example with definition update when source or tokens changed"
workspace_id = "00000000-0000-0000-0000-000000000000"
format = "ipynb"
definition = {
"notebook-content.ipynb" = {
source = "${local.path}/notebook.ipynb.tmpl"
Expand All @@ -65,14 +67,14 @@ resource "fabric_notebook" "example_definition_update" {

### Optional

- `definition` (Attributes Map) Definition parts. Accepted path keys: `notebook-content.ipynb`. Read more about [Notebook definition part paths](https://learn.microsoft.com/rest/api/fabric/articles/item-management/definitions/notebook-definition). (see [below for nested schema](#nestedatt--definition))
- `definition` (Attributes Map) Definition parts. Accepted path keys: `notebook-content.ipynb`, `notebook-content.py`. Read more about [Notebook definition part paths](https://learn.microsoft.com/rest/api/fabric/articles/item-management/definitions/notebook-definition). (see [below for nested schema](#nestedatt--definition))
- `definition_update_enabled` (Boolean) Update definition on change of source content. Default: `true`.
- `description` (String) The Notebook description.
- `format` (String) The Notebook format. Possible values: `ipynb`, `py`
- `timeouts` (Attributes) (see [below for nested schema](#nestedatt--timeouts))

### Read-Only

- `format` (String) The Notebook format. Possible values: `ipynb`.
- `id` (String) The Notebook ID.

<a id="nestedatt--definition"></a>
Expand Down
4 changes: 3 additions & 1 deletion docs/resources/report.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ resource "fabric_report" "example_bootstrap" {
display_name = "example"
workspace_id = "00000000-0000-0000-0000-000000000000"
definition_update_enabled = false
format = "PBIR-Legacy"
definition = {
"report.json" = {
source = "${local.path}/report.json"
Expand All @@ -44,6 +45,7 @@ resource "fabric_report" "example_bootstrap" {
resource "fabric_report" "example_update" {
display_name = "example with update"
workspace_id = "00000000-0000-0000-0000-000000000000"
format = "PBIR-Legacy"
definition = {
"report.json" = {
source = "${local.path}/report.json"
Expand All @@ -68,6 +70,7 @@ resource "fabric_report" "example_update" {

- `definition` (Attributes Map) Definition parts. Accepted path keys: `report.json`, `definition.pbir`, `StaticResources/RegisteredResources/*`, `StaticResources/SharedResources/*`. Read more about [Report definition part paths](https://learn.microsoft.com/rest/api/fabric/articles/item-management/definitions/report-definition). (see [below for nested schema](#nestedatt--definition))
- `display_name` (String) The Report display name.
- `format` (String) The Report format. Possible values: `PBIR-Legacy`
- `workspace_id` (String) The Workspace ID.

### Optional
Expand All @@ -78,7 +81,6 @@ resource "fabric_report" "example_update" {

### Read-Only

- `format` (String) The Report format. Possible values: `PBIR-Legacy`.
- `id` (String) The Report ID.

<a id="nestedatt--definition"></a>
Expand Down
4 changes: 3 additions & 1 deletion docs/resources/semantic_model.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ resource "fabric_semantic_model" "example_bootstrap" {
display_name = "example"
workspace_id = "00000000-0000-0000-0000-000000000000"
definition_update_enabled = false
format = "TMSL"
definition = {
"model.bim" = {
source = "${local.path}/model.bim.tmpl"
Expand All @@ -38,6 +39,7 @@ resource "fabric_semantic_model" "example_bootstrap" {
resource "fabric_semantic_model" "example_update" {
display_name = "example with update"
workspace_id = "00000000-0000-0000-0000-000000000000"
format = "TMSL"
definition = {
"model.bim" = {
source = "${local.path}/model.bim.tmpl"
Expand All @@ -59,6 +61,7 @@ resource "fabric_semantic_model" "example_update" {

- `definition` (Attributes Map) Definition parts. Accepted path keys: `model.bim`, `definition.pbism`, `diagramLayout.json`. Read more about [Semantic Model definition part paths](https://learn.microsoft.com/rest/api/fabric/articles/item-management/definitions/semantic-model-definition). (see [below for nested schema](#nestedatt--definition))
- `display_name` (String) The Semantic Model display name.
- `format` (String) The Semantic Model format. Possible values: `TMSL`
- `workspace_id` (String) The Workspace ID.

### Optional
Expand All @@ -69,7 +72,6 @@ resource "fabric_semantic_model" "example_update" {

### Read-Only

- `format` (String) The Semantic Model format. Possible values: `TMSL`.
- `id` (String) The Semantic Model ID.

<a id="nestedatt--definition"></a>
Expand Down
4 changes: 3 additions & 1 deletion docs/resources/spark_job_definition.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ resource "fabric_spark_job_definition" "example_definition_bootstrap" {
description = "example with definition bootstrapping"
workspace_id = "00000000-0000-0000-0000-000000000000"
definition_update_enabled = false
format = "SparkJobDefinitionV1"
definition = {
"SparkJobDefinitionV1.json" = {
source = "${local.path}/SparkJobDefinitionV1.json.tmpl"
Expand All @@ -43,6 +44,7 @@ resource "fabric_spark_job_definition" "example_definition_update" {
display_name = "example3"
description = "example with definition update when source or tokens changed"
workspace_id = "00000000-0000-0000-0000-000000000000"
format = "SparkJobDefinitionV1"
definition = {
"SparkJobDefinitionV1.json" = {
source = "${local.path}/SparkJobDefinitionV1.json.tmpl"
Expand All @@ -68,11 +70,11 @@ resource "fabric_spark_job_definition" "example_definition_update" {
- `definition` (Attributes Map) Definition parts. Accepted path keys: `SparkJobDefinitionV1.json`. Read more about [Spark Job Definition definition part paths](https://learn.microsoft.com/rest/api/fabric/articles/item-management/definitions/spark-job-definition). (see [below for nested schema](#nestedatt--definition))
- `definition_update_enabled` (Boolean) Update definition on change of source content. Default: `true`.
- `description` (String) The Spark Job Definition description.
- `format` (String) The Spark Job Definition format. Possible values: `SparkJobDefinitionV1`
- `timeouts` (Attributes) (see [below for nested schema](#nestedatt--timeouts))

### Read-Only

- `format` (String) The Spark Job Definition format. Possible values: `SparkJobDefinitionV1`.
- `id` (String) The Spark Job Definition ID.
- `properties` (Attributes) The Spark Job Definition properties. (see [below for nested schema](#nestedatt--properties))

Expand Down
1 change: 1 addition & 0 deletions examples/data-sources/fabric_notebook/data-source.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ data "fabric_notebook" "example_by_id" {
data "fabric_notebook" "example_definition" {
id = "11111111-1111-1111-1111-111111111111"
workspace_id = "00000000-0000-0000-0000-000000000000"
format = "ipynb"
output_definition = true
}

Expand Down
1 change: 1 addition & 0 deletions examples/data-sources/fabric_report/data-source.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ data "fabric_report" "example" {
data "fabric_report" "example_definition" {
id = "11111111-1111-1111-1111-111111111111"
workspace_id = "00000000-0000-0000-0000-000000000000"
format = "PBIR-Legacy"
output_definition = true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ data "fabric_semantic_model" "example" {
data "fabric_semantic_model" "example_definition" {
id = "11111111-1111-1111-1111-111111111111"
workspace_id = "00000000-0000-0000-0000-000000000000"
format = "TMSL"
output_definition = true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ data "fabric_spark_job_definition" "example_by_name" {
data "fabric_spark_job_definition" "example_definition" {
id = "11111111-1111-1111-1111-111111111111"
workspace_id = "00000000-0000-0000-0000-000000000000"
format = "SparkJobDefinitionV1"
output_definition = true
}

Expand Down
2 changes: 2 additions & 0 deletions examples/resources/fabric_notebook/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ resource "fabric_notebook" "example_definition_bootstrap" {
description = "example with definition bootstrapping"
workspace_id = "00000000-0000-0000-0000-000000000000"
definition_update_enabled = false
format = "ipynb"
definition = {
"notebook-content.ipynb" = {
source = "${local.path}/notebook.ipynb.tmpl"
Expand All @@ -22,6 +23,7 @@ resource "fabric_notebook" "example_definition_update" {
display_name = "example"
description = "example with definition update when source or tokens changed"
workspace_id = "00000000-0000-0000-0000-000000000000"
format = "ipynb"
definition = {
"notebook-content.ipynb" = {
source = "${local.path}/notebook.ipynb.tmpl"
Expand Down
2 changes: 2 additions & 0 deletions examples/resources/fabric_report/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ resource "fabric_report" "example_bootstrap" {
display_name = "example"
workspace_id = "00000000-0000-0000-0000-000000000000"
definition_update_enabled = false
format = "PBIR-Legacy"
definition = {
"report.json" = {
source = "${local.path}/report.json"
Expand All @@ -23,6 +24,7 @@ resource "fabric_report" "example_bootstrap" {
resource "fabric_report" "example_update" {
display_name = "example with update"
workspace_id = "00000000-0000-0000-0000-000000000000"
format = "PBIR-Legacy"
definition = {
"report.json" = {
source = "${local.path}/report.json"
Expand Down
2 changes: 2 additions & 0 deletions examples/resources/fabric_semantic_model/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ resource "fabric_semantic_model" "example_bootstrap" {
display_name = "example"
workspace_id = "00000000-0000-0000-0000-000000000000"
definition_update_enabled = false
format = "TMSL"
definition = {
"model.bim" = {
source = "${local.path}/model.bim.tmpl"
Expand All @@ -17,6 +18,7 @@ resource "fabric_semantic_model" "example_bootstrap" {
resource "fabric_semantic_model" "example_update" {
display_name = "example with update"
workspace_id = "00000000-0000-0000-0000-000000000000"
format = "TMSL"
definition = {
"model.bim" = {
source = "${local.path}/model.bim.tmpl"
Expand Down
2 changes: 2 additions & 0 deletions examples/resources/fabric_spark_job_definition/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ resource "fabric_spark_job_definition" "example_definition_bootstrap" {
description = "example with definition bootstrapping"
workspace_id = "00000000-0000-0000-0000-000000000000"
definition_update_enabled = false
format = "SparkJobDefinitionV1"
definition = {
"SparkJobDefinitionV1.json" = {
source = "${local.path}/SparkJobDefinitionV1.json.tmpl"
Expand All @@ -22,6 +23,7 @@ resource "fabric_spark_job_definition" "example_definition_update" {
display_name = "example3"
description = "example with definition update when source or tokens changed"
workspace_id = "00000000-0000-0000-0000-000000000000"
format = "SparkJobDefinitionV1"
definition = {
"SparkJobDefinitionV1.json" = {
source = "${local.path}/SparkJobDefinitionV1.json.tmpl"
Expand Down
19 changes: 12 additions & 7 deletions internal/pkg/fabricitem/data_item_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ type DataSourceFabricItemDefinition struct {
MarkdownDescription string
IsDisplayNameUnique bool
FormatTypeDefault string
FormatTypes []string
DefinitionPathKeys []string
DefinitionFormats []DefinitionFormat
}

func NewDataSourceFabricItemDefinition(config DataSourceFabricItemDefinition) datasource.DataSource {
Expand Down Expand Up @@ -120,10 +119,12 @@ func (d *DataSourceFabricItemDefinition) Read(ctx context.Context, req datasourc
return
}

data.Format = types.StringNull()

if d.FormatTypeDefault != "" {
data.Format = types.StringValue(d.FormatTypeDefault)
if data.Format.IsNull() || data.Format.IsUnknown() {
if d.FormatTypeDefault != "" {
data.Format = types.StringValue(d.FormatTypeDefault)
} else {
data.Format = types.StringNull()
}
}

resp.Diagnostics.Append(resp.State.Set(ctx, data)...)
Expand Down Expand Up @@ -203,7 +204,11 @@ func (d *DataSourceFabricItemDefinition) getDefinition(ctx context.Context, mode
respGetOpts := &fabcore.ItemsClientBeginGetItemDefinitionOptions{}

if !model.Format.IsNull() {
respGetOpts.Format = model.Format.ValueStringPointer()
apiFormat := GetDefinitionFormatAPI(d.DefinitionFormats, model.Format.ValueString())

if apiFormat != "" {
respGetOpts.Format = azto.Ptr(apiFormat)
}
}

respGet, err := d.client.GetItemDefinition(ctx, model.WorkspaceID.ValueString(), model.ID.ValueString(), respGetOpts)
Expand Down
Loading
Loading