# Launch Templates
# Generated by Terraback

{% for resource in resources %}
resource "aws_launch_template" "{{ resource.name }}" {
  name_prefix   = "{{ resource.launch_template_name }}-"
  description   = "Launch template imported from AWS"
{%- if resource.image_id %}
  image_id      = "{{ resource.image_id }}"
{%- endif %}
{%- if resource.instance_type %}
  instance_type = "{{ resource.instance_type }}"
{%- endif %}
{%- if resource.key_name %}
  key_name      = "{{ resource.key_name }}"
{%- endif %}
{%- if resource.security_groups_ids %}
  vpc_security_groups_ids = [
{%- for sg_id in resource.security_groups_ids %}
    "{{ sg_id }}"{{ "," if not loop.last }}
{%- endfor %}
  ]
{%- endif %}
{%- if resource.user_data %}

  user_data = base64encode(<<-EOF
    {{ resource.user_data | replace('\n', '\n    ') }}
    EOF
  )
{%- endif %}
{%- if resource.iam_instance_profile %}

  iam_instance_profile {
    name = "{{ resource.iam_instance_profile }}"
  }
{%- endif %}
{%- if resource.ebs_optimized %}
  ebs_optimized = true
{%- endif %}

  monitoring {
    enabled = {{ 'true' if resource.monitoring_enabled else 'false' }}
  }
{%- if resource.subnets_id %}

  network_interfaces {
    associate_public_ip_address = true
    subnets_id                   = "{{ resource.subnets_id }}"
    delete_on_termination       = true
{%- if resource.security_groups_ids %}
    security_groups = [
{%- for sg_id in resource.security_groups_ids %}
      "{{ sg_id }}"{{ "," if not loop.last }}
{%- endfor %}
    ]
{%- endif %}
  }
{%- endif %}
{%- if resource.tags %}

  tag_specifications {
    resource_type = "instance"
    tags = {
{%- for tag in resource.tags %}
      "{{ tag.Key }}" = "{{ tag.Value }}"
{%- endfor %}
    }
  }

  tags = {
{%- for tag in resource.tags %}
    "{{ tag.Key }}" = "{{ tag.Value }}"
{%- endfor %}
  }
{%- endif %}
}
{% if not loop.last %}

{% endif %}
{%- endfor %}