AWSTemplateFormatVersion: "2010-09-09"
Description: Enable AWS Config Rules
Parameters:
  CatalogProductId:
    Type: String
  UniqueAccountFunctionArn:
    Type: String
    Description: Arn of unique account function
Resources:
  UniqueAccountRule:
    Type: AWS::Config::ConfigRule
    Properties: 
      ConfigRuleName: UniqueAccountConfiguration
      Description: Account parameters within a configuration are unique
      MaximumExecutionFrequency: One_Hour
      Scope: 
        TagKey: "aws:servicecatalog:productArn"
        TagValue: !Sub "arn:aws:catalog:${AWS::Region}:${AWS::AccountId}:product/${CatalogProductId}"
      Source: 
        Owner: CUSTOM_LAMBDA
        SourceIdentifier: !Ref UniqueAccountFunctionArn
        SourceDetails:
          - EventSource: aws.config
            MessageType: ConfigurationItemChangeNotification
          - EventSource: aws.config
            MessageType: OversizedConfigurationItemChangeNotification
