{% for pg in resources -%}
resource "aws_elasticache_parameter_group" "pg_{{ pg.name_sanitized }}" {
  family = "{{ pg.CacheParameterGroupFamily }}"
  name   = "{{ pg.CacheParameterGroupName }}"

  {%- if pg.get('Description') %}
  description = "{{ pg.Description }}"
  {%- endif %}

  {%- for param in pg.get('parameters_formatted', []) %}
  parameter {
    name  = "{{ param.name }}"
    value = "{{ param.value }}"
  }
  {%- endfor %}

  tags = {
    {%- for key, value in pg.get('tags_formatted', {}).items() -%}
    "{{ key }}" = "{{ value }}"
    {%- endfor %}
  }
}

{%- if not loop.last %}

{% endif %}
{%- endfor %}