Skip to content

Commit 6c01750

Browse files
kastrasCopilotCopilot
authored
feat(aws-backup): added first release (#950)
* chore(aws-backup): added first release * cicd(wf): added aws-backup * Update modules/aws-backup/_examples/vault_with_plan_and_selection/main.tf Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update modules/aws-backup/main.tf Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update modules/aws-backup/docs/footer.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update modules/aws-backup/_examples/vault_with_plan_and_selection/main.tf Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update modules/aws-backup/docs/header.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update modules/aws-backup/_examples/vault_with_plan_selection_with_replication/main.tf Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update modules/aws-backup/variables.tf Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update modules/aws-backup/docs/header.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update modules/aws-backup/_examples/vault_with_plan_selection_with_replication/main.tf Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update modules/aws-backup/main.tf Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update modules/aws-backup/main.tf Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update modules/aws-backup/main.tf Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update modules/aws-backup/_examples/minimal/main.tf Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update modules/aws-backup/iam-policy-roles.tf Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * feat(aws-backup): update with copilot data * feat(aws-backup): update with copilot data * feat(aws-backup): update with copilot data * fix(aws-backup): correct documentation grammar and typos (#951) * Initial plan * fix(aws-backup): correct grammar and typos in documentation Co-authored-by: kastras <46498851+kastras@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: kastras <46498851+kastras@users.noreply.github.com> * Update modules/aws-backup/main.tf Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update modules/aws-backup/docs/header.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix(aws-backup): typo in documentation * fix(aws-backup): update copy_action in plan * refactor(aws-backup): update try in tf code --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
1 parent 4569637 commit 6c01750

14 files changed

Lines changed: 880 additions & 0 deletions

File tree

.release-please-manifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"modules/azure-disks-backup": "1.2.3",
33
"modules/aws-sso": "0.6.1",
4+
"modules/aws-backup": "0.0.0",
45
"modules/azure-resource-group": "1.5.1",
56
"modules/azure-oidc": "1.4.1",
67
"modules/azure-flexible-server-postgresql": "3.1.2",
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
formatter: "markdown" # this is required
2+
3+
version: ""
4+
5+
header-from: docs/header.md
6+
footer-from: docs/footer.md
7+
8+
recursive:
9+
enabled: false
10+
path: modules
11+
include-main: true
12+
13+
sections:
14+
hide: []
15+
show: []
16+
17+
content: ""
18+
19+
output:
20+
file: "README.md"
21+
mode: inject
22+
template: |-
23+
<!-- BEGIN_TF_DOCS -->
24+
{{ .Content }}
25+
<!-- END_TF_DOCS -->
26+
27+
output-values:
28+
enabled: false
29+
from: ""
30+
31+
sort:
32+
enabled: true
33+
by: name
34+
35+
settings:
36+
anchor: true
37+
color: true
38+
default: true
39+
description: false
40+
escape: true
41+
hide-empty: false
42+
html: true
43+
indent: 2
44+
lockfile: true
45+
read-comments: true
46+
required: true
47+
sensitive: true
48+
type: true

modules/aws-backup/README.md

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
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 -->
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Example: Minimal AWS Backup vault creation
2+
3+
terraform {
4+
required_version = ">= 1.5"
5+
required_providers {
6+
aws = {
7+
source = "hashicorp/aws"
8+
version = "~> 6.3"
9+
}
10+
}
11+
}
12+
13+
provider "aws" {
14+
region = "eu-west-1"
15+
}
16+
17+
module "backup" {
18+
source = "./../.."
19+
20+
aws_backup_vault = [{
21+
vault_name = "my-vault"
22+
# vault_region = "eu-west-1"
23+
# vault_tags = {
24+
# "one" = "two"
25+
# "tree" = "four"
26+
# }
27+
}
28+
]
29+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Example: AWS Backup vault with plan and selection
2+
3+
terraform {
4+
required_version = ">= 1.5"
5+
required_providers {
6+
aws = {
7+
source = "hashicorp/aws"
8+
version = "~> 6.3"
9+
}
10+
}
11+
}
12+
13+
provider "aws" {
14+
region = "eu-west-1"
15+
}
16+
17+
module "backup" {
18+
source = "./../.."
19+
20+
aws_backup_vault = [{
21+
vault_name = "only-rds-backup"
22+
# vault_region = "eu-west-1"
23+
# vault_tags = {
24+
# "one" = "two"
25+
# "tree" = "four"
26+
# }
27+
plan = [{
28+
name = "only-rds-daily-backup"
29+
rule_name = "my-rule"
30+
schedule = "cron(0 12 * * ? *)"
31+
backup_selection_conditions = {
32+
string_equals = [
33+
{ key = "aws:ResourceTag/Component", value = "rds" }
34+
]
35+
}
36+
}]
37+
}
38+
]
39+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Example: AWS Backup vault with plan, selection, and cross-region replication
2+
3+
terraform {
4+
required_version = ">= 1.5"
5+
required_providers {
6+
aws = {
7+
source = "hashicorp/aws"
8+
version = "~> 6.3"
9+
}
10+
}
11+
}
12+
13+
provider "aws" {
14+
region = "eu-west-1"
15+
}
16+
17+
module "backup-cross-region" {
18+
source = "./../.."
19+
aws_backup_vault = [{
20+
vault_name = "only-rds-backup"
21+
vault_region = "us-east-1"
22+
}]
23+
24+
}
25+
module "backup" {
26+
source = "./../.."
27+
28+
aws_backup_vault = [{
29+
vault_name = "only-rds-backup"
30+
# vault_region = "eu-west-1"
31+
# vault_tags = {
32+
# "one" = "two"
33+
# "tree" = "four"
34+
# }
35+
plan = [{
36+
name = "only-rds-daily-backup"
37+
rule_name = "my-rule"
38+
schedule = "cron(0 12 * * ? *)"
39+
backup_selection_conditions = {
40+
string_equals = [
41+
{ key = "aws:ResourceTag/Component", value = "rds" }
42+
]
43+
}
44+
45+
}]
46+
}
47+
]
48+
copy_action_default_values = {
49+
destination_account_id = "123456789012" # Same account id for cross-region copy, different account id for cross-account copy
50+
destination_region = "us-east-1"
51+
delete_after = 8
52+
}
53+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
resource "aws_backup_global_settings" "global" {
2+
for_each = var.enable_cross_account_backup ? { "global" : "global" } : {}
3+
global_settings = {
4+
"isCrossAccountBackupEnabled" = "true"
5+
}
6+
}

0 commit comments

Comments
 (0)