# terraform-emr

## Overview

This module provides functionality to create EMR clusters. Consult the test directory for working examples.

> [!WARNING]
> Breaking changes! Starting with version 3.0.0, the module has been refactored to use a DNS provider for Route53 record creation. The following changes have been made:
> 
> 1. The previous `aws_route53_record.emr_cluster_route53_record` resource has been removed, and only the DNS provider-based record is now used.
> 2. The variable `networking_route53_zone_id` has been renamed to `override_route53_zone_id`.
> 3. Route53 records are now conditionally created based on the `route53_record_creation_enabled` variable.
> 4. By default, Route53 records are created for all environments.
>
> The value for the Route53 zone ID is now determined automatically based on the environment:
> - For the development environment, it defaults to `Z21XEY26C989RH`, which is the zone ID for `dev.theorchard.io` in the Orchard development account.
> - For all other environments, the default is `Z0183645HDT0XCWHLW7S`, corresponding to the `theorchard.io` zone in the networking account.
> - If you need to create records in a different account or zone, please specify the appropriate zone ID using the `override_route53_zone_id` parameter.
>
> In the development and shared account, you may need to use `moved` blocks to migrate existing resources. See the [migration guide](#migration-guide) for more information.

### Providers

The module requires an explicitly defined second AWS provider to create DNS records in the appropriate account based on the environment.
This provider must be defined in the same directory as the module and should use the appropriate profile.
The provider should be defined as follows:

```hcl
provider "aws" {
  region  = var.aws_region
}

provider "aws" {
  region  = var.aws_region
  alias   = "dns"
  profile = "networking"  # Use the appropriate profile for DNS management
}

module "emr" {
  source = "git@github.com:theorchard/terraform-emr.git//?ref=3.0.0"

  providers = {
    aws.dns = aws.dns
  }
  
  subnet_id = module.vpc_info.default_private_subnet_ids[0]
  
  # Optional: Override the default Route53 zone ID if needed
  # override_route53_zone_id = "your-custom-zone-id"
  
  # Optional: Disable Route53 record creation if needed
  # route53_record_creation_enabled = false
  
  // other settings
}
```

### Migration Guide

If you are upgrading from a previous version of this module, you may need to use `moved` blocks to migrate existing resources. This is particularly important for the Route53 record resources that have been refactored.

Here's an example of how to use `moved` blocks to migrate existing resources:

```hcl
# If you previously had records in the prod account
moved {
  from = module.emr.aws_route53_record.emr_cluster_route53_record
  to   = module.emr.aws_route53_record.emr_cluster_route53_record[0]
}

# If you previously had records in the networking account
moved {
  from = module.emr.aws_route53_record.networking_emr_cluster_route53_record[0]
  to   = module.emr.aws_route53_record.emr_cluster_route53_record[0]
}
```

These `moved` blocks should be placed in your root module (not inside the terraform-emr module itself). They tell Terraform how to map the old resource addresses to the new ones, preventing Terraform from trying to destroy and recreate the resources.

Note that you only need to include the `moved` blocks that are relevant to your specific configuration. If you weren't using the networking account records before, you don't need the second `moved` block.