---
########################################################################################
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.              #
#                                                                                      #
# Permission is hereby granted, free of charge, to any person obtaining a copy of this #
# software and associated documentation files (the "Software"), to deal in the Software#
# without restriction, including without limitation the rights to use, copy, modify,   #
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to   #
# permit persons to whom the Software is furnished to do so.                           #  
#                                                                                      #
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,  #
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A        #
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT   #
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION    #
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE       # 
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               #
########################################################################################
Description: "This CloudFormation template sets up hub portfolio, adds the product specified and shares the portfolio with a spoke account(fdp-1oh0t6ngt)"
Parameters:
  EMRCFNPath:
    Description: Complete s3 path of EMR CloudFormation template.
    Type: String
    Default: ""
  SpokeAccountID:
    Description: AWS Account ID of child portfolio.
    Type: String
    Default: ""
Resources:
  HubPortfolio:
    Type: "AWS::ServiceCatalog::Portfolio"
    Properties:
      AcceptLanguage: "en"
      Description: "Sample Hub Portfolio."
      DisplayName: "Sample Hub Portfolio"
      ProviderName: "CCOE"
  EMRProduct:
    Type: "AWS::ServiceCatalog::CloudFormationProduct"
    Properties:
      AcceptLanguage: "en"
      Description: "EMR Product"
      Distributor: "CCOE"
      Name: "EMR Cluster"
      Owner: "CCOE"
      SupportEmail: "email@mycompany.com"
      SupportUrl: "https://www.mycompany.com"
      SupportDescription: "This is a sample EMR product that your CCOE team needs to customize and support."
      ProvisioningArtifactParameters:
        -
          Description: "Version 1 of EMR cluster creation product"
          Name: "Version - 1.0"
          Info:
            LoadTemplateFromURL : !Ref EMRCFNPath
  PortfolioProductAssociation:
    Type: "AWS::ServiceCatalog::PortfolioProductAssociation"
    Properties:
      AcceptLanguage: "en"
      PortfolioId: !Ref HubPortfolio
      ProductId: !Ref EMRProduct
  PortfolioShare:
    Type: "AWS::ServiceCatalog::PortfolioShare"
    Properties:
      AccountId: !Ref SpokeAccountID
      PortfolioId: !Ref HubPortfolio
Outputs:
  PortfolioID:
    Value: !Ref HubPortfolio 
  ProductID:
    Value: !Ref EMRProduct 