# datadog/terraform-aws-ecs-datadog architecture

> Architecture diagram of the GitHub repository datadog/terraform-aws-ecs-datadog, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/datadog/terraform-aws-ecs-datadog
- Repository: https://github.com/datadog/terraform-aws-ecs-datadog

## Overview

##### Project type and purpose
- This is a Terraform‐based IaC (Infrastructure as Code) project providing reusable modules to instrument AWS ECS Fargate tasks with Datadog monitoring.
- The README confirms it wraps aws_ecs_task_definition and injects Datadog configuration (API key, tags, sidecar containers, IAM roles, etc.) automatically.

##### File structure
- Top level:
- modules/ecs_fargate – the core module, containing Terraform code (main.tf, iam.tf, datadog.tf, variables.tf, outputs.tf)
- examples/ecs_fargate – a usage example demonstrating how to call the module in consumer Terraform code
- smoke_tests – Terraform configs that validate various input combinations
- tests – Go test suite invoking a Terraform test harness (coverage of inputs, outputs, role parsing)
- CI/config: .github/workflows, .gitlab-ci.yml, pre-commit, terraform-docs, Makefile – standard pipeline, formatting, documentation generation.

##### Key insights from README
- Purpose: “install Datadog monitoring for AWS Elastic Container Service tasks.”
- Usage pattern: call module, supply dd_api_key_secret, dd_tags, family, container_definitions.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Terraform Consumer Code
    subgraph "Consumer Terraform Code" 
        direction TB
        CT_MAIN["main.tf"]:::terraform
        CT_VARS["variables.tf"]:::terraform
        CT_OUT["outputs.tf"]:::terraform
        CT_VER["versions.tf"]:::terraform
    end

    %% ECS Fargate Module
    subgraph "ecs_fargate Module" 
        direction TB
        MOD_MAIN["main.tf"]:::terraform
        MOD_DATADOG["datadog.tf"]:::terraform
        MOD_IAM["iam.tf"]:::terraform
        MOD_VARS["variables.tf"]:::terraform
        MOD_OUT["outputs.tf"]:::terraform
        MOD_VER["versions.tf"]:::terraform
        MOD_README["README.md"]:::terraform
        MOD_MAKE["Makefile"]:::terraform
    end

    %% Terraform CLI and Provider
    TF_CLI["Terraform CLI"]:::terraform
    AWS_PROVIDER["AWS Provider Plugin"]:::aws

    %% AWS Resources
    subgraph "AWS Resources" 
        direction TB
        ECS_TASK["ECS Fargate Task Definition"]:::aws
        IAM_ROLE["IAM Role & Policies"]:::aws
        SECRETS["Secrets Manager"]:::aws
    end

    %% External Service
    DATADOG["Datadog API/Agent"]:::external

    %% CI/CD Pipeline
    subgraph "CI/CD Pipeline" 
        direction TB
        GH_FMT[".github/workflows/terraform-fmt.yaml"]:::ci
        GH_DOCS[".github/workflows/terraform-docs.yaml"]:::ci
        GH_PRE[".github/workflows/pre-commit.yaml"]:::ci
        GL_CI[".gitlab-ci.yml"]:::ci
        PC_CFG[".pre-commit-config.yaml"]:::ci
        TD_CFG[".terraform-docs.yml"]:::ci
        MAKE["Makefile"]:::ci
    end

    %% Tests
    subgraph "Tests & Smoke Tests"
        direction TB
        SMOKE["smoke_tests/*.tf"]:::test
        GO_TESTS["tests/*.go"]:::test
    end

    %% Connections
    CT_MAIN -->|"imports"| MOD_MAIN
    CT_VARS --> MOD_VARS
    CT_OUT --> MOD_OUT
    CT_VER --> MOD_VER

    SMOKE -->|"validates module"| MOD_MAIN
    GO_TESTS -->|"executes plan against"| MOD_MAIN

    MOD_MAIN --> TF_CLI
    TF_CLI --> AWS_PROVIDER
    AWS_PROVIDER --> ECS_TASK
    AWS_PROVIDER --> IAM_ROLE
    AWS_PROVIDER --> SECRETS

    ECS_TASK -->|"emits metrics"| DATADOG

    GH_FMT --> MOD_MAIN
    GH_DOCS --> MOD_README
    GH_PRE --> MOD_MAIN
    GL_CI --> MOD_MAIN
    PC_CFG --> MOD_MAIN
    TD_CFG --> MOD_README
    MAKE --> MOD_MAIN

    %% Click Events
    click CT_MAIN "https://github.com/datadog/terraform-aws-ecs-datadog/blob/main/examples/ecs_fargate/main.tf"
    click CT_VARS "https://github.com/datadog/terraform-aws-ecs-datadog/blob/main/examples/ecs_fargate/variables.tf"
    click CT_OUT "https://github.com/datadog/terraform-aws-ecs-datadog/blob/main/examples/ecs_fargate/outputs.tf"
    click CT_VER "https://github.com/datadog/terraform-aws-ecs-datadog/blob/main/examples/ecs_fargate/versions.tf"
    click MOD_MAIN "https://github.com/datadog/terraform-aws-ecs-datadog/blob/main/modules/ecs_fargate/main.tf"
    click MOD_DATADOG "https://github.com/datadog/terraform-aws-ecs-datadog/blob/main/modules/ecs_fargate/datadog.tf"
    click MOD_IAM "https://github.com/datadog/terraform-aws-ecs-datadog/blob/main/modules/ecs_fargate/iam.tf"
    click SECRETS "https://github.com/datadog/terraform-aws-ecs-datadog/blob/main/modules/ecs_fargate/datadog.tf"
    click DATADOG "https://github.com/datadog/terraform-aws-ecs-datadog/blob/main/modules/ecs_fargate/datadog.tf"
    click MOD_VARS "https://github.com/datadog/terraform-aws-ecs-datadog/blob/main/modules/ecs_fargate/variables.tf"
    click MOD_OUT "https://github.com/datadog/terraform-aws-ecs-datadog/blob/main/modules/ecs_fargate/outputs.tf"
    click MOD_VER "https://github.com/datadog/terraform-aws-ecs-datadog/blob/main/modules/ecs_fargate/versions.tf"
    click MOD_README "https://github.com/datadog/terraform-aws-ecs-datadog/blob/main/modules/ecs_fargate/README.md"
    click MOD_MAKE "https://github.com/datadog/terraform-aws-ecs-datadog/tree/main/modules/ecs_fargate/Makefile"
    click GH_FMT "https://github.com/datadog/terraform-aws-ecs-datadog/blob/main/.github/workflows/terraform-fmt.yaml"
    click GH_DOCS "https://github.com/datadog/terraform-aws-ecs-datadog/blob/main/.github/workflows/terraform-docs.yaml"
    click GH_PRE "https://github.com/datadog/terraform-aws-ecs-datadog/blob/main/.github/workflows/pre-commit.yaml"
    click GL_CI "https://github.com/datadog/terraform-aws-ecs-datadog/blob/main/.gitlab-ci.yml"
    click PC_CFG "https://github.com/datadog/terraform-aws-ecs-datadog/blob/main/.pre-commit-config.yaml"
    click TD_CFG "https://github.com/datadog/terraform-aws-ecs-datadog/blob/main/.terraform-docs.yml"
    click MAKE "https://github.com/datadog/terraform-aws-ecs-datadog/tree/main/Makefile"
    click SMOKE "https://github.com/datadog/terraform-aws-ecs-datadog/blob/main/smoke_tests/ecs_fargate/provider.tf"
    click GO_TESTS "https://github.com/datadog/terraform-aws-ecs-datadog/blob/main/tests/main_test.go"

    %% Styles
    classDef terraform fill:#dafff0,stroke:#0a8f66,stroke-width:1px
    classDef aws fill:#fff0db,stroke:#e58e0c,stroke-width:1px
    classDef external fill:#f0e6ff,stroke:#8a2be2,stroke-width:1px
    classDef ci fill:#e8f4ff,stroke:#1c7ed6,stroke-width:1px
    classDef test fill:#fff4e6,stroke:#fa8c16,stroke-width:1px
```
