# Terraform configuration to create an Amazon SNS Topic and an email subscription.
# Publishing messages is a runtime operation performed by applications,
# not directly by Terraform.

provider "aws" {
  region = "us-east-1"
}

# --- SNS Topic ---
resource "aws_sns_topic" "email_topic" {
  name = "MyTerraformSNSTopic"

  tags = {
    Name        = "MyTerraformSNSTopic"
    Environment = "Dev"
  }
}

# --- Email Subscription ---
# IMPORTANT: Replace "your-email@example.com" with your actual email address.
# You will receive a confirmation email from AWS. You MUST click the link
# in that email for the subscription to become active.
resource "aws_sns_topic_subscription" "email_subscription" {
  topic_arn = aws_sns_topic.email_topic.arn
  protocol  = "email"
  endpoint  = "your-email@example.com" # !!! IMPORTANT: Replace with your actual email address !!!
  # Set to false if you want to manually confirm the subscription.
  # Set to true if you want Terraform to attempt to confirm it (requires specific permissions).
  # For email, manual confirmation is usually required.
  confirmation_timeout_in_minutes = 1
}

# --- Outputs ---
output "sns_topic_arn" {
  value       = aws_sns_topic.email_topic.arn
  description = "The ARN of the SNS topic."
}

output "sns_topic_name" {
  value       = aws_sns_topic.email_topic.name
  description = "The name of the SNS topic."
}

output "sns_subscription_arn" {
  value       = aws_sns_topic_subscription.email_subscription.arn
  description = "The ARN of the email subscription. Remember to confirm it manually."
}
