05 Enterprise administration and integrations · Advanced

Import a data flow diagram from code

Turn an OpenAPI spec, a CloudFormation template or Terraform into a data flow diagram, review it, and build on it.

Enterprise Lesson 6 of 8 4 min Updated

In this lesson you will learn

  • Which formats you can import
  • What each format turns into
  • How to review the result before it's created

Start from what the code already says

Your infrastructure code and API specs already describe the system. Importing them gives you a first data flow diagram in seconds, with the right element types and trust boundaries, ready to review and threat model.

Steps

  1. Open the import

    On the forest page, click Import from code. Upload a file or paste it in: an OpenAPI 3 or Swagger 2 spec, a CloudFormation or SAM template, or Terraform (.tf files or terraform show -json output). The format is detected automatically.

  2. Review the preview

    Click Preview. You see the diagram and every element it will create. An OpenAPI spec becomes an API consumers entity, the API as a trust boundary with a process per tag, and data flows listing methods, endpoint counts, unauthenticated endpoints and plain-HTTP servers. Cloud templates become cloud elements inside their network boundaries. Untick anything you don't want, name the diagram and click Create diagram.

    ThreatTree's Import a DFD from code preview for a Card controls API OpenAPI spec: a diagram with API consumers, an identity provider and Cards, Health and Payments processes inside the API boundary, a note that the spec describes only the API surface, and the list of elements to create.
    An OpenAPI spec previewed as a diagram before anything is created.
  3. Fill in what code can't show

    A spec describes the API surface, not what sits behind it. Add the data stores and downstream services by hand, then generate attack trees as usual.

Catch drift in CI. Through the API, an import can be compared with an existing diagram, so a pipeline can flag when the infrastructure no longer matches the threat model.

Practice

Try it

Import your service's OpenAPI spec or Terraform, untick anything you don't own, create the diagram, then generate attack trees from it.

This lesson covers Enterprise features. Not on Enterprise yet? Talk to us about Enterprise.

Open My Forests

Quiz

Check what you learned

Three quick questions. Your answers stay in this browser.

1 Which formats can you import?
2 Is the diagram created as soon as you paste the file?
3 What does an OpenAPI import call out?