---
AWSTemplateFormatVersion: '2010-09-09'
Description: Handel-created Redis cluster

Resources:
  Cluster:
    Type: AWS::ElastiCache::CacheCluster
    Properties:
      AutoMinorVersionUpgrade: true
      CacheNodeType: {{instanceType}}
      {{#if cacheParameters}}
      CacheParameterGroupName: !Ref ParameterGroup
      {{else}}
      CacheParameterGroupName: {{defaultCacheParameterGroup}}
      {{/if}}
      CacheSubnetGroupName: {{cacheSubnetGroup}}
      ClusterName: {{clusterName}}
      Engine: redis
      EngineVersion: {{redisVersion}}
      NumCacheNodes: 1
      Port: 6379
      {{#if maintenanceWindow}}
      PreferredMaintenanceWindow: {{maintenanceWindow}}
      {{/if}}
      {{#if snapshotWindow}}
      SnapshotWindow: {{snapshotWindow}}
      {{/if}}
      Tags:
      {{#if tags}}
      {{#each tags}}
      - Key: {{@key}}
        Value: {{this}}
      {{/each}}
      {{/if}}
      - Key: Name
        Value: {{stackName}}
      VpcSecurityGroupIds:
      - {{redisSecurityGroupId}}
  {{#if cacheParameters}}
  ParameterGroup:
    Type: AWS::ElastiCache::ParameterGroup
    Properties:
      CacheParameterGroupFamily: {{cacheParameterGroupFamily}}
      Description: {{description}}
      Properties:
        {{#each cacheParameters}}
        {{@key}}: '{{this}}'
        {{/each}}
  {{/if}}
Outputs:
  CacheAddress:
    Description: The address of the redis configuration endpoint
    Value: !GetAtt Cluster.RedisEndpoint.Address
  CachePort:
    Description: The port of the redis cluster
    Value: !GetAtt Cluster.RedisEndpoint.Port
