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

correct linting errors for typelist/max_items schema attributes #13090

Closed
wants to merge 10 commits into from
1 change: 1 addition & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ lint:
-S015 \
-S016 \
-S017 \
-S018 \
-S019 \
-S020 \
-S021 \
Expand Down
4 changes: 2 additions & 2 deletions aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ func providerConfigure(d *schema.ResourceData, terraformVersion string) (interfa
}
config.CredsFilename = credsPath

assumeRoleList := d.Get("assume_role").(*schema.Set).List()
assumeRoleList := d.Get("assume_role").([]interface{})
if len(assumeRoleList) == 1 {
assumeRole := assumeRoleList[0].(map[string]interface{})
config.AssumeRoleARN = assumeRole["role_arn"].(string)
Expand Down Expand Up @@ -1202,7 +1202,7 @@ var awsMutexKV = mutexkv.NewMutexKV()

func assumeRoleSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeSet,
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Expand Down
18 changes: 6 additions & 12 deletions aws/resource_aws_api_gateway_usage_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func resourceAwsApiGatewayUsagePlan() *schema.Resource {
},

"quota_settings": {
Type: schema.TypeSet,
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{
Expand Down Expand Up @@ -85,7 +85,7 @@ func resourceAwsApiGatewayUsagePlan() *schema.Resource {
},

"throttle_settings": {
Type: schema.TypeSet,
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{
Expand Down Expand Up @@ -155,7 +155,7 @@ func resourceAwsApiGatewayUsagePlanCreate(d *schema.ResourceData, meta interface
}

if v, ok := d.GetOk("quota_settings"); ok {
settings := v.(*schema.Set).List()
settings := v.([]interface{})
q, ok := settings[0].(map[string]interface{})

if errors := validateApiGatewayUsagePlanQuotaSettings(q); len(errors) > 0 {
Expand Down Expand Up @@ -184,7 +184,7 @@ func resourceAwsApiGatewayUsagePlanCreate(d *schema.ResourceData, meta interface
}

if v, ok := d.GetOk("throttle_settings"); ok {
settings := v.(*schema.Set).List()
settings := v.([]interface{})
q, ok := settings[0].(map[string]interface{})

if !ok {
Expand Down Expand Up @@ -363,10 +363,7 @@ func resourceAwsApiGatewayUsagePlanUpdate(d *schema.ResourceData, meta interface

if d.HasChange("throttle_settings") {
o, n := d.GetChange("throttle_settings")

os := o.(*schema.Set)
ns := n.(*schema.Set)
diff := ns.Difference(os).List()
diff := n.([]interface{})

// Handle Removal
if len(diff) == 0 {
Expand Down Expand Up @@ -411,10 +408,7 @@ func resourceAwsApiGatewayUsagePlanUpdate(d *schema.ResourceData, meta interface

if d.HasChange("quota_settings") {
o, n := d.GetChange("quota_settings")

os := o.(*schema.Set)
ns := n.(*schema.Set)
diff := ns.Difference(os).List()
diff := n.([]interface{})

// Handle Removal
if len(diff) == 0 {
Expand Down
22 changes: 11 additions & 11 deletions aws/resource_aws_api_gateway_usage_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,17 @@ func TestAccAWSAPIGatewayUsagePlan_throttling(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAPIGatewayUsagePlanExists(resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "throttle_settings.4173790118.burst_limit", "2"),
resource.TestCheckResourceAttr(resourceName, "throttle_settings.4173790118.rate_limit", "5"),
resource.TestCheckResourceAttr(resourceName, "throttle_settings.0.burst_limit", "2"),
resource.TestCheckResourceAttr(resourceName, "throttle_settings.0.rate_limit", "5"),
),
},
{
Config: testAccAWSApiGatewayUsagePlanThrottlingModifiedConfig(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAPIGatewayUsagePlanExists(resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "throttle_settings.1779463053.burst_limit", "3"),
resource.TestCheckResourceAttr(resourceName, "throttle_settings.1779463053.rate_limit", "6"),
resource.TestCheckResourceAttr(resourceName, "throttle_settings.0.burst_limit", "3"),
resource.TestCheckResourceAttr(resourceName, "throttle_settings.0.rate_limit", "6"),
),
},
{
Expand Down Expand Up @@ -270,7 +270,7 @@ func TestAccAWSAPIGatewayUsagePlan_throttlingInitialRateLimit(t *testing.T) {
Config: testAccAWSApiGatewayUsagePlanThrottlingConfig(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAPIGatewayUsagePlanExists(resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "throttle_settings.4173790118.rate_limit", "5"),
resource.TestCheckResourceAttr(resourceName, "throttle_settings.0.rate_limit", "5"),
),
},
{
Expand Down Expand Up @@ -310,19 +310,19 @@ func TestAccAWSAPIGatewayUsagePlan_quota(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAPIGatewayUsagePlanExists(resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "quota_settings.1956747625.limit", "100"),
resource.TestCheckResourceAttr(resourceName, "quota_settings.1956747625.offset", "6"),
resource.TestCheckResourceAttr(resourceName, "quota_settings.1956747625.period", "WEEK"),
resource.TestCheckResourceAttr(resourceName, "quota_settings.0.limit", "100"),
resource.TestCheckResourceAttr(resourceName, "quota_settings.0.offset", "6"),
resource.TestCheckResourceAttr(resourceName, "quota_settings.0.period", "WEEK"),
),
},
{
Config: testAccAWSApiGatewayUsagePlanQuotaModifiedConfig(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAPIGatewayUsagePlanExists(resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "quota_settings.3909168194.limit", "200"),
resource.TestCheckResourceAttr(resourceName, "quota_settings.3909168194.offset", "20"),
resource.TestCheckResourceAttr(resourceName, "quota_settings.3909168194.period", "MONTH"),
resource.TestCheckResourceAttr(resourceName, "quota_settings.0.limit", "200"),
resource.TestCheckResourceAttr(resourceName, "quota_settings.0.offset", "20"),
resource.TestCheckResourceAttr(resourceName, "quota_settings.0.period", "MONTH"),
),
},
{
Expand Down
4 changes: 2 additions & 2 deletions aws/resource_aws_api_gateway_vpc_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func resourceAwsApiGatewayVpcLink() *schema.Resource {
Optional: true,
},
"target_arns": {
Type: schema.TypeSet,
Type: schema.TypeList,
MaxItems: 1,
Required: true,
ForceNew: true,
Expand All @@ -54,7 +54,7 @@ func resourceAwsApiGatewayVpcLinkCreate(d *schema.ResourceData, meta interface{}

input := &apigateway.CreateVpcLinkInput{
Name: aws.String(d.Get("name").(string)),
TargetArns: expandStringList(d.Get("target_arns").(*schema.Set).List()),
TargetArns: expandStringList(d.Get("target_arns").([]interface{})),
Tags: tags,
}
if v, ok := d.GetOk("description"); ok {
Expand Down
3 changes: 1 addition & 2 deletions aws/resource_aws_appmesh_virtual_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func resourceAwsAppmeshVirtualNode() *schema.Resource {
},

"listener": {
Type: schema.TypeSet,
Type: schema.TypeList,
Optional: true,
MinItems: 0,
MaxItems: 1,
Expand Down Expand Up @@ -173,7 +173,6 @@ func resourceAwsAppmeshVirtualNode() *schema.Resource {
},
},
},
Set: appmeshVirtualNodeListenerHash,
},

"logging": {
Expand Down
20 changes: 1 addition & 19 deletions aws/resource_aws_appmesh_virtual_router.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package aws

import (
"bytes"
"fmt"
"log"
"strings"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/appmesh"
"github.com/hashicorp/terraform-plugin-sdk/helper/hashcode"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
Expand Down Expand Up @@ -59,7 +57,7 @@ func resourceAwsAppmeshVirtualRouter() *schema.Resource {
},

"listener": {
Type: schema.TypeSet,
Type: schema.TypeList,
Required: true,
MinItems: 1,
MaxItems: 1,
Expand Down Expand Up @@ -91,7 +89,6 @@ func resourceAwsAppmeshVirtualRouter() *schema.Resource {
},
},
},
Set: appmeshVirtualRouterListenerHash,
},
},
},
Expand Down Expand Up @@ -258,18 +255,3 @@ func resourceAwsAppmeshVirtualRouterImport(d *schema.ResourceData, meta interfac

return []*schema.ResourceData{d}, nil
}

func appmeshVirtualRouterListenerHash(vListener interface{}) int {
var buf bytes.Buffer
mListener := vListener.(map[string]interface{})
if vPortMapping, ok := mListener["port_mapping"].([]interface{}); ok && len(vPortMapping) > 0 && vPortMapping[0] != nil {
mPortMapping := vPortMapping[0].(map[string]interface{})
if v, ok := mPortMapping["port"].(int); ok {
buf.WriteString(fmt.Sprintf("%d-", v))
}
if v, ok := mPortMapping["protocol"].(string); ok {
buf.WriteString(fmt.Sprintf("%s-", v))
}
}
return hashcode.String(buf.String())
}
4 changes: 2 additions & 2 deletions aws/resource_aws_cloudfront_distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ func resourceAwsCloudFrontDistribution() *schema.Resource {
Optional: true,
},
"forwarded_values": {
Type: schema.TypeSet,
Type: schema.TypeList,
Required: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cookies": {
Type: schema.TypeSet,
Type: schema.TypeList,
Required: true,
MaxItems: 1,
Elem: &schema.Resource{
Expand Down
91 changes: 5 additions & 86 deletions aws/resource_aws_codebuild_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"log"
"regexp"
"strconv"
"time"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -160,7 +159,7 @@ func resourceAwsCodeBuildProject() *schema.Resource {
Computed: true,
},
"environment": {
Type: schema.TypeSet,
Type: schema.TypeList,
Required: true,
MaxItems: 1,
Elem: &schema.Resource{
Expand Down Expand Up @@ -256,7 +255,6 @@ func resourceAwsCodeBuildProject() *schema.Resource {
},
},
},
Set: resourceAwsCodeBuildProjectEnvironmentHash,
},
"logs_config": {
Type: schema.TypeList,
Expand Down Expand Up @@ -474,7 +472,7 @@ func resourceAwsCodeBuildProject() *schema.Resource {
Required: true,
},
"source": {
Type: schema.TypeSet,
Type: schema.TypeList,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"auth": {
Expand Down Expand Up @@ -549,7 +547,6 @@ func resourceAwsCodeBuildProject() *schema.Resource {
},
Required: true,
MaxItems: 1,
Set: resourceAwsCodeBuildProjectSourceHash,
},
"source_version": {
Type: schema.TypeString,
Expand Down Expand Up @@ -812,7 +809,7 @@ func expandProjectCache(s []interface{}) *codebuild.ProjectCache {
}

func expandProjectEnvironment(d *schema.ResourceData) *codebuild.ProjectEnvironment {
configs := d.Get("environment").(*schema.Set).List()
configs := d.Get("environment").([]interface{})

envConfig := configs[0].(map[string]interface{})

Expand Down Expand Up @@ -1006,7 +1003,7 @@ func expandProjectSecondarySources(d *schema.ResourceData) []*codebuild.ProjectS
}

func expandProjectSource(d *schema.ResourceData) codebuild.ProjectSource {
configs := d.Get("source").(*schema.Set).List()
configs := d.Get("source").([]interface{})

data := configs[0].(map[string]interface{})
return expandProjectSourceData(data)
Expand Down Expand Up @@ -1092,7 +1089,7 @@ func resourceAwsCodeBuildProjectRead(d *schema.ResourceData, meta interface{}) e
return fmt.Errorf("error setting artifacts: %s", err)
}

if err := d.Set("environment", schema.NewSet(resourceAwsCodeBuildProjectEnvironmentHash, flattenAwsCodeBuildProjectEnvironment(project.Environment))); err != nil {
if err := d.Set("environment", flattenAwsCodeBuildProjectEnvironment(project.Environment)); err != nil {
return fmt.Errorf("error setting environment: %s", err)
}

Expand Down Expand Up @@ -1515,84 +1512,6 @@ func resourceAwsCodeBuildProjectArtifactsHash(v interface{}) int {
return hashcode.String(buf.String())
}

func resourceAwsCodeBuildProjectEnvironmentHash(v interface{}) int {
var buf bytes.Buffer
m := v.(map[string]interface{})

environmentType := m["type"].(string)
computeType := m["compute_type"].(string)
image := m["image"].(string)
privilegedMode := m["privileged_mode"].(bool)
imagePullCredentialsType := m["image_pull_credentials_type"].(string)
environmentVariables := m["environment_variable"].([]interface{})
buf.WriteString(fmt.Sprintf("%s-", environmentType))
buf.WriteString(fmt.Sprintf("%s-", computeType))
buf.WriteString(fmt.Sprintf("%s-", image))
buf.WriteString(fmt.Sprintf("%t-", privilegedMode))
buf.WriteString(fmt.Sprintf("%s-", imagePullCredentialsType))
if v, ok := m["certificate"]; ok && v.(string) != "" {
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
}
if v, ok := m["registry_credential"]; ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
m := v.([]interface{})[0].(map[string]interface{})

if v, ok := m["credential"]; ok && v.(string) != "" {
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
}

if v, ok := m["credential_provider"]; ok && v.(string) != "" {
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
}
}
for _, e := range environmentVariables {
if e != nil { // Old statefiles might have nil values in them
ev := e.(map[string]interface{})
buf.WriteString(fmt.Sprintf("%s:", ev["name"].(string)))
// type is sometimes not returned by the API
if v, ok := ev["type"]; ok {
buf.WriteString(fmt.Sprintf("%s:", v.(string)))
}
buf.WriteString(fmt.Sprintf("%s-", ev["value"].(string)))
}
}

return hashcode.String(buf.String())
}

func resourceAwsCodeBuildProjectSourceHash(v interface{}) int {
var buf bytes.Buffer
m := v.(map[string]interface{})

buf.WriteString(fmt.Sprintf("%s-", m["type"].(string)))
if v, ok := m["source_identifier"]; ok {
buf.WriteString(fmt.Sprintf("%s-", strconv.Itoa(v.(int))))
}
if v, ok := m["buildspec"]; ok {
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
}
if v, ok := m["location"]; ok {
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
}
if v, ok := m["git_clone_depth"]; ok {
buf.WriteString(fmt.Sprintf("%s-", strconv.Itoa(v.(int))))
}
if v, ok := m["git_submodules_config"]; ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
m := v.([]interface{})[0].(map[string]interface{})

if v, ok := m["fetch_submodules"]; ok {
buf.WriteString(fmt.Sprintf("%s-", strconv.FormatBool(v.(bool))))
}
}
if v, ok := m["insecure_ssl"]; ok {
buf.WriteString(fmt.Sprintf("%s-", strconv.FormatBool(v.(bool))))
}
if v, ok := m["report_build_status"]; ok {
buf.WriteString(fmt.Sprintf("%s-", strconv.FormatBool(v.(bool))))
}

return hashcode.String(buf.String())
}

func resourceAwsCodeBuildProjectSourceAuthHash(v interface{}) int {
var buf bytes.Buffer
m := v.(map[string]interface{})
Expand Down
Loading