From b5cd8ed276004dcea6c9d56de5722b1b9c9a27be Mon Sep 17 00:00:00 2001 From: Jakub Michalak Date: Tue, 17 Sep 2024 13:32:37 +0200 Subject: [PATCH] Add validators and ds templates --- pkg/datasources/masking_policies.go | 36 ++++++++++--------- .../data-sources/masking_policies.md.tmpl | 24 +++++++++++++ templates/data-sources/views.md.tmpl | 24 +++++++++++++ 3 files changed, 68 insertions(+), 16 deletions(-) create mode 100644 templates/data-sources/masking_policies.md.tmpl create mode 100644 templates/data-sources/views.md.tmpl diff --git a/pkg/datasources/masking_policies.go b/pkg/datasources/masking_policies.go index 9ddfc8b65c..0435c1907b 100644 --- a/pkg/datasources/masking_policies.go +++ b/pkg/datasources/masking_policies.go @@ -33,28 +33,32 @@ var maskingPoliciesSchema = map[string]*schema.Schema{ ExactlyOneOf: []string{"in.0.account", "in.0.database", "in.0.schema", "in.0.application", "in.0.application_package"}, }, "database": { - Type: schema.TypeString, - Optional: true, - Description: "Returns records for the current database in use or for a specified database.", - ExactlyOneOf: []string{"in.0.account", "in.0.database", "in.0.schema", "in.0.application", "in.0.application_package"}, + Type: schema.TypeString, + Optional: true, + Description: "Returns records for the current database in use or for a specified database.", + ExactlyOneOf: []string{"in.0.account", "in.0.database", "in.0.schema", "in.0.application", "in.0.application_package"}, + ValidateDiagFunc: resources.IsValidIdentifier[sdk.AccountObjectIdentifier](), }, "schema": { - Type: schema.TypeString, - Optional: true, - Description: "Returns records for the current schema in use or a specified schema. Use fully qualified name.", - ExactlyOneOf: []string{"in.0.account", "in.0.database", "in.0.schema", "in.0.application", "in.0.application_package"}, + Type: schema.TypeString, + Optional: true, + Description: "Returns records for the current schema in use or a specified schema. Use fully qualified name.", + ExactlyOneOf: []string{"in.0.account", "in.0.database", "in.0.schema", "in.0.application", "in.0.application_package"}, + ValidateDiagFunc: resources.IsValidIdentifier[sdk.DatabaseObjectIdentifier](), }, "application": { - Type: schema.TypeString, - Optional: true, - Description: "Returns records for the specified application.", - ExactlyOneOf: []string{"in.0.account", "in.0.database", "in.0.schema", "in.0.application", "in.0.application_package"}, + Type: schema.TypeString, + Optional: true, + Description: "Returns records for the specified application.", + ExactlyOneOf: []string{"in.0.account", "in.0.database", "in.0.schema", "in.0.application", "in.0.application_package"}, + ValidateDiagFunc: resources.IsValidIdentifier[sdk.AccountObjectIdentifier](), }, "application_package": { - Type: schema.TypeString, - Optional: true, - Description: "Returns records for the specified application package.", - ExactlyOneOf: []string{"in.0.account", "in.0.database", "in.0.schema", "in.0.application", "in.0.application_package"}, + Type: schema.TypeString, + Optional: true, + Description: "Returns records for the specified application package.", + ExactlyOneOf: []string{"in.0.account", "in.0.database", "in.0.schema", "in.0.application", "in.0.application_package"}, + ValidateDiagFunc: resources.IsValidIdentifier[sdk.AccountObjectIdentifier](), }, }, }, diff --git a/templates/data-sources/masking_policies.md.tmpl b/templates/data-sources/masking_policies.md.tmpl new file mode 100644 index 0000000000..abd91a8e36 --- /dev/null +++ b/templates/data-sources/masking_policies.md.tmpl @@ -0,0 +1,24 @@ +--- +page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}" +subcategory: "" +description: |- +{{ if gt (len (split .Description "")) 1 -}} +{{ index (split .Description "") 1 | plainmarkdown | trimspace | prefixlines " " }} +{{- else -}} +{{ .Description | plainmarkdown | trimspace | prefixlines " " }} +{{- end }} +--- + +!> **V1 release candidate** This data source was reworked and is a release candidate for the V1. We do not expect significant changes in it before the V1. We will welcome any feedback and adjust the data source if needed. Any errors reported will be resolved with a higher priority. We encourage checking this data source out before the V1 release. Please follow the [migration guide](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/MIGRATION_GUIDE.md#v0950--v0960) to use it. + +# {{.Name}} ({{.Type}}) + +{{ .Description | trimspace }} + +{{ if .HasExample -}} +## Example Usage + +{{ tffile (printf "examples/data-sources/%s/data-source.tf" .Name)}} +{{- end }} + +{{ .SchemaMarkdown | trimspace }} diff --git a/templates/data-sources/views.md.tmpl b/templates/data-sources/views.md.tmpl new file mode 100644 index 0000000000..e34e4a1d07 --- /dev/null +++ b/templates/data-sources/views.md.tmpl @@ -0,0 +1,24 @@ +--- +page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}" +subcategory: "" +description: |- +{{ if gt (len (split .Description "")) 1 -}} +{{ index (split .Description "") 1 | plainmarkdown | trimspace | prefixlines " " }} +{{- else -}} +{{ .Description | plainmarkdown | trimspace | prefixlines " " }} +{{- end }} +--- + +!> **V1 release candidate** This data source was reworked and is a release candidate for the V1. We do not expect significant changes in it before the V1. We will welcome any feedback and adjust the data source if needed. Any errors reported will be resolved with a higher priority. We encourage checking this data source out before the V1 release. Please follow the [migration guide](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/MIGRATION_GUIDE.md#v094x--v0950) to use it. + +# {{.Name}} ({{.Type}}) + +{{ .Description | trimspace }} + +{{ if .HasExample -}} +## Example Usage + +{{ tffile (printf "examples/data-sources/%s/data-source.tf" .Name)}} +{{- end }} + +{{ .SchemaMarkdown | trimspace }}