Skip to content

Commit

Permalink
resolve issues that would cause lint warnings if we enabled the linte…
Browse files Browse the repository at this point in the history
…rs (#2754)

Merged PR #2754.
  • Loading branch information
danawillow authored and modular-magician committed Nov 27, 2019
1 parent 872f85a commit 79f0f92
Show file tree
Hide file tree
Showing 32 changed files with 72 additions and 87 deletions.
2 changes: 1 addition & 1 deletion build/terraform
2 changes: 1 addition & 1 deletion build/terraform-beta
16 changes: 6 additions & 10 deletions templates/terraform/constants/disk.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Is the new disk size smaller than the old one?
func isDiskShrinkage(old, new, _ interface{}) bool {
// It's okay to remove size entirely.
if old == nil || new == nil {
return false
}
return new.(int) < old.(int)
// It's okay to remove size entirely.
if old == nil || new == nil {
return false
}
return new.(int) < old.(int)
}

// We cannot suppress the diff for the case when family name is not part of the image name since we can't
Expand Down Expand Up @@ -186,9 +186,5 @@ func suppressWindowsFamilyDiff(imageName, familyName string) bool {
updatedFamilyString := strings.Replace(familyName, "windows-", "windows-server-", 1)
updatedImageName := strings.Replace(imageName, "-dc-", "-", 1)
if strings.Contains(updatedImageName, updatedFamilyString) {
return true
}
return false
return strings.Contains(updatedImageName, updatedFamilyString)
}
5 changes: 1 addition & 4 deletions templates/terraform/constants/firewall.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,5 @@ func resourceComputeFirewallRuleHash(v interface{}) int {
}

func compareCaseInsensitive(k, old, new string, d *schema.ResourceData) bool {
if strings.ToLower(old) == strings.ToLower(new) {
return true
}
return false
return strings.ToLower(old) == strings.ToLower(new)
}
30 changes: 15 additions & 15 deletions templates/terraform/constants/tpu_node.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ func compareTpuNodeSchedulingConfig(k, old, new string, d *schema.ResourceData)
}

func validateHttpHeaders() schema.SchemaValidateFunc {
return func(i interface{}, k string) (s []string, es []error) {
headers := i.(map[string]interface{})
if _, ok := headers["Content-Length"]; ok {
es = append(es, fmt.Errorf("Cannot set the Content-Length header on %s", k))
return
}
for key, _ := range headers {
match, _ := regexp.MatchString("(X-Google-|X-AppEngine-).*", key)
if match {
es = append(es, fmt.Errorf("Cannot set the %s header on %s", key, k))
return
}
}
return func(i interface{}, k string) (s []string, es []error) {
headers := i.(map[string]interface{})
if _, ok := headers["Content-Length"]; ok {
es = append(es, fmt.Errorf("Cannot set the Content-Length header on %s", k))
return
}
r := regexp.MustCompile(`(X-Google-|X-AppEngine-).*`)
for key, _ := range headers {
if r.MatchString(key) {
es = append(es, fmt.Errorf("Cannot set the %s header on %s", key, k))
return
}
}

return
}
return
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d T

topic := d.Get("topic").(string)

re := regexp.MustCompile("projects\\/(.*)\\/topics\\/(.*)")
re := regexp.MustCompile(`projects\/(.*)\/topics\/(.*)`)
match := re.FindStringSubmatch(topic)
if len(match) == 3 {
return topic, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,5 @@
# limitations under the License.
-%>
func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData) interface{} {
if v == nil {
return false
}

return true
return v != nil
}
6 changes: 3 additions & 3 deletions templates/terraform/custom_flatten/http_headers.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d
delete(headers, "Content-Type")
}
}
for key, _ := range headers {
match, _ := regexp.MatchString("(X-Google-|X-AppEngine-|Content-Length).*", key)
if match {
r := regexp.MustCompile(`(X-Google-|X-AppEngine-|Content-Length).*`)
for key, _ := range headers {
if r.MatchString(key) {
delete(headers, key)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
)
}

d.Set("project", fmt.Sprintf("%s", stringParts[1]))
d.Set("project", stringParts[1])
return []*schema.ResourceData{d}, nil
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ if len(stringParts) != 4 {
)
}

d.Set("organization", fmt.Sprintf("%s", stringParts[1]))
d.Set("organization", stringParts[1])
return []*schema.ResourceData{d}, nil
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func dataSourceGoogleComputeNodeTypesRead(d *schema.ResourceData, meta interface
}

func flattenComputeNodeTypes(nodeTypes []*compute.NodeType) []string {
result := make([]string, len(nodeTypes), len(nodeTypes))
result := make([]string, len(nodeTypes))
for i, nodeType := range nodeTypes {
result[i] = nodeType.Name
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func dataSourceGoogleComputeRegionsRead(d *schema.ResourceData, meta interface{}
}

func flattenRegions(regions []*compute.Region) []string {
result := make([]string, len(regions), len(regions))
result := make([]string, len(regions))
for i, region := range regions {
result[i] = region.Name
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func dataSourceGoogleComputeZonesRead(d *schema.ResourceData, meta interface{})
}

func flattenZones(zones []*compute.Zone) []string {
result := make([]string, len(zones), len(zones))
result := make([]string, len(zones))
for i, zone := range zones {
result[i] = zone.Name
}
Expand Down
20 changes: 10 additions & 10 deletions third_party/terraform/resources/resource_bigquery_table.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ func resourceBigQueryTable() *schema.Resource {
},

// Schema: [Optional] Describes the schema of this table.
// Schema is required for external tables in CSV and JSON formats
// and disallowed for Google Cloud Bigtable, Cloud Datastore backups,
// and Avro formats.
// Schema is required for external tables in CSV and JSON formats
// and disallowed for Google Cloud Bigtable, Cloud Datastore backups,
// and Avro formats.
"schema": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -307,8 +307,8 @@ func resourceBigQueryTable() *schema.Resource {
"clustering": &schema.Schema{
Type: schema.TypeList,
Optional: true,
ForceNew: true,
MaxItems: 4,
ForceNew: true,
MaxItems: 4,
Elem: &schema.Schema{Type: schema.TypeString},
},

Expand Down Expand Up @@ -446,7 +446,7 @@ func resourceTable(d *schema.ResourceData, meta interface{}) (*bigquery.Table, e

if v, ok := d.GetOk("clustering"); ok {
table.Clustering = &bigquery.Clustering{
Fields: convertStringArr(v.([]interface{})),
Fields: convertStringArr(v.([]interface{})),
ForceSendFields: []string{"Fields"},
}
}
Expand Down Expand Up @@ -648,7 +648,7 @@ func flattenExternalDataConfiguration(edc *bigquery.ExternalDataConfiguration) (
result["google_sheets_options"] = flattenGoogleSheetsOptions(edc.GoogleSheetsOptions)
}

if edc.IgnoreUnknownValues == true {
if edc.IgnoreUnknownValues {
result["ignore_unknown_values"] = edc.IgnoreUnknownValues
}
if edc.MaxBadRecords != 0 {
Expand Down Expand Up @@ -703,11 +703,11 @@ func expandCsvOptions(configured interface{}) *bigquery.CsvOptions {
func flattenCsvOptions(opts *bigquery.CsvOptions) []map[string]interface{} {
result := map[string]interface{}{}

if opts.AllowJaggedRows == true {
if opts.AllowJaggedRows {
result["allow_jagged_rows"] = opts.AllowJaggedRows
}

if opts.AllowQuotedNewlines == true {
if opts.AllowQuotedNewlines {
result["allow_quoted_newlines"] = opts.AllowQuotedNewlines
}

Expand Down Expand Up @@ -815,7 +815,7 @@ func flattenTimePartitioning(tp *bigquery.TimePartitioning) []map[string]interfa
result["expiration_ms"] = tp.ExpirationMs
}

if tp.RequirePartitionFilter == true {
if tp.RequirePartitionFilter {
result["require_partition_filter"] = tp.RequirePartitionFilter
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func resourceCloudFunctionsFunction() *schema.Resource {
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
availableMemoryMB := v.(int)

if functionAllowedMemory[availableMemoryMB] != true {
if !functionAllowedMemory[availableMemoryMB] {
errors = append(errors, fmt.Errorf("Allowed values for memory (in MB) are: %s . Got %d",
joinMapKeys(&functionAllowedMemory), availableMemoryMB))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestAccComputeInstanceIamPolicy(t *testing.T) {
},
{
ResourceName: "google_compute_instance_iam_policy.foo",
ImportStateId: fmt.Sprintf("%s", instanceName),
ImportStateId: instanceName,
ImportState: true,
ImportStateVerify: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ func getDiskFromAttributes(config *Config, instance *compute.Instance, allDisks

func getDiskFromSource(instance *compute.Instance, source string) (*compute.AttachedDisk, error) {
for _, disk := range instance.Disks {
if disk.Boot == true || disk.Type == "SCRATCH" {
if disk.Boot || disk.Type == "SCRATCH" {
// Ignore boot/scratch disks since this is just for finding attached disks
continue
}
Expand All @@ -420,7 +420,7 @@ func getDiskFromSource(instance *compute.Instance, source string) (*compute.Atta

func getDiskFromDeviceName(instance *compute.Instance, deviceName string) (*compute.AttachedDisk, error) {
for _, disk := range instance.Disks {
if disk.Boot == true || disk.Type == "SCRATCH" {
if disk.Boot || disk.Type == "SCRATCH" {
// Ignore boot/scratch disks since this is just for finding attached disks
continue
}
Expand All @@ -437,7 +437,7 @@ func getDiskFromEncryptionKey(instance *compute.Instance, encryptionKey string)
return nil, err
}
for _, disk := range instance.Disks {
if disk.Boot == true || disk.Type == "SCRATCH" {
if disk.Boot || disk.Type == "SCRATCH" {
// Ignore boot/scratch disks since this is just for finding attached disks
continue
}
Expand All @@ -457,7 +457,7 @@ func getDiskFromAutoDeleteAndImage(config *Config, instance *compute.Instance, a
canonicalImage := imgParts[len(imgParts)-1]

for i, disk := range instance.Disks {
if disk.Boot == true || disk.Type == "SCRATCH" {
if disk.Boot || disk.Type == "SCRATCH" {
// Ignore boot/scratch disks since this is just for finding attached disks
continue
}
Expand All @@ -482,7 +482,7 @@ func getDiskFromAutoDeleteAndImage(config *Config, instance *compute.Instance, a
// the image family.
canonicalImage = strings.Replace(canonicalImage, "/family/", "/", -1)
for i, disk := range instance.Disks {
if disk.Boot == true || disk.Type == "SCRATCH" {
if disk.Boot || disk.Type == "SCRATCH" {
// Ignore boot/scratch disks since this is just for finding attached disks
continue
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ func reorderDisks(configDisks []interface{}, apiDisks []map[string]interface{})
return apiDisks
}

result := make([]map[string]interface{}, len(apiDisks), len(apiDisks))
result := make([]map[string]interface{}, len(apiDisks))

/*
Disks aren't necessarily returned from the API in the same order they were sent, so gather
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func canonicalizeInstanceRef(instanceRef string) string {

// Healthchecks need to exist before being referred to from the target pool.
func convertHealthChecks(healthChecks []interface{}, d *schema.ResourceData, config *Config) ([]string, error) {
if healthChecks == nil || len(healthChecks) == 0 {
if len(healthChecks) == 0 {
return []string{}, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2210,7 +2210,7 @@ func expandMaintenancePolicy(d *schema.ResourceData, meta interface{}) *containe
if cluster != nil && cluster.MaintenancePolicy != nil {
resourceVersion = cluster.MaintenancePolicy.ResourceVersion
}
exclusions := make(map[string]containerBeta.TimeWindow, 0)
exclusions := make(map[string]containerBeta.TimeWindow)
if cluster != nil && cluster.MaintenancePolicy != nil && cluster.MaintenancePolicy.Window != nil {
exclusions = cluster.MaintenancePolicy.Window.MaintenanceExclusions
}
Expand Down Expand Up @@ -2657,7 +2657,7 @@ func flattenWorkloadIdentityConfig(c *containerBeta.WorkloadIdentityConfig) []ma

func flattenIPAllocationPolicy(c *containerBeta.Cluster, d *schema.ResourceData, config *Config) []map[string]interface{} {
// If IP aliasing isn't enabled, none of the values in this block can be set.
if c == nil || c.IpAllocationPolicy == nil || c.IpAllocationPolicy.UseIpAliases == false {
if c == nil || c.IpAllocationPolicy == nil || !c.IpAllocationPolicy.UseIpAliases {
return nil
}

Expand Down Expand Up @@ -2943,7 +2943,7 @@ func containerClusterPrivateClusterConfigCustomDiff(d *schema.ResourceDiff, meta
return nil
}
config := pccList[0].(map[string]interface{})
if config["enable_private_nodes"].(bool) == true {
if config["enable_private_nodes"].(bool) {
block := config["master_ipv4_cidr_block"]

// We can only apply this validation if we know the final value of the field, and we may
Expand Down
2 changes: 1 addition & 1 deletion third_party/terraform/resources/resource_storage_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ func flattenCors(corsRules []*storage.BucketCors) []map[string]interface{} {

func expandBucketEncryption(configured interface{}) *storage.BucketEncryption {
encs := configured.([]interface{})
if encs == nil || len(encs) == 0 || encs[0] == nil {
if len(encs) == 0 || encs[0] == nil {
return nil
}
enc := encs[0].(map[string]interface{})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func TestComputeInstanceGroupMigrateState_empty(t *testing.T) {

// should handle non-nil but empty
is = &terraform.InstanceState{}
is, err = resourceComputeInstanceGroupMigrateState(tc.StateVersion, is, meta)
_, err = resourceComputeInstanceGroupMigrateState(tc.StateVersion, is, meta)

if err != nil {
t.Fatalf("bad %s, err: %#v", tn, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestAccComputeSubnetworkIamPolicy(t *testing.T) {
},
{
ResourceName: "google_compute_subnetwork_iam_policy.foo",
ImportStateId: fmt.Sprintf("%s", subnetwork),
ImportStateId: subnetwork,
ImportState: true,
ImportStateVerify: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ func TestAccSpannerDatabaseIamPolicy(t *testing.T) {
// Test a few import formats
{
ResourceName: "google_spanner_database_iam_policy.foo",
ImportStateId: fmt.Sprintf("%s", spannerDatabaseId{
ImportStateId: spannerDatabaseId{
Instance: instance,
Database: database,
Project: project,
}.terraformId()),
}.terraformId(),
ImportState: true,
ImportStateVerify: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ func TestAccSpannerInstanceIamPolicy(t *testing.T) {
// Test a few import formats
{
ResourceName: "google_spanner_instance_iam_policy.foo",
ImportStateId: fmt.Sprintf("%s", spannerInstanceId{
ImportStateId: spannerInstanceId{
Instance: instance,
Project: project,
}.terraformId()),
}.terraformId(),
ImportState: true,
ImportStateVerify: true,
},
Expand Down
Loading

0 comments on commit 79f0f92

Please sign in to comment.