AWSTemplateFormatVersion: '2010-09-09'
Resources:

  # Athena, Glue, and S3 Stack (Template 1)
  AthenaGlueS3Stack:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: https://aws-blogs-artifacts-public.s3.us-east-1.amazonaws.com/artifacts/ML-16929/cfn/1-athena_glue_s3_template.yaml
      TimeoutInMinutes: 10


  # Knowledgebase Stack (Template 2) depends on Template 1
  KnowledgebaseStack:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: https://aws-blogs-artifacts-public.s3.us-east-1.amazonaws.com/artifacts/ML-16929/cfn/2-knowledgebase_template.yaml
      Parameters:
        UnstructuredDataBucketName: !GetAtt AthenaGlueS3Stack.Outputs.UnstructuredDataBucketName
        StructuredDataBucketName: !GetAtt AthenaGlueS3Stack.Outputs.S3BucketName
      TimeoutInMinutes: 15
    DependsOn: AthenaGlueS3Stack


  # Redshift Stack (Template 3) depends on Template 2
  RedshiftStack:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: https://aws-blogs-artifacts-public.s3.us-east-1.amazonaws.com/artifacts/ML-16929/cfn/3-redshift_template.yaml
      TimeoutInMinutes: 15
    DependsOn: KnowledgebaseStack

  # Pharmaceutical Sub-Agent Stack (Template 4) depends on Template 3
  PharmaceuticalSubAgentStack:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: https://aws-blogs-artifacts-public.s3.us-east-1.amazonaws.com/artifacts/ML-16929/cfn/4-sub_agent_legal.yaml
      TimeoutInMinutes: 10
    DependsOn: RedshiftStack

  # Legal Sub-Agent Stack (Template 5) depends on Template 4
  LegalSubAgentStack:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: https://aws-blogs-artifacts-public.s3.us-east-1.amazonaws.com/artifacts/ML-16929/cfn/5-sub_agent_finance.yaml
      TimeoutInMinutes: 10
    DependsOn: PharmaceuticalSubAgentStack

  # Finance Sub-Agent Stack (Template 6) depends on Template 5
  FinanceSubAgentStack:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: https://aws-blogs-artifacts-public.s3.us-east-1.amazonaws.com/artifacts/ML-16929/cfn/6-sub_agent_pharmaceutical.yaml
      TimeoutInMinutes: 10
    DependsOn: LegalSubAgentStack

  # Main Agent Stack (Template 7) depends on Template 6
  MainAgentStack:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: https://aws-blogs-artifacts-public.s3.us-east-1.amazonaws.com/artifacts/ML-16929/cfn/7-mac_main_agent.yaml
      TimeoutInMinutes: 10
    DependsOn: FinanceSubAgentStack

Outputs:
  DeploymentMessage:
    Description: "Deployment status message"
    Value: "CloudFormation templates from the S3 bucket have been deployed in the correct order."