# Terraform configuration generated by Vibe Infra
# Provider: {{ provider }}

terraform {
  required_version = ">= 1.0"
  required_providers {
    {% if provider == "aws" %}
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
    {% elif provider == "gcp" %}
    google = {
      source  = "hashicorp/google"
      version = "~> 5.0"
    }
    {% elif provider == "azure" %}
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~> 3.0"
    }
    {% endif %}
  }
}

{% if provider == "aws" %}
provider "aws" {
  region = var.region
}
{% elif provider == "gcp" %}
provider "google" {
  project = var.project_id
  region  = var.region
}
{% elif provider == "azure" %}
provider "azurerm" {
  features {}
}
{% endif %}

# Variables
{% for var_name, var_config in variables.items() %}
variable "{{ var_name }}" {
  description = "{{ var_config.get('description', var_name) }}"
  type        = {{ var_config.get('type', 'string') }}
  {% if 'default' in var_config %}
  default     = {{ var_config['default'] | tojson }}
  {% endif %}
}
{% endfor %}

# Resources
{% for resource in resources %}
resource "{{ resource.type }}" "{{ resource.name }}" {
  {% for key, value in resource.config.items() %}
  {{ key }} = {{ value | tojson }}
  {% endfor %}

  {% if resource.get('tags') %}
  tags = {
    {% for tag_key, tag_value in resource.tags.items() %}
    {{ tag_key }} = "{{ tag_value }}"
    {% endfor %}
    ManagedBy = "athena"
  }
  {% endif %}
}

{% endfor %}

# Outputs
{% for output_name, output_config in outputs.items() %}
output "{{ output_name }}" {
  description = "{{ output_config.get('description', output_name) }}"
  value       = {{ output_config['value'] }}
}
{% endfor %}
