Enforce terraform fmt in examples

This commit is contained in:
Julio Castillo 2022-12-16 12:53:56 +01:00
parent 0faf8ae1f1
commit e700a27079
45 changed files with 368 additions and 360 deletions

View File

@ -31,7 +31,7 @@ module "gateway" {
EOT EOT
service_account_email = "sa@my-project.iam.gserviceaccount.com" service_account_email = "sa@my-project.iam.gserviceaccount.com"
iam = { iam = {
"roles/apigateway.admin" = [ "user:user@example.com" ] "roles/apigateway.admin" = ["user:user@example.com"]
} }
} }
# tftest modules=1 resources=7 # tftest modules=1 resources=7
@ -50,8 +50,8 @@ module "gateway" {
EOT EOT
service_account_create = true service_account_create = true
iam = { iam = {
"roles/apigateway.admin" = [ "user:mirene@google.com" ] "roles/apigateway.admin" = ["user:mirene@google.com"]
"roles/apigateway.viewer" = [ "user:mirene@google.com" ] "roles/apigateway.viewer" = ["user:mirene@google.com"]
} }
} }
# tftest modules=1 resources=11 # tftest modules=1 resources=11

View File

@ -20,11 +20,11 @@ module "binauthz" {
"europe-west1-c.cluster" = { "europe-west1-c.cluster" = {
evaluation_mode = "REQUIRE_ATTESTATION" evaluation_mode = "REQUIRE_ATTESTATION"
enforcement_mode = "ENFORCED_BLOCK_AND_AUDIT_LOG" enforcement_mode = "ENFORCED_BLOCK_AND_AUDIT_LOG"
attestors = [ "test" ] attestors = ["test"]
} }
} }
attestors_config = { attestors_config = {
"test": { "test" : {
note_reference = null note_reference = null
pgp_public_keys = [ pgp_public_keys = [
<<EOT <<EOT

View File

@ -19,8 +19,8 @@ module "cloud_run" {
command = null command = null
args = null args = null
env = { env = {
"VAR1": "VALUE1", "VAR1" : "VALUE1",
"VAR2": "VALUE2", "VAR2" : "VALUE2",
} }
env_from = null env_from = null
} }
@ -46,7 +46,7 @@ module "cloud_run" {
args = null args = null
env = null env = null
env_from = { env_from = {
"CREDENTIALS": { "CREDENTIALS" : {
name = "credentials" name = "credentials"
key = "1" key = "1"
} }
@ -75,7 +75,7 @@ module "cloud_run" {
ports = null ports = null
resources = null resources = null
volume_mounts = { volume_mounts = {
"credentials": "/credentials" "credentials" : "/credentials"
} }
}] }]
volumes = [ volumes = [

View File

@ -29,7 +29,7 @@ module "cmn-dc" {
tags = { tags = {
low = null low = null
medium = null medium = null
high = {"roles/datacatalog.categoryFineGrainedReader" = ["group:GROUP_NAME@example.com"]} high = { "roles/datacatalog.categoryFineGrainedReader" = ["group:GROUP_NAME@example.com"] }
} }
iam = { iam = {
"roles/datacatalog.categoryAdmin" = ["group:GROUP_NAME@example.com"] "roles/datacatalog.categoryAdmin" = ["group:GROUP_NAME@example.com"]

View File

@ -115,7 +115,7 @@ module "hub" {
} }
} }
configmanagement_clusters = { configmanagement_clusters = {
"default" = [ "cluster-1" ] "default" = ["cluster-1"]
} }
} }

View File

@ -48,7 +48,7 @@ module "vpn-2" {
network = var.vpc2.self_link network = var.vpc2.self_link
name = "net2-to-net1" name = "net2-to-net1"
router_config = { asn = 64513 } router_config = { asn = 64513 }
peer_gateway = { gcp = module.vpn-1.self_link} peer_gateway = { gcp = module.vpn-1.self_link }
tunnels = { tunnels = {
remote-0 = { remote-0 = {
bgp_peer = { bgp_peer = {

View File

@ -24,9 +24,9 @@ BLUEPRINTS_PATH = FABRIC_ROOT / 'blueprints/'
MODULES_PATH = FABRIC_ROOT / 'modules/' MODULES_PATH = FABRIC_ROOT / 'modules/'
SUBMODULES_PATH = MODULES_PATH / 'cloud-config-container' SUBMODULES_PATH = MODULES_PATH / 'cloud-config-container'
FILE_TEST_RE = re.compile(r'# tftest-file id=(\w+) path=([\S]+)') FILE_TEST_RE = re.compile(r'# tftest-file +id=(\w+) +path=([\S]+)')
Example = collections.namedtuple('Example', 'code module files') Example = collections.namedtuple('Example', 'name code module files')
File = collections.namedtuple('File', 'path content') File = collections.namedtuple('File', 'path content')
@ -71,11 +71,11 @@ def pytest_generate_tests(metafunc):
continue continue
if child.lang == 'hcl': if child.lang == 'hcl':
path = module.relative_to(FABRIC_ROOT) path = module.relative_to(FABRIC_ROOT)
examples.append(Example(code, path, files[last_header]))
name = f'{path}:{last_header}' name = f'{path}:{last_header}'
if index > 1: if index > 1:
name += f' {index}' name += f' {index}'
ids.append(name) ids.append(name)
examples.append(Example(name, code, path, files[last_header]))
elif isinstance(child, marko.block.Heading): elif isinstance(child, marko.block.Heading):
last_header = child.children[0].children last_header = child.children[0].children
index = 0 index = 0

View File

@ -13,6 +13,7 @@
# limitations under the License. # limitations under the License.
import re import re
import subprocess
from pathlib import Path from pathlib import Path
BASE_PATH = Path(__file__).parent 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_modules == num_modules, 'wrong number of modules'
assert expected_resources == num_resources, 'wrong number of resources' 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: else:
assert False, "can't find tftest directive" assert False, "can't find tftest directive"