Skip to content

Commit c1bcc6d

Browse files
committed
More updates everywhere
1 parent 597d5e5 commit c1bcc6d

File tree

9 files changed

+201
-96
lines changed

9 files changed

+201
-96
lines changed

CODE_OF_CONDUCT.md

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6+
7+
## Our Standards
8+
9+
Examples of behavior that contributes to creating a positive environment include:
10+
11+
* Using welcoming and inclusive language
12+
* Being respectful of differing viewpoints and experiences
13+
* Gracefully accepting constructive criticism
14+
* Focusing on what is best for the community
15+
* Showing empathy towards other community members
16+
17+
Examples of unacceptable behavior by participants include:
18+
19+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
20+
* Trolling, insulting/derogatory comments, and personal or political attacks
21+
* Public or private harassment
22+
* Publishing others' private information, such as a physical or electronic address, without explicit permission
23+
* Other conduct which could reasonably be considered inappropriate in a professional setting
24+
25+
## Our Responsibilities
26+
27+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28+
29+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30+
31+
## Scope
32+
33+
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34+
35+
## Enforcement
36+
37+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project maintainer at [email protected]. The project maintainer will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project maintainer is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38+
39+
Project contributors who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40+
41+
## Attribution
42+
43+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44+
45+
[homepage]: http://contributor-covenant.org
46+
[version]: http://contributor-covenant.org/version/1/4/

LICENSE

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2018 Anton Babenko
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+61-15
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1-
# modules.tf-lambda
1+
# modules.tf - Infrastructure as code generator - from visual diagrams to Terraform
22

3-
This repository contains AWS Lambda function which accepts URL to blueprint json file from Cloudcraft and returns zip-archive with infrastructure as code.
3+
This repository contains code for AWS Lambda function which accepts URL to blueprint json file from Cloudcraft and returns zip-archive with Terraform infrastructure as code.
44

5-
Input:
5+
This code is deployed and available for everyone:
6+
* [Sign up for free](https://cloudcraft.co/signup) or [login](https://cloudcraft.co/app) to [Cloudcraft](https://cloudcraft.co/app)
7+
* Visualize your cloud architecture (like a pro)
8+
* Click "Export" and "Export as code (modules.tf)"
9+
* Unzip archive which you have just downloaded and read `README.md` file in it
10+
11+
12+
to:
13+
* [lambda.modules.tf - production environment](https://lambda.modules.tf/)
14+
* [dev-lambda.modules.tf - dev environment](https://dev-lambda.modules.tf/)
15+
16+
Example input:
617
* URL: https://cloudcraft.co/api/blueprint/bf0ad2c6-168f-4452-9add-cc4c869f910b
718
* local file: blueprint.json
819

@@ -79,27 +90,62 @@ cd final
7990
pre-commit run -c $(pwd)/.pre-commit-config.yaml --files $(pwd)/eu-west-1/rds/terraform.tfvars
8091
pre-commit run -c $(pwd)/.pre-commit-config.yaml --files $(pwd)/....
8192

82-
# Run locally:
93+
## I am developer - show me the code & let's ship it!
94+
95+
Ok, if you are a developer and want to contribute, this is really great because [I](https://github.com/antonbabenko) need your help:
96+
97+
- Report, triage and fix bugs
98+
- Refactor code
99+
- Improve documentation
100+
- Implement new sources and workflows (now only [Cloudcraft](https://cloudcraft.co/app) is partially supported)
101+
- Consider contributing to [Terraform AWS modules](https://github.com/terraform-aws-modules) if you familiar with Terraform already
102+
103+
### Getting started
104+
105+
[AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html) supports Python 3.6, so you should use it also. Run this to install all required packages:
106+
107+
```
108+
$ pip install -r requirements.txt
109+
```
110+
111+
[Serverless framework](https://serverless.com) is used to do heavy-lifting by packaging dependencies required for AWS Lambda function (`requirements-lambda.txt`) and updating the code there. Read through [Quick Start guide](https://serverless.com/framework/docs/providers/aws/guide/quick-start/), as well as [installation](https://serverless.com/framework/docs/providers/aws/guide/installation/), [various AWS functions](https://serverless.com/framework/docs/providers/aws/guide/functions/), [serverless.yml reference](https://serverless.com/framework/docs/providers/aws/guide/serverless.yml/) to familiarise yourself with the usage of the framework.
112+
113+
As a short cheatsheet, you will need to use these commands:
83114

84-
serverless invoke local --function generate --path input.json
115+
* Invoke function locally providing `input.json`:
85116

86-
Or:
117+
```
118+
$ serverless invoke local --function generate-cloudcraft --path test_fixtures/input_localfile.json
119+
```
120+
121+
* Deploy all functions to `prod` environment:
122+
123+
```
124+
$ serverless deploy --stage prod
125+
```
87126

88-
python3 handler.py
127+
* Deploy single function to `dev` environment:
89128

90-
# Deploy to prod
129+
```
130+
$ serverless deploy function --function generate-cloudcraft --stage dev
131+
```
132+
133+
* Deploy single function to `prod` environment:
134+
135+
```
136+
$ serverless deploy function --function generate-cloudcraft --stage prod
137+
```
91138

92-
serverless deploy --stage prod
139+
## Authors
93140

94-
# Deploy single function to dev
141+
This project is created and maintained by [Anton Babenko](https://github.com/antonbabenko) with the help from different contributors.
95142

96-
serverless deploy function --function generate-cloudcraft --stage dev
143+
Remember to sign up for [Cloudcraft](https://cloudcraft.co/app) account and visualize your cloud architecture like a pro! This project would probably not exist without it.
97144

98-
or to prod:
145+
The authors and contributors to this content cannot guarantee the validity of the information found here. Please make sure that you understand that the information provided here is being provided freely, and that no kind of agreement or contract is created between you and any persons associated with this content or project. The authors and contributors do not assume and hereby disclaim any liability to any party for any loss, damage, or disruption caused by errors or omissions in the information contained in, associated with, or linked from this content, whether such errors or omissions result from negligence, accident, or any other cause.
99146

100-
serverless deploy function --function generate-cloudcraft --stage prod
147+
## License
101148

102-
# License
103-
The MIT License
149+
This work is licensed under MIT License. See LICENSE for full details.
104150

105151
Copyright (c) 2018 Anton Babenko

handler.py

+35-62
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
import glob
44
import json
55
import re
6-
import tempfile
7-
8-
import networkx as nx
96

107
import boto3
118
import os
@@ -14,56 +11,25 @@
1411
from hashlib import md5
1512
from pprint import pprint, pformat
1613
import requests
17-
import sys
18-
import logging
14+
1915
from cookiecutter.exceptions import NonTemplatedInputDirException
2016

2117
from cookiecutter.main import cookiecutter
2218

2319
from modulestf.terraform import *
2420
from modulestf.converter import *
25-
from modulestf.modules import MODULES
26-
from modulestf.cloudcraft.graph import *
27-
28-
BASE_PATH = os.path.dirname(os.path.abspath(__file__))
29-
30-
pprint(MODULES)
31-
32-
COOKIECUTTER_TEMPLATES_DIR = os.path.join(BASE_PATH, "templates")
33-
COOKIECUTTER_TEMPLATES_PREFIX = "terragrunt" #"terraform" # or "terragrunt"
34-
35-
OUTPUT_DIR = "output"
36-
WORK_DIR = "work"
37-
FINAL_DIR = "../final"
38-
39-
if os.environ.get("IS_LOCAL"):
40-
tmp_dir = os.getcwd()
41-
else:
42-
tmp_dir = tempfile.gettempdir() # was /tmp
43-
44-
45-
# Logging snippet was from https://gist.github.com/niranjv/fb95e716151642e8ca553b0e38dd152e
46-
def setup_logging():
47-
logger = logging.getLogger()
48-
for h in logger.handlers:
49-
logger.removeHandler(h)
50-
51-
h = logging.StreamHandler(sys.stdout)
52-
53-
# use whatever format you want here
54-
FORMAT = "[%(levelname)s]\t%(asctime)s.%(msecs)dZ\t%(name)s\t%(message)s\n"
55-
h.setFormatter(logging.Formatter(FORMAT))
56-
logger.addHandler(h)
57-
logger.setLevel(logging.INFO)
58-
59-
return logger
21+
from modulestf.const import *
22+
from modulestf.logger import setup_logging
6023

24+
from modulestf.modules import *
25+
from modulestf.cloudcraft.graph import *
6126

6227
logger = setup_logging()
6328

64-
6529
def render_single_layer(resource, regions, append_id=False):
6630

31+
# logger.info("...")
32+
6733
try:
6834
region = list(regions.keys())[0]
6935
except Exception:
@@ -152,7 +118,7 @@ def load_data(event):
152118
r = requests.get(blueprint_url)
153119
data = r.json()
154120

155-
logging.info("Blueprint url: %s, response code: %s" % (blueprint_url, r.status_code))
121+
logger.info("Blueprint url: %s, response code: %s" % (blueprint_url, r.status_code))
156122

157123
if 403 == r.status_code:
158124
raise ValueError("Sharing has been disabled for this blueprint. You have to enable it by clicking 'Export' -> 'Get shareable link' on https://cloudcraft.co/app/", 403)
@@ -185,6 +151,13 @@ def get_types_text(resources):
185151

186152
return types_text
187153

154+
# filesystem.py
155+
# def mkdir(dir):
156+
# try:
157+
# os.mkdir(dir)
158+
# except OSError:
159+
# pass
160+
188161

189162
def prepare_render_dirs():
190163
output_dir = os.path.join(tmp_dir, OUTPUT_DIR)
@@ -292,7 +265,7 @@ def handler(event, context):
292265
"statusCode": error.args[1],
293266
}
294267

295-
logging.info(pformat(data, indent=2))
268+
logger.info(pformat(data, indent=2))
296269

297270
graph = populate_graph(data)
298271

@@ -314,22 +287,22 @@ def handler(event, context):
314287
"statusCode": 302,
315288
}
316289

317-
318-
if __name__ == "__main__":
319-
test_event = {}
320-
321-
# test_event = {
322-
# "queryStringParameters":
323-
# {
324-
# "cloudcraft": "https://cloudcraft.co/api/blueprint/cd5294fb-0aab-4475-bbcc-196f12738eac?key=5c3EuqRadKOJm3Xkkx-yeQ",
325-
# }
326-
# }
327-
328-
test_event = {
329-
"queryStringParameters":
330-
{
331-
"localfile": "input/blueprint_default.json",
332-
}
333-
}
334-
335-
handler(test_event, None)
290+
# @todo: move to "tests" or remove completely
291+
# if __name__ == "__main__":
292+
# test_event = {}
293+
#
294+
# # test_event = {
295+
# # "queryStringParameters":
296+
# # {
297+
# # "cloudcraft": "https://cloudcraft.co/api/blueprint/cd5294fb-0aab-4475-bbcc-196f12738eac?key=5c3EuqRadKOJm3Xkkx-yeQ",
298+
# # }
299+
# # }
300+
#
301+
# test_event = {
302+
# "queryStringParameters":
303+
# {
304+
# "localfile": "input/blueprint_default.json",
305+
# }
306+
# }
307+
#
308+
# handler(test_event, None)

modulestf/cloudcraft/graph.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@
22

33
from collections import namedtuple
44

5-
Graph = namedtuple('Graph', 'G source regions surfaces')
6-
75

86
def populate_graph(data):
9-
# global source
10-
# global surfaces
11-
# global regions
12-
# global G
7+
8+
Graph = namedtuple('Graph', 'G source regions surfaces')
139

1410
G = nx.Graph() # We can't trust directions of edges, so graph should be not-directional
1511
# MG = nx.Graph() # converted graph to modules.tf schema

modulestf/const.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import os, tempfile
2+
3+
BASE_PATH = os.path.dirname(os.path.abspath(__file__))
4+
5+
COOKIECUTTER_TEMPLATES_DIR = os.path.join(BASE_PATH, "../templates")
6+
7+
COOKIECUTTER_TEMPLATES_PREFIX = "terragrunt" #"terraform" # or "terragrunt"
8+
9+
OUTPUT_DIR = "output"
10+
WORK_DIR = "work"
11+
FINAL_DIR = "../final"
12+
13+
if os.environ.get("IS_LOCAL"):
14+
tmp_dir = os.getcwd()
15+
else:
16+
tmp_dir = tempfile.gettempdir() # was /tmp

0 commit comments

Comments
 (0)