Skip to content

Make custom-* valid custom type #48

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

Merged
merged 2 commits into from
Oct 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions rules/google_composer_environment_invalid_machine_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package rules

import (
"fmt"
"strings"

hcl "github.com/hashicorp/hcl/v2"
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
Expand Down Expand Up @@ -64,11 +63,7 @@ func (r *GoogleComposerEnvironmentInvalidMachineTypeRule) Check(runner tflint.Ru
err := runner.EvaluateExpr(attribute.Expr, &machineType)

err = runner.EnsureNoError(err, func() error {
if validMachineTypes[machineType] ||
strings.HasPrefix(machineType, "e2-custom-") ||
strings.HasPrefix(machineType, "n2-custom-") ||
strings.HasPrefix(machineType, "n2d-custom-") ||
strings.HasPrefix(machineType, "n1-custom-") {
if validMachineTypes[machineType] || isCustomType(machineType) {
return nil
}

Expand Down
9 changes: 2 additions & 7 deletions rules/google_compute_instance_invalid_machine_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ package rules

import (
"fmt"
"strings"

hcl "github.com/hashicorp/hcl/v2"
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
)

// GoogleComputeInstanceInvalidMachineTypeRule checks whether the machine type is invalid
type GoogleComputeInstanceInvalidMachineTypeRule struct {}
type GoogleComputeInstanceInvalidMachineTypeRule struct{}

// NewGoogleComputeInstanceInvalidMachineTypeRule returns a new rule
func NewGoogleComputeInstanceInvalidMachineTypeRule() *GoogleComputeInstanceInvalidMachineTypeRule {
Expand Down Expand Up @@ -43,11 +42,7 @@ func (r *GoogleComputeInstanceInvalidMachineTypeRule) Check(runner tflint.Runner
err := runner.EvaluateExpr(attribute.Expr, &machineType)

return runner.EnsureNoError(err, func() error {
if validMachineTypes[machineType] ||
strings.HasPrefix(machineType, "e2-custom-") ||
strings.HasPrefix(machineType, "n2-custom-") ||
strings.HasPrefix(machineType, "n2d-custom-") ||
strings.HasPrefix(machineType, "n1-custom-") {
if validMachineTypes[machineType] || isCustomType(machineType) {
return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ package rules

import (
"fmt"
"strings"

hcl "github.com/hashicorp/hcl/v2"
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
)

// GoogleComputeInstanceTemplateInvalidMachineTypeRule checks whether the machine type is invalid
type GoogleComputeInstanceTemplateInvalidMachineTypeRule struct {}
type GoogleComputeInstanceTemplateInvalidMachineTypeRule struct{}

// NewGoogleComputeInstanceTemplateInvalidMachineTypeRule returns a new rule
func NewGoogleComputeInstanceTemplateInvalidMachineTypeRule() *GoogleComputeInstanceTemplateInvalidMachineTypeRule {
Expand Down Expand Up @@ -43,11 +42,7 @@ func (r *GoogleComputeInstanceTemplateInvalidMachineTypeRule) Check(runner tflin
err := runner.EvaluateExpr(attribute.Expr, &machineType)

return runner.EnsureNoError(err, func() error {
if validMachineTypes[machineType] ||
strings.HasPrefix(machineType, "e2-custom-") ||
strings.HasPrefix(machineType, "n2-custom-") ||
strings.HasPrefix(machineType, "n2d-custom-") ||
strings.HasPrefix(machineType, "n1-custom-") {
if validMachineTypes[machineType] || isCustomType(machineType) {
return nil
}

Expand Down
7 changes: 1 addition & 6 deletions rules/google_compute_reservation_invalid_machine_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package rules

import (
"fmt"
"strings"

hcl "github.com/hashicorp/hcl/v2"
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
Expand Down Expand Up @@ -64,11 +63,7 @@ func (r *GoogleComputeReservationInvalidMachineTypeRule) Check(runner tflint.Run
err := runner.EvaluateExpr(attribute.Expr, &machineType)

err = runner.EnsureNoError(err, func() error {
if validMachineTypes[machineType] ||
strings.HasPrefix(machineType, "e2-custom-") ||
strings.HasPrefix(machineType, "n2-custom-") ||
strings.HasPrefix(machineType, "n2d-custom-") ||
strings.HasPrefix(machineType, "n1-custom-") {
if validMachineTypes[machineType] || isCustomType(machineType) {
return nil
}

Expand Down
7 changes: 1 addition & 6 deletions rules/google_container_cluster_invalid_machine_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package rules

import (
"fmt"
"strings"

hcl "github.com/hashicorp/hcl/v2"
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
Expand Down Expand Up @@ -53,11 +52,7 @@ func (r *GoogleContainerClusterInvalidMachineTypeRule) Check(runner tflint.Runne
err := runner.EvaluateExpr(attribute.Expr, &machineType)

return runner.EnsureNoError(err, func() error {
if validMachineTypes[machineType] ||
strings.HasPrefix(machineType, "e2-custom-") ||
strings.HasPrefix(machineType, "n2-custom-") ||
strings.HasPrefix(machineType, "n2d-custom-") ||
strings.HasPrefix(machineType, "n1-custom-") {
if validMachineTypes[machineType] || isCustomType(machineType) {
return nil
}

Expand Down
7 changes: 1 addition & 6 deletions rules/google_container_node_pool_invalid_machine_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package rules

import (
"fmt"
"strings"

hcl "github.com/hashicorp/hcl/v2"
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
Expand Down Expand Up @@ -53,11 +52,7 @@ func (r *GoogleContainerNodePoolInvalidMachineTypeRule) Check(runner tflint.Runn
err := runner.EvaluateExpr(attribute.Expr, &machineType)

return runner.EnsureNoError(err, func() error {
if validMachineTypes[machineType] ||
strings.HasPrefix(machineType, "e2-custom-") ||
strings.HasPrefix(machineType, "n2-custom-") ||
strings.HasPrefix(machineType, "n2d-custom-") ||
strings.HasPrefix(machineType, "n1-custom-") {
if validMachineTypes[machineType] || isCustomType(machineType) {
return nil
}

Expand Down
9 changes: 2 additions & 7 deletions rules/google_dataflow_job_invalid_machine_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ package rules

import (
"fmt"
"strings"

hcl "github.com/hashicorp/hcl/v2"
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
)

// GoogleDataflowJobInvalidMachineTypeRule checks whether the machine type is invalid
type GoogleDataflowJobInvalidMachineTypeRule struct {}
type GoogleDataflowJobInvalidMachineTypeRule struct{}

// NewGoogleDataflowJobInvalidMachineTypeRule returns a new rule
func NewGoogleDataflowJobInvalidMachineTypeRule() *GoogleDataflowJobInvalidMachineTypeRule {
Expand Down Expand Up @@ -43,11 +42,7 @@ func (r *GoogleDataflowJobInvalidMachineTypeRule) Check(runner tflint.Runner) er
err := runner.EvaluateExpr(attribute.Expr, &machineType)

return runner.EnsureNoError(err, func() error {
if validMachineTypes[machineType] ||
strings.HasPrefix(machineType, "e2-custom-") ||
strings.HasPrefix(machineType, "n2-custom-") ||
strings.HasPrefix(machineType, "n2d-custom-") ||
strings.HasPrefix(machineType, "n1-custom-") {
if validMachineTypes[machineType] || isCustomType(machineType) {
return nil
}

Expand Down
10 changes: 10 additions & 0 deletions rules/utils.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package rules

import "strings"

var validMachineTypes = map[string]bool{
"e2-standard-2": true,
"e2-standard-4": true,
Expand Down Expand Up @@ -114,3 +116,11 @@ var validMachineTypes = map[string]bool{
"f1-micro": true,
"g1-small": true,
}

func isCustomType(machineType string) bool {
return strings.HasPrefix(machineType, "e2-custom-") ||
strings.HasPrefix(machineType, "n2-custom-") ||
strings.HasPrefix(machineType, "n2d-custom-") ||
strings.HasPrefix(machineType, "n1-custom-") ||
strings.HasPrefix(machineType, "custom-")
}