Giter Club home page Giter Club logo

modules.tf-lambda's Introduction

Diagrams to code (d2c) - Infrastructure as code generator - from visual diagrams to Terraform

Financial Contributors on Open Collective MIT license @antonbabenko

modules.tf - Infrastructure as code generator - from visual diagrams to Terraform

Code in this repository is used for generating infrastructure as Terraform configurations from visual diagrams created using Cloudcraft.

How can I try this?

  1. Sign up for a free account with Cloudcraft.
  2. Draw AWS architecture in web-browser (you can import live AWS resources, too).
  3. Click "Export" and "Terraform code export" at the top right side.
  4. Download archive and extract it locally.
  5. Follow step-by-step instructions in README.md which you can find inside of it.

How do the generated Terraform configurations look like?

In modules.tf-demo repository you can see the exact configuration code generated from sample "Web App Reference Architecture".

Original infrastructure

Web App Reference Architecture

Recording of complete code execution

modules.tf demo - November 2019

Supporters

Cloudcraft - the best way to draw AWS diagrams

This project was partially sponsored by Cloudcraft - the best way to draw AWS diagrams.

Become a sponsor to @antonbabenko on GitHub.

@antonbabenko @antonbabenko modules.tf-lambda

Developer's guide

This project is Python 3.8 serverless application written using serverless.tf framework and open-source components (Terraform AWS modules).

Notes for developers

Terraform is used to provision infrastructure resources as well as packaging artifacts and to do the deployments (check out serverless.tf for more details).

Source code is located in src/handler.py.

Go to directory terraform, verify/update file terraform.tfvars and run:

$ terraform init     # Download required Terraform providers and modules
$ terraform apply    # Create or update infrastructure resources or do a new deployment of Lambda function (if source code has changed)

When infrastructure is created, you should be able to POST using httpie or curl like this:

$ http --print Hhb --all --follow https://dev-d2c.modules.tf @test_fixtures/input/blueprint_my.json

Contributors

Code Contributors

This project exists thanks to all the people who contribute.

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

License

This work is licensed under MIT License. See LICENSE for full details.

Copyright (c) 2018-2021 Anton Babenko

modules.tf-lambda's People

Contributors

ahlinc avatar antonbabenko avatar ebahsini avatar k0te avatar monkeywithacupcake avatar snyk-bot avatar tjunnone avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

modules.tf-lambda's Issues

Error occured at runing test_lambda_local.sh

> ./test_lambda_local.sh                                                                                                                                                                          Traceback (most recent call last):
  File "/usr/local/bin/python-lambda-local", line 6, in <module>
    from lambda_local import main
  File "/usr/local/lib/python3.7/site-packages/lambda_local/__init__.py", line 12, in <module>
    from .main import run
  File "/usr/local/lib/python3.7/site-packages/lambda_local/main.py", line 25, in <module>
    urllib3.disable_warnings()
AttributeError: module 'botocore.vendored.requests.packages.urllib3' has no attribute 'disable_warnings'

Implement the same using https://plantuml.com/

For instance using

https://github.com/awslabs/aws-icons-for-plantuml

Describe the solution you'd like

You could do 2 ways

  1. From existing AWS infrastructure to a diagram
  2. From an existing diagram to a corresponding AWS terraform script

You could consider other open source modelling tools like

https://c4model.com/ (which also integrates with plantuml)
https://www.archimatetool.com/

or

https://mermaid-js.github.io/mermaid/#/

Describe alternatives you've considered

Your existing solution however I believe it is better to have this built using open source tools.

Additional context

https://structurizr.com/

https://www.archimatetool.com/resources/

https://engineering.linecorp.com/en/blog/diagramming-software-architecture-using-c4-model-and-c4-plantuml/

Cloud architecture diagrams - C4 model | Simon Brown (3mins)
https://www.youtube.com/watch?v=ALuL9uKqWU4

Visualising software architecture with the C4 model - Simon Brown, Agile on the Beach 2019 (35 mins)
https://www.youtube.com/watch?v=x2-rSnhpw0g

Similar existing tools

https://github.com/GoogleCloudPlatform/terraformer
CLI tool to generate terraform files from existing infrastructure (reverse Terraform). Infrastructure to Code

https://github.com/dtan4/terraforming
Export existing AWS resources to Terraform style (tf, tfstate)

https://former2.com/
https://github.com/iann0036/former2
Generate CloudFormation / Terraform / Troposphere templates from your existing AWS resources.

multiple ec2s getting "var.subnet_ids is empty list of string"

Describe the bug

Receiving this error on multiple ec2s before the build fails:

Error: Error in function call

  on main.tf line 12, in resource "aws_instance" "this":
  12:   subnet_id = length(var.network_interface) > 0 ? null : element(
  13:     distinct(compact(concat([var.subnet_id], var.subnet_ids))),
  14:     count.index,
  15:   )
    |----------------
    | count.index is 0
    | var.subnet_id is ""
    | var.subnet_ids is empty list of string

Call to function "element" failed: cannot use element function with an empty
list.

Releasing state lock. This may take a few moments...

-----BEGIN PGP MESSAGE-----
Version: Keybase OpenPGP v2.1.13
Comment: https://keybase.io/crypto

wcFMAxWeMqYOPYuBAQ//biL5BcqYVj+IirR88sspCQNnCBT3ImaQ55Vo6dtf/96c
yYc3JNnFtOEtTmrcf8ZpGvPe6ITtRIpuRLtDL9Yd/1zfBgX4tw2YZPny+QVHKvt2
CLLFLasS8MZNvQzv13NXPVo99t9tsGCvKFssZHHxXDy7VBjW0qhdU1pNIalwkv6x
svbTsoJrLyu1wbNy691ZkmjvxXSdFeA01gys4x2qJi7v1NcMqJgO6WN4KVJigWm/
zWqfvJfW2gRJzOH/KOEQZletApOAqq/JtDT14f82JlDwxh6MmwKDO+8mc3wsjR6p
8dkNMklMOGeBtZGD69jaEX4U3ogmL6YNsJs4v+lQkMJfCDTGCmxAW/We2Wp1NgyD
iLdkxMANRA17JnaqRNKl4IjUJ0JsqfgcROKlV3LfvoXDoyCnMibWpGsVdyzKKJMY
JSaLBXyEwtnt5Cou1ZzM7wMSLXCeik6a8XeW/fCbQb/OkKRbA7FgxzTgcxJ+80AB
8xHbLVYW/J6ZOW6nJXyBBl6YL5tPZw8Ox8lD8366s8xOLkWcEdPQG3FMAAekUo+5
gd9qolZ0AzJtK6Nb+V4ryeqWPjnbEUDNLwN7gFNR0/lZ2po1PHcxcP8hqtGLBEGd
Qj2ILX83S+uysN5beyHaWkSqOMOv8v8LDMVdAyB5DfudIKNHI9NdeLxlpHwH+LTS
mgEUATjwkT3bqgL0KdgAy3nL4Xjx9RZC4Ur7/Gkuu6on4XM8vnbyu7FXG9IpkGdr
FJzfEEeXmnkSPDeTC02JknyPVUx0R5Wob1ECHNJUJuvS1gDqK38kpYrj9EuEio9L
9DErJP6u0SPtksmlzJaQuw7khZ93+3dssGAmFb/POpCvhIc+3KXC5iT/0hZMZngf
Omb1BkXHx9yfi8w=
=AMYJ
-----END PGP MESSAGE-----

Expected behavior

After exporting my project to tf and installing dependencies, expected a successful build

Actual behavior

Build failure

Names with special chars

Describe the bug

function_name = "Lambda 
Microservices"

image

if name has new line it has error during run:

Invalid multi-line string; Quoted strings may not be split over multiple lines. To produce a multi-line string, either use the \n escape to represent a newline character or use the "heredoc" multi-line template syntax., and 1 other diagnostic(s) 
ERRO[0000] Unable to determine underlying exit code, so Terragrunt will exit with error code 1

Expected behavior

Remove specials cachers from the name

Actual behavior

Error

Implement validation flow before rendering

Validation flow:

  • Once a user clicks “Export as Terraform code”, POST to endpoint “/validate” and JSON (with comments, severity, and recommendations) is returned.
  • Show scrollable text block with actual comments and recommendations in modal
  • Add two buttons to modal - “Edit” and “Download archive”
  • Start with single "error" to try out UI

Examples of JSON responses from modules.tf /validate endpoint:

When there are errors:

{
"comments": [
  {"severity": "INFO", "text": "Network load-balancer does not have Terraform module yet, and it will not be exported"},
  {"severity": "ERROR", "text": "VPC 'vpcname' can't span across multiple regions (eu-west-1, eu-west-2, us-east-1). VPC can be only in one region."},
  {"severity": "ERROR", "text": "VPC 'vpcname' and resources it contains should be in the same region."}
],
"summary": "Please correct blueprint and try again",
"valid": false
}

When success:

{
"comments": [
  {"severity": "INFO", "text": "Network load-balancer does not have Terraform module yet, and it will not be exported"},
],
"summary": "Validation passed",
"valid": true
}

Description:

  1. If there is at least one hard-failure valid is set to false. This means the user can't see the "Continue" button and get zip-archive.
  2. summary - is a human-friendly text to show.
  3. comments - is a list of severity and text.

filter_criteria with SQS

Describe the bug

We are trying to add a Filter_criteria to the lambda function and did not get code anywhere. we tried our own and it is showing syntax error or some other. Could you please help me with some examples?

Expected behavior

A clear and concise description of what you expected to happen.

Actual behavior

A clear and concise description of what has happened.

Additional context

Add any other context about the problem here.

S3 bucket name error

Describe the bug

aws_s3_bucket.this[0]: Creating...
╷
│ Error: Error validating S3 bucket name: only lowercase alphanumeric characters and hyphens allowed in "s3_bucket_deployments"
│ 
│   with aws_s3_bucket.this[0],

Transformer modules Git clone issue

The current implementation needs to add SSH_Keys to the Git. It is additional configuration.

Change of all source properties in .hcl files
from:

terraform {
source = "git::[email protected]:terraform-aws-modules/terraform-aws-autoscaling.git?ref=v3.4.0"
to:
source = "git::https://github.com/terraform-aws-modules/terraform-aws-autoscaling.git?ref=v3.4.0"
}

fixes this problem

Maybe it is possible to use https as the default git method?

Filter_criteria

Is your feature request related to a problem? Please describe.

We are trying to add a Filter_criteria to the lambda function and did not get code anywhere. Could you please help me with some examples?

Describe the solution you'd like

expected some example code

Describe alternatives you've considered

A clear and concise description of any alternative solutions or features you've considered.

Additional context

Add any other context or screenshots about the feature request here.

Security group rules are not transcripted correctly from Cloudcraft to HCL files

Describe the bug

I declare some simple security groups (ex: allow tcp traffic on 80,443 from ALB to EC2), and I get this after export via modules.tf:

terraform {
  source = "git::[email protected]:terraform-aws-modules/terraform-aws-security-group.git?ref=v3.4.0"
}

include {
  path = find_in_parent_folders()
}

dependencies {
  paths = ["../courbet-vpc"]
}

dependency "courbet-vpc" {
  config_path = "../courbet-vpc"
}

###########################################################
# View all available inputs for this module:
# https://registry.terraform.io/modules/terraform-aws-modules/security-group/aws/3.4.0?tab=inputs
###########################################################
inputs = {
  # List of IPv4 CIDR ranges to use on all ingress rules
  # type: list(string)
  ingress_cidr_blocks = ["0.0.0.0/0"]

  # List of ingress rules to create by name
  # type: list(string)
  ingress_rules = ["all-all"]

  # Name of security group
  # type: string
  name = "elb-to-ec2-sg"

  # ID of the VPC where to create security group
  # type: string
  vpc_id = dependency.courbet-vpc.outputs.vpc_id

  
}

Which is not corresponding to my rules declared in Cloudcraft:

DeepinScreenshot_select-area_20200803155217

Expected behavior

I think the expected output is something like (not sure about syntax):

// ...
inputs = {
  ingress_with_source_security_group_id = ["frontend-lb-sg"]
  ingress_rules = ["http-80", "https-443"]

  # Name of security group
  # type: string
  name = "elb-to-ec2-sg"

  # ID of the VPC where to create security group
  # type: string
  vpc_id = dependency.courbet-vpc.outputs.vpc_id

  
}

Actual behavior

Actually, all security groups generated allows all traffic on all ports

Load Balancer target groups based on Cloudcraft "Edge" component

Is your feature request related to a problem? Please describe.

It would be nice to define load balancer target groups based on drawing an "Edge" component between AWS Load Balancers and an EC2 instance, for example.

Describe the solution you'd like

When a User connects a Load Balancer to an EC2 instance, the exported terraform configuration would represent that connection as a "target group" or "target group attachment", depending on the Load Balancer configuration.

https://www.terraform.io/docs/providers/aws/d/lb_target_group.html
https://www.terraform.io/docs/providers/aws/r/lb_target_group_attachment.html

Describe alternatives you've considered

  • Manual target groups
  • CLI post deployment
  • Not using Terraform, export to AWS CDK / SDK

Additional context

Cloudcraft JSON representation of an "elb" with an Edge component connecting to an "ec2"

{
  "nodes": [
    {
      "type": "elb",
      "id": "c2d0d77d-4627-470b-b1c3-553eac59d141",
      "mapPos": [
        5,
        11
      ],
      "region": "us-east-1",
      "color": {
        "isometric": "#ececed",
        "2d": "#693cc5"
      },
      "accentColor": {
        "isometric": "#4286c5",
        "2d": "#ffffff"
      },
      "elbType": "classic",
      "lcu": 1,
      "dataGb": 10
    },
    {
      "type": "ec2",
      "id": "e39584f4-208a-472d-a99d-7e963faa7867",
      "mapPos": [
        5,
        5
      ],
      "region": "us-east-1",
      "transparent": false,
      "platform": "linux",
      "instanceType": "m5",
      "instanceSize": "24xlarge",
      "color": {
        "isometric": "#ececed",
        "2d": "#d86613"
      },
      "accentColor": {
        "isometric": "#4286c5",
        "2d": "#d86613"
      },
      "billingOptions": {
        "type": "ri",
        "utilization": 1,
        "leaseContractLength": 36,
        "purchaseOption": "All Upfront",
        "offeringClass": "standard"
      }
    }
  ],
  "edges": [
    {
      "type": "edge",
      "from": "c2d0d77d-4627-470b-b1c3-553eac59d141",
      "to": "e39584f4-208a-472d-a99d-7e963faa7867",
      "width": 2,
      "color": {
        "isometric": "#000000",
        "2d": "#000000"
      },
      "dashed": false,
      "endCap": "arrow"
    }
  ],
  "boundingRect": {
    "x": 5,
    "y": 5,
    "width": 1,
    "height": 7
  }
}

script randomly overwrites the whole content

Describe the bug

The "update_dynamic_values_in_tfvars.sh" script randomly overwrites the whole content of the "terraform.tfvars" files. I have updated the script bash like this:

#!/bin/bash

############################
# This script is used by Terragrunt hook to find and replace references in terraform.tfvars with the real values fetched using `terragrunt output`
############################
# 1. check if this script has not been disabled using special flag (@modulestf:disable_values_updates)
# 2. get list of things to replace
# 3. go through the list of things to replace
# 4. get actual value
# 5. replace value in terraform.tfvars:
#   a. When `to_list` is specified the type of the value will be converted to a list - ["sg-1234"]

# @todo:
# 1. Get values from other sources:
# - data sources generic
# - aws_account_id or aws_region data sources
# 2. terragrunt_outputs from stacks:
# - in any folder
# - in current region
# 3. cache values unless stack is changed/updated
# 4. functions (limit(2), to_list)
# 5. rewrite in go (invoke like this => update_dynamic_values_in_tfvars ${get_parent_tfvars_dir()}/${path_relative_to_include()})
# 6. make it much faster, less verbose

# Syntax:
# @modulestf:terragrunt_output.security-group_5.this_security_group_id.to_list
# @modulestf:terragrunt_output.["eu-west-1/security-group_5"].this_security_group_id.to_list
# @modulestf:terragrunt_output.["global/route53-zones"].zone_id
# @modulestf:terragrunt_data.aws_region.zone_id
# @modulestf:terragrunt_data.aws_region[{current=true}].zone_id

############################

readonly tfvars_file="$1/terraform.tfvars"
readonly parent_dir="$1/../"
readonly terragrunt_working_dir=$(dirname "$(find "$1/.terragrunt-cache" -type d -name ".terraform")")

echo "parent_dir=$parent_dir"
echo "TERRAGRUNT_WORKING_DIR=$terragrunt_working_dir"

readonly modulestf_disable_values_updates_flag="@modulestf:disable_values_updates"
readonly modulestf_terraform_output_prefix="@modulestf:terraform_output"

############################

if grep -q "$modulestf_disable_values_updates_flag" "$tfvars_file"; then
  echo "Dynamic update has been disabled in terraform.tfvars"
  exit 0
fi

# Sample keys:
# @modulestf:terraform_output.security-group_5.this_security_group_id          - the type of the value will not be modified
# @modulestf:terraform_output.security-group_5.this_security_group_id.to_list  - the type of the value will be converted to list
IFS=" " read -r -a keys_to_replace <<< "$(grep -oh "$modulestf_terraform_output_prefix\.[^ ]*" "$tfvars_file" | sort | uniq)"

for key_to_replace in "${keys_to_replace[@]}"; do
  dir_name=$(cut -d "." -f 2 <<< "$key_to_replace")
  output_name=$(cut -d "." -f 3 <<< "$key_to_replace")
  convert_to_type=$(cut -d "." -f 4 <<< "$key_to_replace")

  cd "${parent_dir}/${dir_name}" || return

  item=$(terragrunt output -json "$output_name")
  exit_code=$?

  if [[ "$exit_code" != "0" ]]; then
    echo "Can't update value of $key_to_replace in $tfvars_file because key $output_name does not exist in output"
    continue
  fi

  item_type=$(echo "$item" | jq -rc ".type")
  item_value=$(echo "$item" | jq -rc ".value")

  if [[ "$item_type" == "string" ]]; then
    item_value="\"$item_value\""
  fi

  if [[ "$convert_to_type" == "to_list" ]]; then
    item_value="[$item_value]"
  fi

  echo "Updating value of $key_to_replace with $item_value in $tfvars_file"

#  set -x # print command: on

  sed -i -r "s|^(.+) =.+(\#)+(.*)${key_to_replace}(.*)|\1 = ${item_value} \2\3${key_to_replace}\4|g" "$tfvars_file"

#  set +x # print command: off

  echo "Copying updated $tfvars_file into $terragrunt_working_dir"

  \cp -f "$tfvars_file" "$terragrunt_working_dir"

done

What do you think about it?

Multiregion diagram generates code in one region

Describe the bug

The export places all resources in the same region even though the two VPC's are drawn in different regions

-----BEGIN PGP MESSAGE-----
Version: Keybase OpenPGP v2.1.13
Comment: https://keybase.io/crypto

wcFMAxWeMqYOPYuBAQ/+IpPbtkKQDNCuiopjzh+x91BjmtcwpQGojgRLAvb2Y8jk
Z6WBoyM/AQ+AAVhuJBzlJW/nJisZB9k5soqyEQ7RpDTZPQX9h1xRqZ6Gy36I/TUE
cz4W8lNeJjiuUCGaLY370EHcjlj4fmAddevASTQBLCMstESfXY2WC7t8P9KMirAQ
8TG5oeJUDV92WlLu+YrXU8VTcqXNe3HovRo6oeH4eLIVuKTb9WiXolZ9svsMMLbg
0GygTq3YZzl5n8ec22OXd3RfMem8j+QBZJP6BBfeJ+axImGpvhpxdqbSn/yNUhdV
/RUadGdcJGbxjPYLY27KxTbIsjGSxligXLaJgX+tPjOQrPn9YI5TE2l+J8Hzi51C
2Ks6RWrhxc7y1ncjf0W6EV+SOYtzhq70XBbKnfe4JwFreij5gxyCiJkjOammE0/p
A87/xGFdh74agJnkCAFe/B9FqaeY9WWBzjs7uAWZuDRWp4C3mvLkRwVNwL+zVmRH
JCh3I/qFyfDKVxayuwx9iBrII28GO0nDouj8fEyfWXsGnQvVT3ENW4H4jbQZkThJ
viIkP4x/X081ngzEP9PFlYxsYLYK5XSwTzHFv6rkqbeGk4bltG9qWE+1S9a5hadw
pZlMKbcLCZtoh7Y2HfVMZUAmd4A7V86iCfrgpK0lrzdA++tPSl3cFbbYxTH0jxDS
lAHbPGKLyGN1wQJEGAC6qNNm23TPO1KvNwUduBbj4IPhPFb6lp40G+nedB/58vAI
IIXTmupsedLw1zO2W45lY1BsB+pUmWt2afqSmqUcBn3KqeLOH6Rxrm3IkFiFyEzU
k6fvEa8cmywjH9jlvg/RAQBnN7dltY0Bnlz6Y6hKMJub31ojAplcOwQvYsbZmfnk
b8JvJWc=
=+I1F
-----END PGP MESSAGE-----

terragrunt init failed

Describe the bug

Using git bash in Windows machine and try to do terragrunt init

Expected behavior

It should not fail but get the following,

provider "aws": failed to create .terraform\plugins\windows_amd64\terraform-provider-aws_v2.57.0_x4.exe: open .terraform\plugins\windows_amd64\terraform-provider-aws_v2.57.0_x4.exe: The system cannot find the path specified..

PLUGIN cahce dir defined as:
TF_PLUGIN_CACHE_DIR=c:/Users/louie.kwan/.terraform.d/plugin-cache

Actual behavior

2020/04/14 22:16:57 [DEBUG] installing aws 2.57.0 to .terraform\plugins\windows_amd64\terraform-provider-aws_v2.57.0_x4.exe from local cache c:\Users\louie.kwan.terraform.d\plugin-cache\windows_amd64\terraform-provider-aws_v2.57.0_x4.exe

Error installing provider "aws": failed to create .terraform\plugins\windows_amd64\terraform-provider-aws_v2.57.0_x4.exe: open .terraform\plugins\windows_amd64\terraform-provider-aws_v2.57.0_x4.exe: The system cannot find the path specified..

Terraform analyses the configuration and state and automatically downloads
plugins for the providers used. However, when attempting to download this
plugin an unexpected error occurred.

This may be caused if for some reason Terraform is unable to reach the
plugin repository. The repository may be unreachable if access is blocked
by a firewall.

If automatic installation is not possible or desirable in your environment,
you may alternatively manually install plugins by downloading a suitable
distribution package and placing the plugin's executable file in the
following directory:
terraform.d/plugins/windows_amd64

Error: failed to create .terraform\plugins\windows_amd64\terraform-provider-aws_v2.57.0_x4.exe: open .terraform\plugins\windows_amd64\terraform-provider-aws_v2.57.0_x4.exe: The system cannot find the path specified.

Additional context

Any help is much appreciated.

Is this project dead?

I think this project is brilliant.
But since cloudcraft has dropped "Terraform code export" how does one use it?
Are there any plans to be able to use other drawing tools instead?

Set folder names matching names of components on diagram

Is your feature request related to a problem? Please describe.

Names of folders are confusing - rds_1, security-group_1...

Describe the solution you'd like

Use names from components, replace strange characters with single _

Additional context

cloudcraft-proposal-naming

ALB does not set subnet properly

Describe the bug

#28 (comment)

ALB belongs to VPC, but the subnets argument does not seem to set.

{
  "id": "f8abab63-0007-4ea2-8ea8-b9186d3259f1",
  "data": {
    "grid": "standard",
    "name": "test2",
    "text": [
      {
        "id": "91b7110b-90cb-4d34-83fc-8a55c95bd393",
        "text": "Auto Scaling",
        "type": "isotext",
        "color": {
          "2d": "#f5b720",
          "isometric": "#ffffff"
        },
        "mapPos": {
          "relTo": "cf8dd975-3e12-47b4-89b1-7f6aee0d0f26",
          "offset": [
            -0.18000000000000016,
            1.1399999999999997
          ]
        },
        "outline": true,
        "standing": false,
        "textSize": 25,
        "direction": "down",
        "isometric": true
      },
      {
        "id": "d5ed2357-f83c-4811-a67e-7d9e530da451",
        "text": "ELB",
        "type": "isotext",
        "color": {
          "2d": "#f5b720",
          "isometric": "#ffffff"
        },
        "mapPos": {
          "relTo": "38913a77-d1a8-46d9-a013-519264b0d4c9",
          "offset": [
            0.125,
            1
          ]
        },
        "outline": true,
        "standing": false,
        "textSize": 25,
        "direction": "down",
        "isometric": true
      }
    ],
    "edges": [
      {
        "to": "e3d78548-758d-4711-9de0-b17de0dc768f",
        "from": "38913a77-d1a8-46d9-a013-519264b0d4c9",
        "type": "edge",
        "color": {
          "2d": "#000000",
          "isometric": "#000000"
        },
        "width": 2,
        "dashed": false,
        "endCap": "arrow"
      }
    ],
    "icons": [],
    "nodes": [
      {
        "id": "e3d78548-758d-4711-9de0-b17de0dc768f",
        "type": "ec2",
        "color": {
          "2d": "#d86613",
          "isometric": "#ececed"
        },
        "mapPos": [
          4,
          6.25
        ],
        "region": "us-west-1",
        "platform": "linux",
        "accentColor": {
          "2d": "#d86613",
          "isometric": "#f44336"
        },
        "transparent": false,
        "instanceSize": "xlarge",
        "instanceType": "c5",
        "billingOptions": {
          "type": "od",
          "utilization": 1
        }
      },
      {
        "id": "38913a77-d1a8-46d9-a013-519264b0d4c9",
        "lcu": 1,
        "type": "elb",
        "color": {
          "2d": "#693cc5",
          "isometric": "#ececed"
        },
        "dataGb": 10,
        "mapPos": [
          4,
          9
        ],
        "region": "us-west-1",
        "elbType": "application",
        "accentColor": {
          "2d": "#ffffff",
          "isometric": "#4286c5"
        }
      }
    ],
    "groups": [
      {
        "id": "cf8dd975-3e12-47b4-89b1-7f6aee0d0f26",
        "type": "asg",
        "color": {
          "2d": "#f5b720",
          "isometric": "#f44336"
        },
        "nodes": [
          "e3d78548-758d-4711-9de0-b17de0dc768f"
        ],
        "layout": "even",
        "mapPos": [
          3.5,
          6.25
        ],
        "region": "us-west-1",
        "mapSize": [
          2,
          1
        ]
      },
      {
        "id": "d47e0440-653f-4d94-93d5-ad65c7dfa52f",
        "name": "vpc",
        "type": "vpc",
        "color": {
          "2d": "#3f51b5",
          "isometric": "#3f51b5"
        },
        "nodes": [
          "38913a77-d1a8-46d9-a013-519264b0d4c9",
          "e3d78548-758d-4711-9de0-b17de0dc768f"
        ],
        "shape": "dynamic",
        "region": "us-west-1",
        "padding": 1.5,
        "peeringConnections": []
      }
    ],
    "images": [],
    "linkKey": "iBtyR4AsIr9jWfy-sJARUg",
    "version": 1,
    "surfaces": [],
    "shareDocs": false,
    "connectors": [],
    "projection": "isometric",
    "disabledLayers": []
  },
  "readAccess": null,
  "writeAccess": null,
  "createdAt": "2020-05-06T08:19:31.982Z",
  "updatedAt": "2020-05-06T08:22:40.607Z",
  "CreatorId": "0cfaaa28-bd74-42f7-a6f5-4f78c91ab92e",
  "LastUserId": "0cfaaa28-bd74-42f7-a6f5-4f78c91ab92e"
}

How to make all this more extendable?

Thanks for spending your time helping with the reviewal of Python code in this project!

handler.py has function handler which is invoked by AWS Lambda via API Gateway.

Currently this project implements:

  • convert Cloudcraft json blueprint into modules.tf-schema
  • convert modules.tf-schema into Terragrunt code

I am working on adding support for extension or ways to expand this project, for example:

  • convert modules.tf-schema into Terraform code (in addition to Terragrunt)
  • support other formats as inputs (now only Cloudcraft json is supported)

While doing this I feel that I can do it and will spend a lot of time, so I am looking for some advice/help (in no specific order):

  1. handler now has a linear flow, but it will not be so always. How can I split handler.py into several smaller files and include them conditionally (eg, generate/terraform.py and generate/terragrunt.py) instead of calling render_terraform_from_modulestf_config or render_terragrunt_from_modulestf_config? Does it make sense to add OOP / Proxy pattern, or is there another more pythoniс way?
  2. Does it make sense to split handler.py into several smaller files at this point? Now the function generate_modulestf_config implements a single interface (Cloudcraft), but I want it to implement different also, and have smaller files.
  3. How would you recommend to test this? I do run this with different arguments, but it is not automated more than that.

Please think about this and try to give me an advice for so called "the lowest hanging fruit".

Thank you!

Incomplete edges in input json leads to a failure in rendering

Sometimes there are incomplete edges in input json, which can be contracted in the graph.

ValueError: Edge ('16310948-04c7-4842-9c02-aa5a54616a40', 'a1a904b3-556e-4220-9812-011e1bbd2dfc') does not exist in graph G; cannot contract it

ValueError
Traceback (most recent call last):
  File "/var/task/handler.py", line 76, in handler
    graph = populate_graph(data)
  File "/var/task/modulestf/cloudcraft/graph.py", line 94, in populate_graph
    G = nx.contracted_edge(G, (edge[0], edge[1]), self_loops=False)
  File "/var/task/networkx/algorithms/minors.py", line 452, in contracted_edge
    ' it'.format(edge))

Expected behavior

Fail with proper error, so that user knows that input json was badly formatted.

Actual behavior

Nothing, 500 error returned to a user.

Additional context

This happens very-very seldom, so minor priority.

Terragrunt Aplly-ALL doesnt work multiple errors

[terragrunt] [/home/genaker/Downloads/Magento-Terraform-Infrastructure(3)/magento-terraform-infrastructure/us-west-1/mysql-master-rds] 2020/03/24 22:18:39 Running command: terraform apply -input=false -input=false -auto-approve
module.db_instance.data.aws_iam_policy_document.enhanced_monitoring: Refreshing state...

Error: first character of "name_prefix" must be a letter

  on modules/db_option_group/main.tf line 1, in resource "aws_db_option_group" "this":
   1: resource "aws_db_option_group" "this" {



Error: only alphanumeric characters and hyphens allowed in "name_prefix"

  on modules/db_option_group/main.tf line 1, in resource "aws_db_option_group" "this":
   1: resource "aws_db_option_group" "this" {



Error: only lowercase alphanumeric characters and hyphens allowed in parameter group "name_prefix"

  on modules/db_parameter_group/main.tf line 33, in resource "aws_db_parameter_group" "this":
  33: resource "aws_db_parameter_group" "this" {



Error: first character of parameter group "name_prefix" must be a letter

  on modules/db_parameter_group/main.tf line 33, in resource "aws_db_parameter_group" "this":
  33: resource "aws_db_parameter_group" "this" {


aws_lb.this[0]: Creating...
[terragrunt] [/home/genaker/Downloads/Magento-Terraform-Infrastructure(3)/magento-terraform-infrastructure/us-west-1/mysql-master-rds] 2020/03/24 22:18:43 Module /home/genaker/Downloads/Magento-Terraform-Infrastructure(3)/magento-terraform-infrastructure/us-west-1/mysql-master-rds has finished with an error: Hit multiple errors:
exit status 1

Error: Error creating application Load Balancer: ValidationError: At least two subnets in two different Availability Zones must be specified
	status code: 400, request id: bee0f9bb-e951-41f9-9ea0-969803b89e32

  on main.tf line 1, in resource "aws_lb" "this":
   1: resource "aws_lb" "this" {

Security Group doesn't have default egress/outbound rules.

Describe the bug

The instance doesn't have an internet connection. No egress/outbound rules

FIX set default all egress:

  # Default CIDR blocks, which will be used for all egress rules in this module. Typically these are CIDR blocks of the VPC.
  # If this is not specified then no CIDR blocks will be use
  egress_cidr_blocks = ["0.0.0.0/0"]
  
  # Prefix list ids to use in all egress rules in this module.
  # egress_prefix_list_ids = ["pl-123456"]
  # Open for all CIDRs defined in egress_cidr_blocks
  egress_rules = ["all-all"]

Failed to create dir when name has only invalid chars

Describe the bug

When the project name is empty or containing wrong chars, it can't create a working directory:

[Errno 30] Read-only file system: '/eu-west-1'"

Blueprint:

{"id":"...","readAccess":null,"writeAccess":null,"data":{"version":1,"name":"?????",
...

Hook seed error

##The dynamic update for the values don't work

The seeding of the dynamic value in the terraform.tfvars don't work.
See the image below.

Schermata 2019-05-03 alle 20 37 22

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.