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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -24,9 +24,9 @@ BLUEPRINTS_PATH = FABRIC_ROOT / 'blueprints/'
MODULES_PATH = FABRIC_ROOT / 'modules/'
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')
@ -71,11 +71,11 @@ def pytest_generate_tests(metafunc):
continue
if child.lang == 'hcl':
path = module.relative_to(FABRIC_ROOT)
examples.append(Example(code, path, files[last_header]))
name = f'{path}:{last_header}'
if index > 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

View File

@ -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"