-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from eerkunt/coverage_and_locals
Coverage and locals
- Loading branch information
Showing
12 changed files
with
292 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
venv | ||
*,cover | ||
coverage.xml | ||
.coverage | ||
.scannerwork | ||
.pytest_cache | ||
*.pyc | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Feature: Resources should have a proper naming standard | ||
In order to keep consistency between resources | ||
As engineers | ||
We'll enforce naming standards | ||
|
||
Scenario Outline: Naming Standard on all available resources | ||
Given I have <resource_name> defined | ||
Then it should contain <name_key> | ||
And its value must match the "\${var.project}-\${var.environment}-\${var.application}-.*" regex | ||
|
||
Examples: | ||
| resource_name | name_key | | ||
| AWS EC2 instance | name | | ||
| AWS ELB resource | name | | ||
| AWS RDS instance | name | | ||
| AWS S3 Bucket | name | | ||
| AWS EBS volume | name | | ||
| AWS Auto-Scaling Group | name | | ||
| aws_key_pair | key_name | | ||
| aws_ecs_cluster | name | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from sys import exc_info, exit | ||
from os.path import isdir | ||
from terraform_compliance import Validator | ||
from terraform_validate.terraform_validate import TerraformSyntaxException | ||
|
||
|
||
def load_tf_files(tf_directory): | ||
result = False | ||
print('Reading terraform files.') | ||
|
||
if isdir('{}/.terraform'.format(tf_directory)): | ||
print('ERROR: You already have a .terraform directory within your terraform files.') | ||
print(' This will lead to run tests against those imported modules. Please delete the directory to continue.') | ||
exit(2) | ||
|
||
while result is False: | ||
try: | ||
Validator(tf_directory) | ||
print('All HCL files look good.') | ||
result = True | ||
|
||
except ValueError: | ||
print('Unable to validate Terraform Files.') | ||
print('ERROR: {}'.format(exc_info()[1])) | ||
exit(1) | ||
except TerraformSyntaxException: | ||
pad_invalid_tf_files(exc_info()[1]) | ||
|
||
return result | ||
|
||
|
||
def pad_invalid_tf_files(exception_message): | ||
exception_message = str(exception_message).split('\n') | ||
if 'Unexpected end of file' in exception_message[1]: | ||
filename = exception_message[0].split(' ')[-1:][0] | ||
print('Invalid HCL file: {}. Fixing it.'.format(filename)) | ||
pad_tf_file(filename) | ||
return True | ||
|
||
return False | ||
|
||
|
||
def pad_tf_file(file): | ||
with open(file, 'a') as f: | ||
f.write('variable {}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import sys | ||
import os | ||
from argparse import Action | ||
|
||
|
||
class ReadableDir(Action): | ||
def __init__(self, dest, required, help, option_strings=None, metavar=None): | ||
super(ReadableDir, self).__init__(dest, required, help, option_strings, metavar) | ||
self.dest = dest | ||
self.required = required | ||
self.help = help | ||
self.option_strings = option_strings | ||
self.metavar = metavar | ||
|
||
def __call__(self, parser, namespace, values, option_string=None): | ||
prospective_dir = values | ||
|
||
# Check if the given directory is actually a git repo | ||
if prospective_dir.startswith('git:'): | ||
print('Using remote git repository: {}'.format(prospective_dir[4:])) | ||
setattr(namespace, self.dest, prospective_dir[4:]) | ||
return True | ||
|
||
# Check if the given path is a directory really | ||
if not os.path.isdir(prospective_dir): | ||
print('ERROR: {} is not a directory.'.format(prospective_dir)) | ||
sys.exit(1) | ||
|
||
# Check if we have access to that directory | ||
if os.access(prospective_dir, os.R_OK): | ||
setattr(namespace, self.dest, prospective_dir) | ||
return True | ||
|
||
print('ERROR: Can not read {}'.format(prospective_dir)) | ||
sys.exit(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.