{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Description": "AWS Service Catalog Demo Portfolio Setup for AWS Organizations Sharing.(fdp-1qr5btau9)",
    "Metadata": {
        "AWS::CloudFormation::Interface": {
            "ParameterGroups": [
                {
                    "Label": {
                        "default": "AWS SC Portfolio Information"
                    },
                    "Parameters": [
                        "PortfolioName",
                        "PortfolioProvider",
                        "PortfolioDescription"
                    ]
                },
                {
                    "Label": {
                        "default": "AWS SC Product Template Source Information"
                    },
                    "Parameters": [
                        "RepoRootURL",
                        "Product1TemplateName",
                        "Product2TemplateName"
                    ]
                },
                {
                    "Label": {
                        "default": "Launch Constraint IAM Configuration"
                    },
                    "Parameters": [
                        "LocalLaunchRoleName"
                    ]
                }
            ]
        }
    },
    "Parameters":
      {
        "PortfolioProvider": {
            "Type":"String",
            "Description":"Provider Name",
            "Default": "IT Services"
        },
       "PortfolioName": {
            "Type": "String",
            "Description": "Portfolio Name",
            "Default": "SCHubPortfolioDemo",
            "AllowedPattern" : "[a-zA-Z0-9]*",
            "ConstraintDescription" : "must contain only alphanumeric characters."
        },
        "PortfolioDescription": {
            "Type": "String",
            "Description": "Portfolio Description",
            "Default": "Service Catalog Portfolio that contains reference architecture products for Amazon Elastic Compute Cloud (EC2)."
        },
        "LocalLaunchRoleName": {
            "Type": "String",
            "Description": "Name of the launch constraint IAM role used for this portfolio (must be precreated)"
        },
        "RepoRootURL": {
            "Type": "String",
            "Description": "S3 root url for the repository containing the product templates.",
            "Default": "https://marketplace-sa-resources.s3.amazonaws.com/sc-org-sharing-blog-june20 "
        },
        "Product1TemplateName": {
            "Type": "String",
            "Description": "Filename of the AWS Service Catalog product 1 template.",
            "Default": "sc-product-ec2-linux.json"
        },
        "Product2TemplateName": {
            "Type": "String",
            "Description": "Filename of the AWS Service Catalog product 2 template.",
            "Default": "sc-product-ec2-windows.json"
        }
      },
    "Resources": 
    {
        "SCPortfolio": {
          "Type" : "AWS::ServiceCatalog::Portfolio",
          "Properties" : {
            "ProviderName": {"Ref":"PortfolioProvider"},
            "Description" : {"Ref":"PortfolioDescription"},
            "DisplayName" : {"Ref":"PortfolioName"}
          }
        },   
        "SCProduct1": {
          "Type" : "AWS::CloudFormation::Stack",
          "Properties" : {
            "Parameters" : {         
                "PortfolioProvider": {"Ref":"PortfolioProvider"},
                "LocalLaunchRoleName": {"Ref":"LocalLaunchRoleName"},
                "PortfolioId":{"Ref":"SCPortfolio"},
                "RepoRootURL":{"Ref":"RepoRootURL"}
            },
            "TemplateURL" : {"Fn::Sub": "${RepoRootURL}/${Product1TemplateName}"},
            "TimeoutInMinutes" : 5
          }
        },
        "SCProduct2": {
          "Type" : "AWS::CloudFormation::Stack",
          "Properties" : {
            "Parameters" : {         
                "PortfolioProvider": {"Ref":"PortfolioProvider"},
                "LocalLaunchRoleName": {"Ref":"LocalLaunchRoleName"},
                "PortfolioId":{"Ref":"SCPortfolio"},
                "RepoRootURL":{"Ref":"RepoRootURL"}
            },
            "TemplateURL" : {"Fn::Sub": "${RepoRootURL}/${Product2TemplateName}"},
            "TimeoutInMinutes" : 5
          }
        }
    },
    "Outputs": {
     "SCPortfolioId":{
        "Value": {"Ref":"SCPortfolio"},
        "Description":"Portfolio Id of the newly created AWS Service Catalog Portfolio"
      },
      "SCProduct1":{
        "Value": {"Fn::GetAtt":["SCProduct1","Outputs.ProductId"]},
        "Description":"Product Id of the newly created AWS Service Catalog Product 1"
      },
      "SCProduct2":{
        "Value": {"Fn::GetAtt":["SCProduct2","Outputs.ProductId"]},
        "Description":"Product Id of the newly created AWS Service Catalog Product 2"
      }
  }
}
