From 68a4289770a9111db6f1987d4875c6188385ff29 Mon Sep 17 00:00:00 2001 From: magodo Date: Mon, 17 May 2021 01:25:10 +0800 Subject: [PATCH] Clean up XS003 warnings (#11718) Running the XS003 rule against the master branch and got following warnings: /home/magodo/github/terraform-provider-azurerm-secondary/azurerm/internal/services/compute/virtual_machine_scale_set.go:449:17: XS003: schema might introduce crash or diff as it allows to be an empty block /home/magodo/github/terraform-provider-azurerm-secondary/azurerm/internal/services/consumption/schema.go:185:13: XS003: schema might introduce crash or diff as it allows to be an empty block /home/magodo/github/terraform-provider-azurerm-secondary/azurerm/internal/services/consumption/schema.go:203:13: XS003: schema might introduce crash or diff as it allows to be an empty block /home/magodo/github/terraform-provider-azurerm-secondary/azurerm/internal/services/media/media_asset_filter_resource.go:69:31: XS003: schema might introduce crash or diff as it allows to be an empty block /home/magodo/github/terraform-provider-azurerm-secondary/azurerm/internal/services/media/media_asset_filter_resource.go:113:23: XS003: schema might introduce crash or diff as it allows to be an empty block /home/magodo/github/terraform-provider-azurerm-secondary/azurerm/internal/services/media/media_asset_filter_resource.go:118:20: XS003: schema might introduce crash or diff as it allows to be an empty block /home/magodo/github/terraform-provider-azurerm-secondary/azurerm/internal/services/mssql/migration/database_v0_to_v1.go:107:34: XS003: schema might introduce crash or diff as it allows to be an empty block /home/magodo/github/terraform-provider-azurerm-secondary/azurerm/internal/services/web/app_service.go:877:16: XS003: schema might introduce crash or diff as it allows to be an empty block This PR fixes all the warnings above, except the vmss one, which is covered in #11712. --- .../internal/services/consumption/schema.go | 39 ++++++++++--------- .../media/media_asset_filter_resource.go | 18 ++++++++- .../mssql/migration/database_v0_to_v1.go | 1 + azurerm/internal/services/web/app_service.go | 1 + .../docs/r/media_asset_filter.html.markdown | 2 +- 5 files changed, 41 insertions(+), 20 deletions(-) diff --git a/azurerm/internal/services/consumption/schema.go b/azurerm/internal/services/consumption/schema.go index 6d4680741cd34..95bdd1a4673d1 100644 --- a/azurerm/internal/services/consumption/schema.go +++ b/azurerm/internal/services/consumption/schema.go @@ -189,16 +189,18 @@ func SchemaConsumptionBudgetCommonResource() map[string]*schema.Schema { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "dimension": { - Type: schema.TypeSet, - Optional: true, - Set: schema.HashResource(SchemaConsumptionBudgetFilterDimensionElement()), - Elem: SchemaConsumptionBudgetFilterDimensionElement(), + Type: schema.TypeSet, + Optional: true, + Set: schema.HashResource(SchemaConsumptionBudgetFilterDimensionElement()), + Elem: SchemaConsumptionBudgetFilterDimensionElement(), + AtLeastOneOf: []string{"filter.0.dimension", "filter.0.tag", "filter.0.not"}, }, "tag": { - Type: schema.TypeSet, - Optional: true, - Set: schema.HashResource(SchemaConsumptionBudgetFilterTagElement()), - Elem: SchemaConsumptionBudgetFilterTagElement(), + Type: schema.TypeSet, + Optional: true, + Set: schema.HashResource(SchemaConsumptionBudgetFilterTagElement()), + Elem: SchemaConsumptionBudgetFilterTagElement(), + AtLeastOneOf: []string{"filter.0.dimension", "filter.0.tag", "filter.0.not"}, }, "not": { Type: schema.TypeList, @@ -207,21 +209,22 @@ func SchemaConsumptionBudgetCommonResource() map[string]*schema.Schema { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "dimension": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - ConflictsWith: []string{"filter.0.not.0.tag"}, - Elem: SchemaConsumptionBudgetFilterDimensionElement(), + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + ExactlyOneOf: []string{"filter.0.not.0.tag"}, + Elem: SchemaConsumptionBudgetFilterDimensionElement(), }, "tag": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - ConflictsWith: []string{"filter.0.not.0.dimension"}, - Elem: SchemaConsumptionBudgetFilterTagElement(), + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + ExactlyOneOf: []string{"filter.0.not.0.dimension"}, + Elem: SchemaConsumptionBudgetFilterTagElement(), }, }, }, + AtLeastOneOf: []string{"filter.0.dimension", "filter.0.tag", "filter.0.not"}, }, }, }, diff --git a/azurerm/internal/services/media/media_asset_filter_resource.go b/azurerm/internal/services/media/media_asset_filter_resource.go index 82a3c1d05b5f1..e61e2675c3711 100644 --- a/azurerm/internal/services/media/media_asset_filter_resource.go +++ b/azurerm/internal/services/media/media_asset_filter_resource.go @@ -76,35 +76,47 @@ func resourceMediaAssetFilter() *schema.Resource { Type: schema.TypeInt, Optional: true, ValidateFunc: validation.IntAtLeast(0), + AtLeastOneOf: []string{"presentation_time_range.0.end_in_units", "presentation_time_range.0.force_end", "presentation_time_range.0.live_backoff_in_units", + "presentation_time_range.0.presentation_window_in_units", "presentation_time_range.0.start_in_units", "presentation_time_range.0.unit_timescale_in_miliseconds"}, }, "force_end": { Type: schema.TypeBool, Optional: true, + AtLeastOneOf: []string{"presentation_time_range.0.end_in_units", "presentation_time_range.0.force_end", "presentation_time_range.0.live_backoff_in_units", + "presentation_time_range.0.presentation_window_in_units", "presentation_time_range.0.start_in_units", "presentation_time_range.0.unit_timescale_in_miliseconds"}, }, "live_backoff_in_units": { Type: schema.TypeInt, Optional: true, ValidateFunc: validation.IntAtLeast(0), + AtLeastOneOf: []string{"presentation_time_range.0.end_in_units", "presentation_time_range.0.force_end", "presentation_time_range.0.live_backoff_in_units", + "presentation_time_range.0.presentation_window_in_units", "presentation_time_range.0.start_in_units", "presentation_time_range.0.unit_timescale_in_miliseconds"}, }, "presentation_window_in_units": { Type: schema.TypeInt, Optional: true, ValidateFunc: validation.IntAtLeast(0), + AtLeastOneOf: []string{"presentation_time_range.0.end_in_units", "presentation_time_range.0.force_end", "presentation_time_range.0.live_backoff_in_units", + "presentation_time_range.0.presentation_window_in_units", "presentation_time_range.0.start_in_units", "presentation_time_range.0.unit_timescale_in_miliseconds"}, }, "start_in_units": { Type: schema.TypeInt, Optional: true, ValidateFunc: validation.IntAtLeast(0), + AtLeastOneOf: []string{"presentation_time_range.0.end_in_units", "presentation_time_range.0.force_end", "presentation_time_range.0.live_backoff_in_units", + "presentation_time_range.0.presentation_window_in_units", "presentation_time_range.0.start_in_units", "presentation_time_range.0.unit_timescale_in_miliseconds"}, }, "unit_timescale_in_miliseconds": { Type: schema.TypeInt, Optional: true, ValidateFunc: validation.IntAtLeast(1), + AtLeastOneOf: []string{"presentation_time_range.0.end_in_units", "presentation_time_range.0.force_end", "presentation_time_range.0.live_backoff_in_units", + "presentation_time_range.0.presentation_window_in_units", "presentation_time_range.0.start_in_units", "presentation_time_range.0.unit_timescale_in_miliseconds"}, }, }, }, @@ -115,9 +127,10 @@ func resourceMediaAssetFilter() *schema.Resource { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ + //lintignore:XS003 "condition": { Type: schema.TypeList, - Optional: true, + Required: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "operation": { @@ -365,6 +378,9 @@ func expandTracks(input []interface{}) *[]media.FilterTrackSelection { trackSelectionList := rawSelection.([]interface{}) filterTrackSelections := make([]media.FilterTrackPropertyCondition, 0) for _, trackSelection := range trackSelectionList { + if trackSelection == nil { + continue + } filterTrackSelection := media.FilterTrackPropertyCondition{} track := trackSelection.(map[string]interface{}) diff --git a/azurerm/internal/services/mssql/migration/database_v0_to_v1.go b/azurerm/internal/services/mssql/migration/database_v0_to_v1.go index a90b5c5216120..4911e7e10f3ed 100644 --- a/azurerm/internal/services/mssql/migration/database_v0_to_v1.go +++ b/azurerm/internal/services/mssql/migration/database_v0_to_v1.go @@ -104,6 +104,7 @@ func databaseV0V1Schema() *schema.Resource { Computed: true, }, + //lintignore:XS003 "long_term_retention_policy": { Type: schema.TypeList, Optional: true, diff --git a/azurerm/internal/services/web/app_service.go b/azurerm/internal/services/web/app_service.go index d5705a90103ce..9ed79fe9b1822 100644 --- a/azurerm/internal/services/web/app_service.go +++ b/azurerm/internal/services/web/app_service.go @@ -874,6 +874,7 @@ func schemaAppServiceIpRestriction() *schema.Schema { }, false), }, + //lintignore:XS003 "headers": { Type: schema.TypeList, Optional: true, diff --git a/website/docs/r/media_asset_filter.html.markdown b/website/docs/r/media_asset_filter.html.markdown index a85fadc4ef97f..6e942737c330d 100644 --- a/website/docs/r/media_asset_filter.html.markdown +++ b/website/docs/r/media_asset_filter.html.markdown @@ -143,7 +143,7 @@ A `selection` block supports the following: A `track_selection` block supports the following: -* `condition` - (Optional) One or more `condition` blocks as defined above. +* `condition` - (Required) One or more `condition` blocks as defined above. ## Attributes Reference