From e700a27079a437ad35e97c259981b33f66ab1ecb Mon Sep 17 00:00:00 2001 From: Julio Castillo Date: Fri, 16 Dec 2022 12:53:56 +0100 Subject: [PATCH] Enforce terraform fmt in examples --- .../factories/project-factory/README.md | 4 +- blueprints/gke/multitenant-fleet/README.md | 24 +++---- modules/api-gateway/README.md | 26 +++---- modules/apigee/README.md | 38 +++++----- modules/bigquery-dataset/README.md | 4 +- modules/bigtable-instance/README.md | 36 +++++----- modules/billing-budget/README.md | 2 +- modules/binauthz/README.md | 28 ++++---- .../cloud-config-container/coredns/README.md | 6 +- .../cos-generic-metadata/README.md | 2 +- .../cloud-config-container/mysql/README.md | 2 +- .../cloud-config-container/nginx/README.md | 2 +- .../cloud-config-container/squid/README.md | 6 +- modules/cloud-function/README.md | 70 +++++++++---------- modules/cloud-identity-group/README.md | 2 +- modules/cloud-run/README.md | 62 ++++++++-------- modules/cloudsql-instance/README.md | 2 +- modules/compute-mig/README.md | 10 +-- modules/compute-vm/README.md | 16 ++--- modules/data-catalog-policy-tag/README.md | 8 +-- modules/datafusion/README.md | 10 +-- modules/folder/README.md | 18 ++--- modules/gcs/README.md | 2 +- modules/gke-cluster/README.md | 4 +- modules/gke-hub/README.md | 28 ++++---- modules/gke-nodepool/README.md | 40 +++++------ modules/iam-service-account/README.md | 10 +-- modules/kms/README.md | 14 ++-- modules/net-address/README.md | 8 +-- modules/net-glb/README.md | 30 ++++---- modules/net-ilb-l7/README.md | 20 +++--- modules/net-ilb/README.md | 4 +- modules/net-vpc-firewall/README.md | 12 ++-- modules/net-vpc/README.md | 38 +++++----- modules/net-vpn-dynamic/README.md | 10 +-- modules/net-vpn-ha/README.md | 4 +- modules/organization/README.md | 24 +++---- modules/project/README.md | 46 ++++++------ modules/pubsub/README.md | 2 +- modules/secret-manager/README.md | 8 +-- modules/service-directory/README.md | 22 +++--- modules/source-repository/README.md | 8 +-- modules/vpc-sc/README.md | 2 +- tests/examples/conftest.py | 6 +- tests/examples/test_plan.py | 8 +++ 45 files changed, 368 insertions(+), 360 deletions(-) diff --git a/blueprints/factories/project-factory/README.md b/blueprints/factories/project-factory/README.md index a5680781..32a1f8f0 100644 --- a/blueprints/factories/project-factory/README.md +++ b/blueprints/factories/project-factory/README.md @@ -49,8 +49,8 @@ locals { trimsuffix(f, ".yaml") => yamldecode(file("${local._data_dir}/${f}")) } # these are usually set via variables - _base_dir = "./fabric/blueprints/factories/project-factory" - _data_dir = "${local._base_dir}/sample-data/projects/" + _base_dir = "./fabric/blueprints/factories/project-factory" + _data_dir = "${local._base_dir}/sample-data/projects/" _defaults_file = "${local._base_dir}/sample-data/defaults.yaml" } diff --git a/blueprints/gke/multitenant-fleet/README.md b/blueprints/gke/multitenant-fleet/README.md index 80d09ac1..52f26ced 100644 --- a/blueprints/gke/multitenant-fleet/README.md +++ b/blueprints/gke/multitenant-fleet/README.md @@ -78,7 +78,7 @@ module "gke-fleet" { location = "europe-west1" private_cluster_config = local.cluster_defaults.private_cluster_config vpc_config = { - subnetwork = local.subnet_self_links.ew1 + subnetwork = local.subnet_self_links.ew1 master_ipv4_cidr_block = "172.16.10.0/28" } } @@ -86,7 +86,7 @@ module "gke-fleet" { location = "europe-west3" private_cluster_config = local.cluster_defaults.private_cluster_config vpc_config = { - subnetwork = local.subnet_self_links.ew3 + subnetwork = local.subnet_self_links.ew3 master_ipv4_cidr_block = "172.16.20.0/28" } } @@ -95,16 +95,16 @@ module "gke-fleet" { cluster-0 = { nodepool-0 = { node_config = { - disk_type = "pd-balanced" + disk_type = "pd-balanced" machine_type = "n2-standard-4" - spot = true + spot = true } } } cluster-1 = { nodepool-0 = { node_config = { - disk_type = "pd-balanced" + disk_type = "pd-balanced" machine_type = "n2-standard-4" } } @@ -143,13 +143,13 @@ module "gke" { prefix = "myprefix" clusters = { cluster-0 = { - location = "europe-west1" + location = "europe-west1" vpc_config = { subnetwork = local.subnet_self_links.ew1 } } cluster-1 = { - location = "europe-west3" + location = "europe-west3" vpc_config = { subnetwork = local.subnet_self_links.ew3 } @@ -159,16 +159,16 @@ module "gke" { cluster-0 = { nodepool-0 = { node_config = { - disk_type = "pd-balanced" + disk_type = "pd-balanced" machine_type = "n2-standard-4" - spot = true + spot = true } } } cluster-1 = { nodepool-0 = { node_config = { - disk_type = "pd-balanced" + disk_type = "pd-balanced" machine_type = "n2-standard-4" } } @@ -205,14 +205,14 @@ module "gke" { enable_hierarchical_resource_quota = true enable_pod_tree_labels = true } - policy_controller = { + policy_controller = { audit_interval_seconds = 30 exemptable_namespaces = ["kube-system"] log_denies_enabled = true referential_rules_enabled = true template_library_installed = true } - version = "1.10.2" + version = "1.10.2" } } fleet_configmanagement_clusters = { diff --git a/modules/api-gateway/README.md b/modules/api-gateway/README.md index 7c15f581..0b5fc928 100644 --- a/modules/api-gateway/README.md +++ b/modules/api-gateway/README.md @@ -6,11 +6,11 @@ This module allows creating an API with its associated API config and API gatewa ## Basic example ```hcl module "gateway" { - source = "./fabric/modules/api-gateway" - project_id = "my-project" - api_id = "api" - region = "europe-west1" - spec = < 1: name += f' {index}' ids.append(name) + examples.append(Example(name, code, path, files[last_header])) elif isinstance(child, marko.block.Heading): last_header = child.children[0].children index = 0 diff --git a/tests/examples/test_plan.py b/tests/examples/test_plan.py index c7fd8dac..4248f641 100644 --- a/tests/examples/test_plan.py +++ b/tests/examples/test_plan.py @@ -13,6 +13,7 @@ # limitations under the License. import re +import subprocess from pathlib import Path BASE_PATH = Path(__file__).parent @@ -52,5 +53,12 @@ def test_example(plan_validator, tmp_path, example): assert expected_modules == num_modules, 'wrong number of modules' assert expected_resources == num_resources, 'wrong number of resources' + # TODO(jccb): this should probably be done in check_documentation + # but we already have all the data here. + result = subprocess.run( + 'terraform fmt -check -diff -no-color main.tf'.split(), cwd=tmp_path, + stdout=subprocess.PIPE, encoding='utf-8') + assert result.returncode == 0, f'terraform code not formatted correctly\n{result.stdout}' + else: assert False, "can't find tftest directive"