AWSTemplateFormatVersion: "2010-09-09"
Description: Catalog
Parameters:
  PrincipalArn:
    Type: String
    Description: Gives access to the specified group/role/user
  ProductUrl:
    Type: String
    Description: The URL of the product template
Resources:
  Portfolio:
    Type: AWS::ServiceCatalog::Portfolio
    Properties:
      DisplayName: AWSConfigDemoPortfolio
      ProviderName: Mechanical Rock

  Product:
    Type: AWS::ServiceCatalog::CloudFormationProduct
    Properties:
      Name: AccountConfig
      Owner: Mechanical Rock
      SupportUrl: https://mechanicalrock.io
      SupportEmail: sales@mechanicalrock.io
      ProvisioningArtifactParameters:
        - Description: Demo Product
          Name: 1.0.0
          Info:
            LoadTemplateFromURL: !Ref ProductUrl

  AssociateProduct:
    Type: AWS::ServiceCatalog::PortfolioProductAssociation
    Properties: 
      PortfolioId: !Ref Portfolio
      ProductId: !Ref Product

  PortfolioAccess:
    Type: AWS::ServiceCatalog::PortfolioPrincipalAssociation
    Properties: 
      PortfolioId: !Ref Portfolio
      PrincipalARN: !Ref PrincipalArn
      PrincipalType: IAM

Outputs:
  ProductId:
    Description: ProductID of product
    Value: !Ref Product