Skip to content

Commit 14bef9e

Browse files
authored
Merge pull request #45 from thstarshine/correct-custom-machine-types
Use correct custom machine types
2 parents 488919c + 2b4923c commit 14bef9e

15 files changed

+43
-15
lines changed

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This documentation describes a list of rules available by enabling this ruleset.
66

77
### Invalid machine types
88

9-
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.
9+
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.
1010

1111
|Name|Severity|Enabled|
1212
| --- | --- | --- |

rules/google_composer_environment_invalid_machine_type.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ func (r *GoogleComposerEnvironmentInvalidMachineTypeRule) Check(runner tflint.Ru
6464
err := runner.EvaluateExpr(attribute.Expr, &machineType)
6565

6666
err = runner.EnsureNoError(err, func() error {
67-
if validMachineTypes[machineType] || strings.HasPrefix(machineType, "custom-") {
67+
if validMachineTypes[machineType] ||
68+
strings.HasPrefix(machineType, "e2-custom-") ||
69+
strings.HasPrefix(machineType, "n2-custom-") ||
70+
strings.HasPrefix(machineType, "n2d-custom-") ||
71+
strings.HasPrefix(machineType, "n1-custom-") {
6872
return nil
6973
}
7074

rules/google_composer_environment_invalid_machine_type_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ resource "google_composer_environment" "test" {
8282
8383
node_config {
8484
zone = "us-central1-a"
85-
machine_type = "custom-6-20480"
85+
machine_type = "n2-custom-6-20480"
8686
8787
network = google_compute_network.test.id
8888
subnetwork = google_compute_subnetwork.test.id

rules/google_compute_instance_invalid_machine_type.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ func (r *GoogleComputeInstanceInvalidMachineTypeRule) Check(runner tflint.Runner
4343
err := runner.EvaluateExpr(attribute.Expr, &machineType)
4444

4545
return runner.EnsureNoError(err, func() error {
46-
if validMachineTypes[machineType] || strings.HasPrefix(machineType, "custom-") {
46+
if validMachineTypes[machineType] ||
47+
strings.HasPrefix(machineType, "e2-custom-") ||
48+
strings.HasPrefix(machineType, "n2-custom-") ||
49+
strings.HasPrefix(machineType, "n2d-custom-") ||
50+
strings.HasPrefix(machineType, "n1-custom-") {
4751
return nil
4852
}
4953

rules/google_compute_instance_invalid_machine_type_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ resource "google_compute_instance" "vm_instance" {
4343
Name: "custom type",
4444
Content: `
4545
resource "google_compute_instance" "vm_instance" {
46-
machine_type = "custom-6-20480"
46+
machine_type = "n2-custom-6-20480"
4747
}`,
4848
Expected: helper.Issues{},
4949
},

rules/google_compute_instance_template_invalid_machine_type.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ func (r *GoogleComputeInstanceTemplateInvalidMachineTypeRule) Check(runner tflin
4343
err := runner.EvaluateExpr(attribute.Expr, &machineType)
4444

4545
return runner.EnsureNoError(err, func() error {
46-
if validMachineTypes[machineType] || strings.HasPrefix(machineType, "custom-") {
46+
if validMachineTypes[machineType] ||
47+
strings.HasPrefix(machineType, "e2-custom-") ||
48+
strings.HasPrefix(machineType, "n2-custom-") ||
49+
strings.HasPrefix(machineType, "n2d-custom-") ||
50+
strings.HasPrefix(machineType, "n1-custom-") {
4751
return nil
4852
}
4953

rules/google_compute_instance_template_invalid_machine_type_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ resource "google_compute_instance_template" "vm_instance" {
4343
Name: "custom type",
4444
Content: `
4545
resource "google_compute_instance_template" "vm_instance" {
46-
machine_type = "custom-6-20480"
46+
machine_type = "n2-custom-6-20480"
4747
}`,
4848
Expected: helper.Issues{},
4949
},

rules/google_compute_reservation_invalid_machine_type.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ func (r *GoogleComputeReservationInvalidMachineTypeRule) Check(runner tflint.Run
6464
err := runner.EvaluateExpr(attribute.Expr, &machineType)
6565

6666
err = runner.EnsureNoError(err, func() error {
67-
if validMachineTypes[machineType] || strings.HasPrefix(machineType, "custom-") {
67+
if validMachineTypes[machineType] ||
68+
strings.HasPrefix(machineType, "e2-custom-") ||
69+
strings.HasPrefix(machineType, "n2-custom-") ||
70+
strings.HasPrefix(machineType, "n2d-custom-") ||
71+
strings.HasPrefix(machineType, "n1-custom-") {
6872
return nil
6973
}
7074

rules/google_compute_reservation_invalid_machine_type_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ resource "google_compute_reservation" "gce_reservation" {
6868
count = 1
6969
instance_properties {
7070
min_cpu_platform = "Intel Cascade Lake"
71-
machine_type = "custom-6-20480"
71+
machine_type = "n2-custom-6-20480"
7272
}
7373
}
7474
}`,

rules/google_container_cluster_invalid_machine_type.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ func (r *GoogleContainerClusterInvalidMachineTypeRule) Check(runner tflint.Runne
5353
err := runner.EvaluateExpr(attribute.Expr, &machineType)
5454

5555
return runner.EnsureNoError(err, func() error {
56-
if validMachineTypes[machineType] || strings.HasPrefix(machineType, "custom-") {
56+
if validMachineTypes[machineType] ||
57+
strings.HasPrefix(machineType, "e2-custom-") ||
58+
strings.HasPrefix(machineType, "n2-custom-") ||
59+
strings.HasPrefix(machineType, "n2d-custom-") ||
60+
strings.HasPrefix(machineType, "n1-custom-") {
5761
return nil
5862
}
5963

rules/google_container_cluster_invalid_machine_type_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ resource "google_container_cluster" "primary_preemptible_nodes" {
7373
7474
node_config {
7575
preemptible = true
76-
machine_type = "custom-6-20480"
76+
machine_type = "n2-custom-6-20480"
7777
7878
oauth_scopes = [
7979
"https://www.googleapis.com/auth/logging.write",

rules/google_container_node_pool_invalid_machine_type.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ func (r *GoogleContainerNodePoolInvalidMachineTypeRule) Check(runner tflint.Runn
5353
err := runner.EvaluateExpr(attribute.Expr, &machineType)
5454

5555
return runner.EnsureNoError(err, func() error {
56-
if validMachineTypes[machineType] || strings.HasPrefix(machineType, "custom-") {
56+
if validMachineTypes[machineType] ||
57+
strings.HasPrefix(machineType, "e2-custom-") ||
58+
strings.HasPrefix(machineType, "n2-custom-") ||
59+
strings.HasPrefix(machineType, "n2d-custom-") ||
60+
strings.HasPrefix(machineType, "n1-custom-") {
5761
return nil
5862
}
5963

rules/google_container_node_pool_invalid_machine_type_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ resource "google_container_node_pool" "primary_preemptible_nodes" {
7676
7777
node_config {
7878
preemptible = true
79-
machine_type = "custom-6-20480"
79+
machine_type = "n2-custom-6-20480"
8080
8181
oauth_scopes = [
8282
"https://www.googleapis.com/auth/logging.write",

rules/google_dataflow_job_invalid_machine_type.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ func (r *GoogleDataflowJobInvalidMachineTypeRule) Check(runner tflint.Runner) er
4343
err := runner.EvaluateExpr(attribute.Expr, &machineType)
4444

4545
return runner.EnsureNoError(err, func() error {
46-
if validMachineTypes[machineType] || strings.HasPrefix(machineType, "custom-") {
46+
if validMachineTypes[machineType] ||
47+
strings.HasPrefix(machineType, "e2-custom-") ||
48+
strings.HasPrefix(machineType, "n2-custom-") ||
49+
strings.HasPrefix(machineType, "n2d-custom-") ||
50+
strings.HasPrefix(machineType, "n1-custom-") {
4751
return nil
4852
}
4953

rules/google_dataflow_job_invalid_machine_type_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ resource "google_dataflow_job" "vm_instance" {
4343
Name: "custom type",
4444
Content: `
4545
resource "google_dataflow_job" "vm_instance" {
46-
machine_type = "custom-6-20480"
46+
machine_type = "n2-custom-6-20480"
4747
}`,
4848
Expected: helper.Issues{},
4949
},

0 commit comments

Comments
 (0)