awslabs / diagram-as-code

Diagram-as-code for AWS architecture.
Apache License 2.0
392 stars 22 forks source link

Generate diagrams from CF templates #9

Open moltar opened 3 months ago

moltar commented 3 months ago

Would it be possible to generate diagrams from the templates?

Perhaps could use tags for things that CF does not support directly.

And then can use resource properties to infer some of the information for the diagrams (e.g. titles).

This would then be great for use with CDK, where resources can be defined and tagged in code, and then a template is generated and then a diagram is generated from that.

ugwis commented 3 months ago

Thank you for creating issue!

Currently, it is not supported, but it is within our scope. There are a few challenges we will need to overcome in order to achieve this:

To give some background, I have dozens of CloudFormation templates and created this tool to generate diagrams for these templates. It seems that many users are looking forward to generation from CloudFormation templates, so I would be happy if I could contribute with this tool.

ugwis commented 1 month ago

First, we have taken a step towards solving this issue. Added the --cfn-template flag to the awsdac command. If you specify the flag, awsdac reads the YAML file as a CloudFormation template and generates an architecture diagram. Thanks, @a2ush, for your hard work on this issue. Please refer example diagram generated from CloudFormation template. README.md#beta-create-a-diagram-from-cloudformation-template

However, not all CloudFormation templates can generate diagrams. The three issues mentioned above are not fully resolved and are only partial resolutions. We also confirmed that since CloudFormation templates are not a notation designed for generating diagrams, there are patterns that cannot be generated, depending on the template. Furthermore, the kind of diagrams a user prefers depends on the user’s purpose. We will continue to improve the way we generate diagrams from CloudFormation templates, but it is not a tool that will meet the needs of all users (we have yet to see the potential of Generative AI). Also, please note that we will not be able to maintain backward compatibility for diagrams generated from CloudFormation templates as we work toward better drawing.

Therefore, we recommend using the --dac-file flag to convert the CloudFormation template to the DaC syntax and generate the diagram from DaC syntax, especially if you want to keep backward compatibility with diagrams generated on CI/CD. We will keep backward compatibility with the DaC syntax (starts with Diagram:) as much as possible.

# Convert CFn template to DaC syntax(output.yaml)
$ awsdac cloudformation.yaml --cfn-template --dac-file
[Done] DAC (diagram as code) data has been written to the output.yaml
[Done] The AWS infrastructure diagram has been generated: output.png

# Rearrange resources from your diagram or remove unnecessary resources.
$ edit output.yaml

# Regenerate diagrams
$ awsdac output.yaml -o output.png

Please note that the implementation task in the metadata section of DaC attributes in a CloudFormation template is currently a low priority, as the feature will not be backward compatible for some time. However, we are actively working on improving drawings and will provide updates as soon as we can. In the meantime, we recommend that you customize them by outputting them in the --dac-file format. This will allow you to keep compatibility with your existing diagrams. For more information, please refer to CFn related issues for additional issues related to generating from CloudFormation templates.