Skip to content

Use correct custom machine types #45

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
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
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This documentation describes a list of rules available by enabling this ruleset.

### Invalid machine types

These rules warn you if a machine type not listed at https://cloud.google.com/compute/docs/machine-types is being used. Please note that custom machine types cannot be detected correctly. These rules consider all machine types starting with `custom-` to be valid.
These rules warn you if a machine type not listed at https://cloud.google.com/compute/docs/machine-types is being used. Please note that custom machine types cannot be detected correctly. These rules consider all machine types starting with `[e2|n2|n2d|n1]-custom-` to be valid.

|Name|Severity|Enabled|
| --- | --- | --- |
Expand Down
6 changes: 5 additions & 1 deletion rules/google_composer_environment_invalid_machine_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ 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, "custom-") {
if validMachineTypes[machineType] ||
strings.HasPrefix(machineType, "e2-custom-") ||
strings.HasPrefix(machineType, "n2-custom-") ||
strings.HasPrefix(machineType, "n2d-custom-") ||
strings.HasPrefix(machineType, "n1-custom-") {
return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ resource "google_composer_environment" "test" {

node_config {
zone = "us-central1-a"
machine_type = "custom-6-20480"
machine_type = "n2-custom-6-20480"

network = google_compute_network.test.id
subnetwork = google_compute_subnetwork.test.id
Expand Down
6 changes: 5 additions & 1 deletion rules/google_compute_instance_invalid_machine_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ 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, "custom-") {
if validMachineTypes[machineType] ||
strings.HasPrefix(machineType, "e2-custom-") ||
strings.HasPrefix(machineType, "n2-custom-") ||
strings.HasPrefix(machineType, "n2d-custom-") ||
strings.HasPrefix(machineType, "n1-custom-") {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion rules/google_compute_instance_invalid_machine_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ resource "google_compute_instance" "vm_instance" {
Name: "custom type",
Content: `
resource "google_compute_instance" "vm_instance" {
machine_type = "custom-6-20480"
machine_type = "n2-custom-6-20480"
}`,
Expected: helper.Issues{},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ func (r *GoogleComputeInstanceTemplateInvalidMachineTypeRule) Check(runner tflin
err := runner.EvaluateExpr(attribute.Expr, &machineType)

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ resource "google_compute_instance_template" "vm_instance" {
Name: "custom type",
Content: `
resource "google_compute_instance_template" "vm_instance" {
machine_type = "custom-6-20480"
machine_type = "n2-custom-6-20480"
}`,
Expected: helper.Issues{},
},
Expand Down
6 changes: 5 additions & 1 deletion rules/google_compute_reservation_invalid_machine_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ 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, "custom-") {
if validMachineTypes[machineType] ||
strings.HasPrefix(machineType, "e2-custom-") ||
strings.HasPrefix(machineType, "n2-custom-") ||
strings.HasPrefix(machineType, "n2d-custom-") ||
strings.HasPrefix(machineType, "n1-custom-") {
return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ resource "google_compute_reservation" "gce_reservation" {
count = 1
instance_properties {
min_cpu_platform = "Intel Cascade Lake"
machine_type = "custom-6-20480"
machine_type = "n2-custom-6-20480"
}
}
}`,
Expand Down
6 changes: 5 additions & 1 deletion rules/google_container_cluster_invalid_machine_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ 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, "custom-") {
if validMachineTypes[machineType] ||
strings.HasPrefix(machineType, "e2-custom-") ||
strings.HasPrefix(machineType, "n2-custom-") ||
strings.HasPrefix(machineType, "n2d-custom-") ||
strings.HasPrefix(machineType, "n1-custom-") {
return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ resource "google_container_cluster" "primary_preemptible_nodes" {

node_config {
preemptible = true
machine_type = "custom-6-20480"
machine_type = "n2-custom-6-20480"

oauth_scopes = [
"https://www.googleapis.com/auth/logging.write",
Expand Down
6 changes: 5 additions & 1 deletion rules/google_container_node_pool_invalid_machine_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ 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, "custom-") {
if validMachineTypes[machineType] ||
strings.HasPrefix(machineType, "e2-custom-") ||
strings.HasPrefix(machineType, "n2-custom-") ||
strings.HasPrefix(machineType, "n2d-custom-") ||
strings.HasPrefix(machineType, "n1-custom-") {
return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ resource "google_container_node_pool" "primary_preemptible_nodes" {

node_config {
preemptible = true
machine_type = "custom-6-20480"
machine_type = "n2-custom-6-20480"

oauth_scopes = [
"https://www.googleapis.com/auth/logging.write",
Expand Down
6 changes: 5 additions & 1 deletion rules/google_dataflow_job_invalid_machine_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ 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, "custom-") {
if validMachineTypes[machineType] ||
strings.HasPrefix(machineType, "e2-custom-") ||
strings.HasPrefix(machineType, "n2-custom-") ||
strings.HasPrefix(machineType, "n2d-custom-") ||
strings.HasPrefix(machineType, "n1-custom-") {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion rules/google_dataflow_job_invalid_machine_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ resource "google_dataflow_job" "vm_instance" {
Name: "custom type",
Content: `
resource "google_dataflow_job" "vm_instance" {
machine_type = "custom-6-20480"
machine_type = "n2-custom-6-20480"
}`,
Expected: helper.Issues{},
},
Expand Down