From 2a8dae3726a5280739187b4993dc4f33682b65a2 Mon Sep 17 00:00:00 2001 From: Toshinori Sugita Date: Sun, 28 Aug 2022 17:14:37 +0900 Subject: [PATCH] Update lint and validation --- README.md | 4 ++++ lint-and-validation/conftest/main.tf | 2 +- lint-and-validation/conftest/policy/tf_test.rego | 2 +- lint-and-validation/terraform-fmt/main.tf | 4 ++-- lint-and-validation/terraform-validate/main.tf | 4 ++-- lint-and-validation/tflint/.tflint.hcl | 2 ++ lint-and-validation/tflint/README.md | 9 ++------- lint-and-validation/tflint/main.tf | 4 ++-- 8 files changed, 16 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 1388b8b..cb58445 100644 --- a/README.md +++ b/README.md @@ -49,3 +49,7 @@ Diffrent repository: [toshi0607/GKE-Microservices-Terraform-project-template](ht ### Chapter 8 Lint and validation * [Lint and validation](./lint-and-validation/) + * [terraform fmt](./lint-and-validation/terraform-fmt) + * [terraform validate](./lint-and-validation/terraform-validate) + * [TFLint](./lint-and-validation/tflint) + * [Conftest](./lint-and-validation/conftest) diff --git a/lint-and-validation/conftest/main.tf b/lint-and-validation/conftest/main.tf index 6206529..ee92d89 100644 --- a/lint-and-validation/conftest/main.tf +++ b/lint-and-validation/conftest/main.tf @@ -1,5 +1,5 @@ provider "google" { - version = ">= 3.33.0" + version = ">= 4.32.0" } resource "google_project_service" "gcp_api_service" { diff --git a/lint-and-validation/conftest/policy/tf_test.rego b/lint-and-validation/conftest/policy/tf_test.rego index 7df9475..ab3ed01 100644 --- a/lint-and-validation/conftest/policy/tf_test.rego +++ b/lint-and-validation/conftest/policy/tf_test.rego @@ -18,7 +18,7 @@ no_violations { test_provider_with_version_is_denied { input := { - "provider": { { "version": ">= 3.33.0", "region": "somewhere" } } + "provider": { { "version": ">= 4.32.0", "region": "somewhere" } } } violations with input as input } diff --git a/lint-and-validation/terraform-fmt/main.tf b/lint-and-validation/terraform-fmt/main.tf index 574c4f8..f1c3701 100644 --- a/lint-and-validation/terraform-fmt/main.tf +++ b/lint-and-validation/terraform-fmt/main.tf @@ -1,11 +1,11 @@ resource "google_compute_instance" "tf_fmt_example" { name = "tf-fmt-test" machine_type = "f1-micro" - zone = "asia-northeast1-a" + zone = "asia-northeast1-c" boot_disk { initialize_params { - image = "debian-cloud/debian-9" + image = "debian-cloud/debian-11" } } diff --git a/lint-and-validation/terraform-validate/main.tf b/lint-and-validation/terraform-validate/main.tf index 3eecdd4..b0e65fc 100644 --- a/lint-and-validation/terraform-validate/main.tf +++ b/lint-and-validation/terraform-validate/main.tf @@ -1,11 +1,11 @@ resource "google_compute_instance" "tf_validate_example" { name = "tf-validate-test" machine_type = "f1-micro" - zone = "asia-northeast1-a" + zone = "asia-northeast1-c" boot_disk { initialize_params = { - image = "debian-cloud/debian-9" + image = "debian-cloud/debian-11" } } diff --git a/lint-and-validation/tflint/.tflint.hcl b/lint-and-validation/tflint/.tflint.hcl index f40c62c..a9d4ddc 100644 --- a/lint-and-validation/tflint/.tflint.hcl +++ b/lint-and-validation/tflint/.tflint.hcl @@ -1,5 +1,7 @@ plugin "google" { enabled = true + version = "0.19.0" + source = "github.com/terraform-linters/tflint-ruleset-google" } rule "google_compute_address_invalid_address_type" { diff --git a/lint-and-validation/tflint/README.md b/lint-and-validation/tflint/README.md index 50d3e90..b203385 100644 --- a/lint-and-validation/tflint/README.md +++ b/lint-and-validation/tflint/README.md @@ -1,10 +1,5 @@ ```console $ brew install tflint -$ git clone git@github.com:terraform-linters/tflint-ruleset-google.git -$ cd tflint-ruleset-google -$ make install - -# Add .tflint.hcl - +$ tflint --init $ tflint -``` \ No newline at end of file +``` diff --git a/lint-and-validation/tflint/main.tf b/lint-and-validation/tflint/main.tf index 5edd1df..bc1ac3d 100644 --- a/lint-and-validation/tflint/main.tf +++ b/lint-and-validation/tflint/main.tf @@ -1,11 +1,11 @@ resource "google_compute_instance" "tflint_example" { name = "tflint-test" machine_type = "invalid-machine-type" - zone = "asia-northeast1-a" + zone = "asia-northeast1-c" boot_disk { initialize_params { - image = "debian-cloud/debian-9" + image = "debian-cloud/debian-11" } }