{% set config = merged_configs.get('aws_secretsmanager_secret', {}) %}
{% set comments = compliance_comments.get('aws_secretsmanager_secret', []) %}
# ------------------------------------------------------------------------------
# Secrets Manager Secret
# ------------------------------------------------------------------------------
{% for comment in comments %}
# {{ comment }}
{% endfor %}

resource "aws_secretsmanager_secret" "this" {
  name        = "{{ config.get('name', project_id ~ '-secret') }}"
  description = "{{ config.get('description', 'Managed by ComplyForm') }}"

  kms_key_id              = {{ config.get('kms_key_id', 'null') }}
  recovery_window_in_days = {{ config.get('recovery_window_in_days', 30) }}

  {% if config.get('replica_regions') %}
  {% for region in config.get('replica_regions', []) %}
  replica {
    region     = "{{ region.get('region') }}"
    kms_key_id = {{ region.get('kms_key_id', 'null') }}
  }
  {% endfor %}
  {% endif %}

  tags = {
    Name      = "{{ config.get('name', project_id ~ '-secret') }}"
    ManagedBy = "complyform"
  }
}
