AWSTemplateFormatVersion: 2010-09-09
Description: Create resources needed to enroll in AWS Marketplace Commerce Analytics Service

Parameters:
  CasBucketName:
    Description: Bucket Name for CAS Data
    Type: String
  CasSnsTopicName:
    Description: CAS SNS Topic Name
    Type: String
    Default: clazar-cas-sns

Resources:
  CasBucket:
    Type: 'AWS::S3::Bucket'
    Properties:
      BucketName: !Ref CasBucketName
      BucketEncryption:
        ServerSideEncryptionConfiguration:
          - ServerSideEncryptionByDefault:
              SSEAlgorithm: AES256
      VersioningConfiguration:
        Status: Enabled
      OwnershipControls:
        Rules:
          - ObjectOwnership: BucketOwnerEnforced

  CasBucketPolicy:
    Type: AWS::S3::BucketPolicy
    Properties:
      Bucket:
        Ref: CasBucket
      PolicyDocument:
        Statement:
          - Sid: DenyHttpRequest
            Effect: Deny
            Principal: "*"
            Action: s3:*
            Resource:
              Fn::Sub: arn:aws:s3:::${CasBucket}/*
            Condition:
              Bool:
                aws:SecureTransport: false

  CasSNSTopic:
    Type: 'AWS::SNS::Topic'
    Properties:
      TopicName: !Ref CasSnsTopicName
      KmsMasterKeyId: alias/aws/sns

Outputs:
  CasSnsTopicArn:
    Description: CAS SNS Topic Arn
    Value: !Ref CasSNSTopic
  CasBucketName:
    Description: CAS S3 Bucket
    Value: !Ref CasBucket
