# terraform-neo4j

## Overview

This module provides functionality to create Neo4j clusters.

This module follows a few conventions:

* Whenever possible, resources will be named `var.environment-var.service_name` (e.g. qa-neo4j-artist)
* User-provided IAM policies will be named `var.environment-var.service_name-instance-policy` 


## Resources

### The module manages the following: 

* Launch configurations
* Autoscaling groups
* Security groups
* IAM policies and roles
* Route53 records
  * Autoscaling lifecycle hooks
* Lambda for lifecycle-based DNS updates

### The module does not manage the following: 

* VPCs
* Subnets
  * This module assumes that subnets already exist and can be specified as `var.vpc_private_subnet_ids`

### IAM

In addition to the programmatically generated policies and roles, you may also provide a JSON file containing additional IAM policies the Neo4j cluster requires, which will be attached to the instance profile role. In order to use this functionality, set the `${var.iam_policy_file_enabled}` variable to `true` and provide a policy file. 

These policy files, which **must** be named `policies/${service_name}.json`, should be located in the same directory as the `main.tf` that defines your cluster. That directory structure might look like this:
```
* modules/
* qa/
    * policies/
        * neo4j-name.json <---- this is the additional policy file for qa
    * main.tf
    * user_data.tpl
* prod/
    * policies/
        * neo4j-name.json <---- this is the additional policy file for prod
    * main.tf
    * user_data.tpl
```

### User Data

The module expects a file called `user_data.tpl` in the directory of your environment, i.e. the same directory as the `main.tf`. This should contain any additional user data you would like provided to the cluster instances. See the above example as a reference for directory structure.

## Examples

See the `test/` directory for working code samples.

## Notes

### Lifecycle Hooks

Lifecycle hooks are implemented in order to send messages to an SQS queue when instances are launched or terminated. The SQS queue triggers a Lambda, which updates the DNS record created by this module, either by removing the terminated instance or adding the newly launched one. Once the Lambda finishes its work, it completes the lifecycle action and the autoscaling group processes the event.
