Git Product home page Git Product logo

the-aws-terraform-samples / terraform-aws-trusted-advisor-glue-aggregator-terraform Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aws-samples/aws-trusted-advisor-glue-aggregator-terraform

0.0 0.0 0.0 159 KB

These Terraform modules aggregate the AWS Trusted Advisor results from different accounts to a centralised account, using AWS Lambda, AWS IAM, Amazon S3 and Amazon SQS

License: MIT No Attribution

Python 40.71% HCL 59.29%

terraform-aws-trusted-advisor-glue-aggregator-terraform's Introduction

aws-trusted-advisor-glue-aggregator

Code to deploy a solution to:

  • periodically aggregate the Trusted Advisor results from different accounts to a centralised account, using AWS Lambda, AWS IAM, Amazon S3 and Amazon SQS
  • run analysis or report SQL queries on the aggregated data, using Amazon Athena, AWS Glue, Amazon S3

Table of Contents

Description

Following the AWS Organization Unit naming convention, we refer to the central data-analysis account as the admin account; and to the target data accounts as the member accounts.

Admin account module

This Terraform module creates resources supporting three flows:

  • An Amazon EventBridge scheduler periodically invoke an AWS Lambda function to obtain the latest list of AWS Accounts to aggregate. It split the account ids into Amazon SQS Queue messages.
  • AWS Lambda function is trigger for each account id in the Amazon SQS Queue, and chain roles to retrieve member account AWS Trusted Advisor checks results. It write them in raw JSON format in a centralised Amazon S3 bucket.
  • AWS Glue map raw-data structure to a synthetic RDMS data-model that can be query in SQL via Amazon Athena, to generate CSV reports or extracts in an Amazon S3 bucket. The module includes all needed roles for the proper access of the services. The module includes logs eviction management for the relevant services.

Member account module

This Terraform module creates an AWS IAM role allowed to read AWS Trusted Advisor checks results and create trust for the admin account role to assume it.

Architecture

The following diagram describes the full architecture.

Diagram

Blue flow: obtains list of accounts in scope

  1. Periodically trigger the "refresh data" process
  2. Retrieve list of accounts. Created an SQS message for each account ID

Yellow flow: retrieve Trusted Advisor data

  1. Invoke Lambda function for each message
  2. Assume trusted admin role
  3. Assume member account role
  4. Call Trusted Advisor API to get data
  5. Save data in S3 Bucket

Green flow: analyse data

  1. Run an Athena Query
  2. Athena Query look how to map the raw data to the synthetic data-model
  3. Athena Query read and process the data
  4. Athena Query save the query result

Prerequisites

  • AWS Premium Support subscription: AWS Business Support or AWS Enterprise Support subscription is required to use this code, as it leverage AWS Trusted Advisor APIs which are available only to these levels of subscription.

Dependencies

Use

The available variables are described in variables.tf file for each module.

Deployment

Pay attention: Both modules are meant to be used as standalone modules. They have to be deployed independently to the relevant AWS accounts The Member module is to be deployed on each member account.

Option 1: You can inspire from main.tf to use the modules directly within your code.
Please have a look inside inside variables.tf for all the possible options.

Option 2: Alternatively, if you have Terraform installed on your workstation, you can deploy the example by executing:

export AWS_PROFILE=<profile>
export AWS_DEFAULT_REGION=eu-west-1

terraform plan -target=module.reporting-admin-module -var region=$AWS_DEFAULT_REGION -var profile=$AWS_PROFILE
terraform apply -target=module.reporting-admin-module -var region=$AWS_DEFAULT_REGION -var profile=$AWS_PROFILE

terraform plan -target=module.reporting-member-module -var region=$AWS_DEFAULT_REGION -var profile=$AWS_PROFILE
terraform apply -target=module.reporting-member-module -var region=$AWS_DEFAULT_REGION -var profile=$AWS_PROFILE

Pay attention: you should first modify the AWS_DEFAULT_REGION in accordance to your requirements.

Testing

Each organisation has its own way to maintain and expose its inventory of AWS Accounts. It is beyond the scope of this article to cover all the options to choose as scope of member accounts (ie: static list, database/file dynamic list, AWS Organization Unit based, etc.)

To support accounts dynamically joining and exiting the scope of analysis, the list of member accounts is re-evaluated each time at runtime.
This educational code allow to hardcode simple list of 2-3 accounts in fetch_accounts_metadata.py for immediate testing purpose. But the reader should replace it by custom logic, adapted to its organisation context, for more advanced usage.

Option 1: AWS Console You can use the AWS Console to:

  • see raw data files aggregated in Amazon S3 bucket
  • run Amazon Athena named or custom queries
  • see query results in Amazon S3 bucket

Option 2: AWS CLI

export randomPrefix=<prefix output displayed by Terraform at deployment>

aws lambda invoke --function-name $randomPrefix-reporting-fetch-accounts-metadata:LIVE out.json
jq --color-output . out.json

aws logs tail /aws/lambda/$randomPrefix-reporting-fetch-accounts-metadata
aws logs tail /aws/lambda/$randomPrefix-reporting-fetch-trusted-advisor
aws s3 ls s3://$randomPrefix-reporting

Cleanup

Use with caution:

rm out.json
terraform destroy -var region=$AWS_DEFAULT_REGION -var profile=$AWS_PROFILE

Security

See CONTRIBUTING for more information.

License

This project is licensed under the MIT-0 License.

=======

terraform-aws-trusted-advisor-glue-aggregator-terraform's People

Contributors

amazon-auto avatar andkamel avatar

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.