aaa2c06c30
Lifecycle Rules: - Add prevent_destroy = true to all 32+ resources - Add ignore_changes = [tags] to prevent tag drift from causing recreation - Add ignore_changes = [tags, user_data, ami, iam_instance_profile] for EC2 - Preserve existing create_before_destroy for security groups and ACM Import Blocks (orphaned resources): - Lambda: sacc4-stop-instances - Lambda: sacc4-start-instances - EventBridge: sacc4-stop-instances-schedule - EventBridge: sacc4-start-instances-schedule Data Sources: - aws_instances.existing_api (detect EC2 duplicates) - aws_db_instance.existing (detect RDS duplicates) - aws_nat_gateways.existing (detect NAT GW duplicates) - aws_cloudfront_distribution.existing (detect CloudFront duplicates) Variables: - db_identifier: for RDS duplicate detection - cloudfront_distribution_id: for CloudFront duplicate detection Validation Results: - terraform validate: PASSED - terraform plan: 0 to add, 1 to change, 0 to destroy - No resources marked for recreation Orphan EIP detected: - eipalloc-0bdf9c47a80885c7a (78.13.177.201) unattached - Requires manual cleanup or investigation Refs: AWS Resource Validation - May 2026
76 lines
3.1 KiB
Terraform
76 lines
3.1 KiB
Terraform
# ===============================================================================================================
|
|
# imports.tf - Import blocks para recursos huérfanos detectados en AWS
|
|
# Descripción:
|
|
# Los siguientes recursos existen en AWS pero NO están en el estado de Terraform.
|
|
# Estos import blocks permiten traerlos bajo gestión de Terraform sin recrearlos.
|
|
#
|
|
# Uso:
|
|
# terraform plan -generate-config-out=generated.tf
|
|
# # Revisar generated.tf, mover recursos a archivos apropiados, luego:
|
|
# terraform plan
|
|
# ===============================================================================================================
|
|
|
|
# -------------------------------------------------------------------------------
|
|
# Lambda Functions (Scheduler para encender/apagar instancias EC2)
|
|
# Detectadas: 2026-05-07 - Existen en AWS pero no en Terraform state
|
|
# -------------------------------------------------------------------------------
|
|
import {
|
|
to = aws_lambda_function.stop_instances
|
|
id = "sacc4-stop-instances"
|
|
}
|
|
|
|
import {
|
|
to = aws_lambda_function.start_instances
|
|
id = "sacc4-start-instances"
|
|
}
|
|
|
|
# -------------------------------------------------------------------------------
|
|
# EventBridge Rules (Schedule para Lambda functions)
|
|
# Detectadas: 2026-05-07 - Existen en AWS pero no en Terraform state
|
|
# -------------------------------------------------------------------------------
|
|
import {
|
|
to = aws_cloudwatch_event_rule.stop_instances_schedule
|
|
id = "sacc4-stop-instances-schedule"
|
|
}
|
|
|
|
import {
|
|
to = aws_cloudwatch_event_rule.start_instances_schedule
|
|
id = "sacc4-start-instances-schedule"
|
|
}
|
|
|
|
# ===============================================================================================================
|
|
# NOTAS DE IMPLEMENTACIÓN:
|
|
# ===============================================================================================================
|
|
#
|
|
# 1. EJECUTAR PRIMERO (genera configuración):
|
|
# terraform plan -generate-config-out=generated.tf
|
|
#
|
|
# 2. REVISAR generated.tf:
|
|
# - Mover aws_lambda_function resources a lambda.tf (crear nuevo archivo)
|
|
# - Mover aws_cloudwatch_event_rule resources a events.tf (crear nuevo archivo)
|
|
# - Añadir tags consistentes con el proyecto
|
|
# - Añadir lifecycle blocks con prevent_destroy = true
|
|
#
|
|
# 3. LIMPIAR:
|
|
# - rm generated.tf
|
|
#
|
|
# 4. VALIDAR:
|
|
# - terraform validate
|
|
# - terraform plan
|
|
#
|
|
# 5. APLICAR (solo después de validar):
|
|
# - terraform apply
|
|
#
|
|
# RECURSOS HUÉRFANOS DETECTADOS:
|
|
# - Lambda: sacc4-stop-instances (Python 3.11, creada 2026-05-07)
|
|
# - Lambda: sacc4-start-instances (Python 3.11, creada 2026-05-07)
|
|
# - EventBridge: sacc4-stop-instances-schedule (ENABLED)
|
|
# - EventBridge: sacc4-start-instances-schedule (ENABLED)
|
|
#
|
|
# EIP HUÉRFANO DETECTADO (requiere limpieza manual):
|
|
# - eipalloc-0bdf9c47a80885c7a (78.13.177.201) - No está asociado a ninguna instancia
|
|
# Probablemente pertenecía al NAT Gateway anterior que fue recreado.
|
|
# Acción recomendada: Liberar manualmente desde la consola AWS o con:
|
|
# aws ec2 release-address --allocation-id eipalloc-0bdf9c47a80885c7a
|
|
# ===============================================================================================================
|