|
| 1 | +<!-- BEGIN_TF_DOCS --> |
| 2 | +# **AWS BACKUP Terraform Module** |
| 3 | + |
| 4 | +## Overview |
| 5 | + |
| 6 | +This module provides configuration for AWS Backup, including vault creation, backup plans, and resource selection. |
| 7 | + |
| 8 | +## Key Features |
| 9 | + |
| 10 | +- **Vault**: Creates a vault to store backups. |
| 11 | +- **Plan**: Creates backup plans with options to replicate backups to other vaults, including cross-account and cross-region replication. |
| 12 | +- **Selections**: Allows selection of resources for backup using tags or specifying the resource ARN. |
| 13 | + |
| 14 | +## Basic Usage |
| 15 | + |
| 16 | +### Minimal Example (Creates only a vault to store backups; this option does not perform backups!) |
| 17 | + |
| 18 | +```hcl |
| 19 | +module "backup" { |
| 20 | + source = "github.com/prefapp/tfm/modules/aws-backup" |
| 21 | + aws_backup_vault = [{ |
| 22 | + vault_name = "my-vault" |
| 23 | + }] |
| 24 | +} |
| 25 | +``` |
| 26 | + |
| 27 | +### Example with plan and tag selection |
| 28 | + |
| 29 | +```hcl |
| 30 | +module "backup" { |
| 31 | + source = "github.com/prefapp/tfm/modules/aws-backup" |
| 32 | + aws_backup_vault = [{ |
| 33 | + vault_name = "only-rds-component-tags-backup" |
| 34 | + # vault_region = "eu-west-1" |
| 35 | + # vault_tags = { |
| 36 | + # "one" = "two" |
| 37 | + # "three" = "four" |
| 38 | + # } |
| 39 | + plan = [{ |
| 40 | + name = "only-rds-daily-backup" |
| 41 | + rule_name = "my-rule" |
| 42 | + schedule = "cron(0 12 * * ? *)" |
| 43 | + backup_selection_conditions = { |
| 44 | + string_equals = [ |
| 45 | + { key = "aws:ResourceTag/Component", value = "rds" } |
| 46 | + ] |
| 47 | + } |
| 48 | + }] |
| 49 | + } |
| 50 | + ] |
| 51 | +} |
| 52 | +``` |
| 53 | + |
| 54 | +### With alias, replication to other regions, and access from other AWS accounts |
| 55 | + |
| 56 | +/!\ Important: Only works with aws organizations, you need to enable cross\_account\_backup in organization main account |
| 57 | + |
| 58 | +This only works in organization main account |
| 59 | +```hcl |
| 60 | +module "backup" { |
| 61 | + source = "github.com/prefapp/tfm/modules/aws-backup" |
| 62 | +
|
| 63 | + enable_cross_account_backup = true |
| 64 | +} |
| 65 | +``` |
| 66 | + |
| 67 | +For the accounts in your organization |
| 68 | + |
| 69 | +In the account that only receives backups: |
| 70 | + |
| 71 | +```hcl |
| 72 | +module "backup" { |
| 73 | + source = "github.com/prefapp/tfm/modules/aws-backup" |
| 74 | + aws_backup_vault = [{ |
| 75 | + vault_name = "only-rds-component-tags-backup" |
| 76 | + # vault_region = "eu-west-1" |
| 77 | + # vault_tags = { |
| 78 | + # "one" = "two" |
| 79 | + # "three" = "four" |
| 80 | + # } |
| 81 | + } |
| 82 | + ] |
| 83 | +} |
| 84 | +``` |
| 85 | + |
| 86 | +In the account that will make backups and send them to another account |
| 87 | + |
| 88 | +```hcl |
| 89 | +module "backup" { |
| 90 | + source = "github.com/prefapp/tfm/modules/aws-backup" |
| 91 | + aws_backup_vault = [{ |
| 92 | + vault_name = "only-rds-component-tags-backup" |
| 93 | + # vault_region = "eu-west-1" |
| 94 | + # vault_tags = { |
| 95 | + # "one" = "two" |
| 96 | + # "three" = "four" |
| 97 | + # } |
| 98 | + plan = [{ |
| 99 | + name = "only-rds-daily-backup" |
| 100 | + rule_name = "my-rule" |
| 101 | + schedule = "cron(0 12 * * ? *)" |
| 102 | + backup_selection_conditions = { |
| 103 | + string_equals = [ |
| 104 | + { key = "aws:ResourceTag/Component", value = "rds" } |
| 105 | + ] |
| 106 | + } |
| 107 | + }] |
| 108 | + } |
| 109 | + ] |
| 110 | + copy_action_default_values = { |
| 111 | + destination_account_id = "098765432109" |
| 112 | + destination_region = "eu-west-1" |
| 113 | + delete_after = 7 |
| 114 | + } |
| 115 | +} |
| 116 | +``` |
| 117 | + |
| 118 | +## File Structure |
| 119 | + |
| 120 | +The module is organized with the following directory and file structure: |
| 121 | + |
| 122 | +``` |
| 123 | +├── backup-global-configuration.tf |
| 124 | +├── docs |
| 125 | +│ ├── footer.md |
| 126 | +│ └── header.md |
| 127 | +├── _examples |
| 128 | +│ ├── minimal |
| 129 | +│ │ └── main.tf |
| 130 | +│ ├── vault_with_plan_and_selection |
| 131 | +│ │ └── main.tf |
| 132 | +│ └── vault_with_plan_selection_with_replication |
| 133 | +│ └── main.tf |
| 134 | +├── iam-policy-roles.tf |
| 135 | +├── main.tf |
| 136 | +└── variables.tf |
| 137 | +``` |
| 138 | + |
| 139 | +- **main.tf**: Entry point that wires together all module components, here they create vaults, plans and selections. |
| 140 | +- **iam-policy-roles.tf**: Policy document for aws vaults. |
| 141 | +- **backup-global-configuration.tf**: Configuration for enable cross account backup in organizations. |
| 142 | + |
| 143 | +## Requirements |
| 144 | + |
| 145 | +| Name | Version | |
| 146 | +|------|---------| |
| 147 | +| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.5 | |
| 148 | +| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 6.3 | |
| 149 | + |
| 150 | +## Providers |
| 151 | + |
| 152 | +| Name | Version | |
| 153 | +|------|---------| |
| 154 | +| <a name="provider_aws"></a> [aws](#provider\_aws) | ~> 6.3 | |
| 155 | + |
| 156 | +## Modules |
| 157 | + |
| 158 | +No modules. |
| 159 | + |
| 160 | +## Resources |
| 161 | + |
| 162 | +| Name | Type | |
| 163 | +|------|------| |
| 164 | +| [aws_backup_global_settings.global](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/backup_global_settings) | resource | |
| 165 | +| [aws_backup_plan.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/backup_plan) | resource | |
| 166 | +| [aws_backup_selection.resource_selection](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/backup_selection) | resource | |
| 167 | +| [aws_backup_selection.tag_selection](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/backup_selection) | resource | |
| 168 | +| [aws_backup_vault.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/backup_vault) | resource | |
| 169 | +| [aws_backup_vault_policy.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/backup_vault_policy) | resource | |
| 170 | +| [aws_iam_role.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource | |
| 171 | +| [aws_iam_role_policy_attachment.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource | |
| 172 | +| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source | |
| 173 | +| [aws_iam_policy_document.assume_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | |
| 174 | +| [aws_iam_policy_document.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | |
| 175 | + |
| 176 | +## Inputs |
| 177 | + |
| 178 | +| Name | Description | Type | Default | Required | |
| 179 | +|------|-------------|------|---------|:--------:| |
| 180 | +| <a name="input_aws_backup_vault"></a> [aws\_backup\_vault](#input\_aws\_backup\_vault) | List of objects defining the backup vault configuration, including backup plans and replication rules. | <pre>list(object({<br/> vault_name = string<br/> vault_region = optional(string)<br/> vault_tags = optional(map(string))<br/> vault_kms_key_arn = optional(string)<br/><br/> plan = optional(list(object({<br/> name = string<br/> rule_name = string<br/> schedule = string<br/> schedule_expression_timezone = optional(string)<br/> start_window = optional(number)<br/> completion_window = optional(number)<br/> # Structure for dynamic conditions in aws_backup_selection<br/> # Example usage:<br/> # backup_selection_conditions = {<br/> # string_equals = [<br/> # { key = "aws:ResourceTag/Component", value = "rds" }<br/> # ]<br/> # string_like = [<br/> # { key = "aws:ResourceTag/Application", value = "app*" }<br/> # ]<br/> # string_not_equals = [<br/> # { key = "aws:ResourceTag/Backup", value = "false" }<br/> # ]<br/> # string_not_like = [<br/> # { key = "aws:ResourceTag/Environment", value = "test*" }<br/> # ]<br/> # }<br/> backup_selection_conditions = optional(object({<br/> string_equals = optional(list(object({ key = string, value = string })))<br/> string_like = optional(list(object({ key = string, value = string })))<br/> string_not_equals = optional(list(object({ key = string, value = string })))<br/> string_not_like = optional(list(object({ key = string, value = string })))<br/> }))<br/> backup_selection_arn_resources = optional(list(string))<br/> lifecycle = optional(object({<br/> cold_storage_after = number<br/> delete_after = number<br/> }))<br/> advanced_backup_setting = optional(list(object({<br/> backup_options = map(string)<br/> resource_type = string<br/> })))<br/> scan_action = optional(list(object({<br/> malware_scanner = string<br/> scan_action_type = string<br/> })))<br/> recovery_point_tags = optional(map(string))<br/> tags = optional(map(string))<br/> copy_action = optional(list(object({<br/> destination_vault_arn = string<br/> delete_after = optional(number)<br/> })))<br/> })<br/> ))<br/> })<br/> )</pre> | `[]` | no | |
| 181 | +| <a name="input_aws_kms_key_vault_arn"></a> [aws\_kms\_key\_vault\_arn](#input\_aws\_kms\_key\_vault\_arn) | ARN of the KMS key used to encrypt the backup vault. If not provided, the default AWS Backup vault encryption will be used. | `string` | `null` | no | |
| 182 | +| <a name="input_copy_action_default_values"></a> [copy\_action\_default\_values](#input\_copy\_action\_default\_values) | Default values for the copy action configuration in backup plan rules. If not provided, the copy action will not be created. | <pre>object({<br/> destination_account_id = string<br/> destination_region = string<br/> delete_after = number<br/> })</pre> | <pre>{<br/> "delete_after": 14,<br/> "destination_account_id": null,<br/> "destination_region": null<br/>}</pre> | no | |
| 183 | +| <a name="input_enable_cross_account_backup"></a> [enable\_cross\_account\_backup](#input\_enable\_cross\_account\_backup) | Enable cross-account backup in AWS Backup global settings. If set to true, the module will manage the global settings resource to enable cross-account backup. If set to false, you can configure it separately if needed. | `bool` | `false` | no | |
| 184 | +| <a name="input_tags"></a> [tags](#input\_tags) | Default tags to apply to all resources. | `map(string)` | `{}` | no | |
| 185 | + |
| 186 | +## Outputs |
| 187 | + |
| 188 | +No outputs. |
| 189 | + |
| 190 | +## Examples |
| 191 | + |
| 192 | +For detailed examples, refer to the [module examples](https://github.com/prefapp/tfm/tree/main/modules/aws-backup/_examples): |
| 193 | + |
| 194 | +- [Minimal](https://github.com/prefapp/tfm/tree/main/modules/aws-backup/_examples/minimal) – Minimal vault creation |
| 195 | +- [Vault with plan and selection](https://github.com/prefapp/tfm/tree/main/modules/aws-backup/_examples/vault\_with\_plan\_and\_selection) – Backup vault creation with configuration of plans and backup selections |
| 196 | +- [Vault with plan, selection, and replication](https://github.com/prefapp/tfm/tree/main/modules/aws-backup/_examples/vault\_with\_plan\_selection\_with\_replication) – KMS key creation with alias, cross-region replication, and additional account access |
| 197 | + |
| 198 | +## Remote Resources |
| 199 | +- Terraform: https://www.terraform.io/ |
| 200 | +- Amazon AWS Backup: [https://aws.amazon.com/es/backup/](https://aws.amazon.com/es/backup/) |
| 201 | +- Terraform AWS Provider: [https://registry.terraform.io/providers/hashicorp/aws/latest](https://registry.terraform.io/providers/hashicorp/aws/latest) |
| 202 | + |
| 203 | +## Support |
| 204 | + |
| 205 | +For issues, questions, or contributions related to this module, please visit the repository’s issue tracker: [https://github.com/prefapp/tfm/issues](https://github.com/prefapp/tfm/issues) |
| 206 | +<!-- END_TF_DOCS --> |
0 commit comments