Skip to content

Commit

Permalink
Clean up XS003 warnings (hashicorp#11718)
Browse files Browse the repository at this point in the history
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 hashicorp#11712.
  • Loading branch information
magodo authored and favoretti committed May 26, 2021
1 parent b66eba3 commit 68a4289
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 20 deletions.
39 changes: 21 additions & 18 deletions azurerm/internal/services/consumption/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"},
},
},
},
Expand Down
18 changes: 17 additions & 1 deletion azurerm/internal/services/media/media_asset_filter_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
},
},
},
Expand All @@ -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": {
Expand Down Expand Up @@ -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{})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func databaseV0V1Schema() *schema.Resource {
Computed: true,
},

//lintignore:XS003
"long_term_retention_policy": {
Type: schema.TypeList,
Optional: true,
Expand Down
1 change: 1 addition & 0 deletions azurerm/internal/services/web/app_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,7 @@ func schemaAppServiceIpRestriction() *schema.Schema {
}, false),
},

//lintignore:XS003
"headers": {
Type: schema.TypeList,
Optional: true,
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/media_asset_filter.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 68a4289

Please sign in to comment.