# ebs

Creates KMS-encrypted EBS volumes with optional EC2 attachment and DLM snapshot lifecycle policies.

Provisions gp3 EBS volumes (or any volume type) with encryption enforced, optional instance attachment via a Name-tag data lookup, and Data Lifecycle Manager policies for automated snapshot creation and retention. A DLM execution role is created automatically if none is supplied.

## Usage

```hcl
module "ebs" {
  source  = "hcassc.jfrog.io/iac-terraform-modules-virtual/storage/ebs/aws"
  version = "0.1.0"

  volumes = {
    data = {
      availability_zone = "us-east-1a"
      size              = 100
      kms_key_id        = module.kms.key_arn
      instance_name     = "my-ec2-instance"
      device_name       = "/dev/xvdf"
    }
  }

  snapshot_schedules = {
    daily = {
      name        = "daily-snapshots"
      retain_count = 7
      target_tags = { Backup = "true" }
    }
  }
}
```

<!-- BEGIN_TF_DOCS — DO NOT EDIT BELOW THIS LINE -->
## Requirements

| Name | Version |
| ---- | ------- |
| <a name="requirement_terraform"></a> [terraform](#requirement_terraform) | ~> 1.5 |
| <a name="requirement_aws"></a> [aws](#requirement_aws) | ~> 6.50 |

## Providers

| Name | Version |
| ---- | ------- |
| <a name="provider_aws"></a> [aws](#provider_aws) | 6.50.0 |

## Resources

| Name | Type |
| ---- | ---- |
| [aws_dlm_lifecycle_policy.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/dlm_lifecycle_policy) | resource |
| [aws_ebs_volume.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ebs_volume) | resource |
| [aws_iam_role.dlm](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
| [aws_iam_role_policy_attachment.dlm](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
| [aws_volume_attachment.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/volume_attachment) | resource |

## Inputs

| Name | Description | Type | Default | Required |
| ---- | ----------- | ---- | ------- | :------: |
| <a name="input_dlm_execution_role_arn"></a> [dlm_execution_role_arn](#input_dlm_execution_role_arn) | ARN of the IAM role for DLM (optional — creates role when null) | `string` | `null` | no |
| <a name="input_dlm_policy_name"></a> [dlm_policy_name](#input_dlm_policy_name) | Name for the Data Lifecycle Manager policy | `string` | `"ebs-snapshot-policy"` | no |
| <a name="input_snapshot_schedules"></a> [snapshot_schedules](#input_snapshot_schedules) | Map of DLM snapshot schedules | <pre>map(object({<br/>    name          = string<br/>    interval      = optional(number, 24)<br/>    interval_unit = optional(string, "HOURS")<br/>    times         = optional(list(string), ["03:00"])<br/>    retain_count  = optional(number, 7)<br/>    target_tags   = map(string)<br/>  }))</pre> | `{}` | no |
| <a name="input_tags"></a> [tags](#input_tags) | Resource tags to apply to all resources | `map(string)` | `{}` | no |
| <a name="input_volumes"></a> [volumes](#input_volumes) | Map of EBS volumes to create | <pre>map(object({<br/>    availability_zone    = string<br/>    size                 = number<br/>    type                 = optional(string, "gp3")<br/>    iops                 = optional(number, null)<br/>    throughput           = optional(number, null)<br/>    encrypted            = optional(bool, true)<br/>    kms_key_id           = optional(string, null)<br/>    multi_attach_enabled = optional(bool, false)<br/>    snapshot_id          = optional(string, null)<br/>    final_snapshot       = optional(bool, false)<br/>    # Attachment<br/>    instance_name = optional(string, null) # data lookup key<br/>    device_name   = optional(string, null)<br/>    force_detach  = optional(bool, false)<br/>  }))</pre> | `{}` | no |

## Outputs

| Name | Description |
| ---- | ----------- |
| <a name="output_dlm_policy_ids"></a> [dlm_policy_ids](#output_dlm_policy_ids) | Map of schedule key to DLM lifecycle policy ID |
| <a name="output_volume_arns"></a> [volume_arns](#output_volume_arns) | Map of logical volume key to EBS volume ARN |
| <a name="output_volume_ids"></a> [volume_ids](#output_volume_ids) | Map of logical volume key to EBS volume ID |
<!-- END_TF_DOCS — DO NOT EDIT ABOVE THIS LINE -->
