{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Description": "(SO0157) Performance Dashboard on AWS Solution Implementation v1.9.4",
  "Parameters": {
    "AdminEmail": {
      "Type": "String",
      "Description": "Email address for the admin user",
      "MinLength": 5
    },
    "AuthenticationRequired": {
      "Type": "String",
      "Default": "no",
      "AllowedValues": [
        "yes",
        "no"
      ],
      "Description": "If public part of the app will ask credentials to users"
    },
    "ExampleLanguage": {
      "Type": "String",
      "Default": "english",
      "AllowedValues": [
        "english",
        "spanish",
        "portuguese"
      ],
      "Description": "Language for example dashboards"
    },
    "DomainName": {
      "Type": "String",
      "Description": "Domain name of the public url (www.example.com). The certificate for the given domain must exists. Value can be empty if no domain required."
    }
  },
  "Resources": {
    "authStack": {
      "Type": "AWS::CloudFormation::Stack",
      "Properties": {
        "TemplateURL": {
          "Fn::Sub": "https://solutions-${AWS::Region}.s3.amazonaws.com/performance-dashboard-on-aws/v1.9.4/Auth.template"
        },
        "TimeoutInMinutes": "60",
        "Parameters": {
          "authenticationRequired": {
            "Ref": "AuthenticationRequired"
          }
        }
      }
    },
    "authzStack": {
      "Type": "AWS::CloudFormation::Stack",
      "DependsOn": "authStack",
      "Properties": {
        "TemplateURL": {
          "Fn::Sub": "https://solutions-${AWS::Region}.s3.amazonaws.com/performance-dashboard-on-aws/v1.9.4/Authz.template"
        },
        "TimeoutInMinutes": "60",
        "Parameters": {
          "adminEmail": {
            "Ref": "AdminEmail"
          },
          "authenticationRequired": {
            "Ref": "AuthenticationRequired"
          }
        }
      }
    },
    "frontendStack": {
      "Type": "AWS::CloudFormation::Stack",
      "Properties": {
        "TemplateURL": {
          "Fn::Sub": "https://solutions-${AWS::Region}.s3.amazonaws.com/performance-dashboard-on-aws/v1.9.4/Frontend.template"
        },
        "TimeoutInMinutes": "60",
        "Parameters": {
          "domainName": {
            "Ref": "DomainName"
          }
        }
      }
    },
    "backendStack": {
      "Type": "AWS::CloudFormation::Stack",
      "DependsOn": [
        "authStack",
        "frontendStack"
      ],
      "Properties": {
        "TemplateURL": {
          "Fn::Sub": "https://solutions-${AWS::Region}.s3.amazonaws.com/performance-dashboard-on-aws/v1.9.4/Backend.template"
        },
        "TimeoutInMinutes": "60",
        "Parameters": {
          "authenticationRequired": {
            "Ref": "AuthenticationRequired"
          },
          "domainName": {
            "Ref": "DomainName"
          }
        }
      }
    },
    "frontendConfigStack": {
      "Type": "AWS::CloudFormation::Stack",
      "DependsOn": [
        "backendStack",
        "frontendStack",
        "authzStack",
        "authStack"
      ],
      "Properties": {
        "TemplateURL": {
          "Fn::Sub": "https://solutions-${AWS::Region}.s3.amazonaws.com/performance-dashboard-on-aws/v1.9.4/FrontendConfig.template"
        },
        "TimeoutInMinutes": "60",
        "Parameters": {
          "authenticationRequired": {
            "Ref": "AuthenticationRequired"
          }
        }
      }
    },
    "examplesStack": {
      "Type": "AWS::CloudFormation::Stack",
      "DependsOn": [
        "backendStack",
        "authzStack"
      ],
      "Properties": {
        "TemplateURL": {
          "Fn::Sub": "https://solutions-${AWS::Region}.s3.amazonaws.com/performance-dashboard-on-aws/v1.9.4/DashboardExamples.template"
        },
        "TimeoutInMinutes": "60",
        "Parameters": {
          "exampleLanguage": {
            "Ref": "ExampleLanguage"
          }
        }
      }
    },
    "opsStack": {
      "Type": "AWS::CloudFormation::Stack",
      "DependsOn": [
        "authStack",
        "authzStack",
        "frontendStack",
        "backendStack",
        "frontendConfigStack",
        "examplesStack"
      ],
      "Properties": {
        "TemplateURL": {
          "Fn::Sub": "https://solutions-${AWS::Region}.s3.amazonaws.com/performance-dashboard-on-aws/v1.9.4/Ops.template"
        },
        "TimeoutInMinutes": "60"
      }
    }
  },
  "Outputs": {
    "StackRef": {
      "Value": {
        "Ref": "frontendStack"
      }
    },
    "OutputFromNestedStack": {
      "Value": {
        "Fn::GetAtt": [
          "frontendStack",
          "Outputs.CloudFrontURL"
        ]
      }
    }
  }
}