Skip to content

Commit 0ecffa1

Browse files
committed
* Rewrite large paths
* Split rules to predefined rules/custom rules * Add tests
1 parent 2c2ea79 commit 0ecffa1

File tree

17 files changed

+657
-205
lines changed

17 files changed

+657
-205
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ end_of_line = lf
88
indent_size = 2
99
indent_style = space
1010
insert_final_newline = true
11-
max_line_length = 80
11+
max_line_length = 120
1212
trim_trailing_whitespace = true
1313

1414
[*.md]

.github/workflows/test.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
###############
3+
## Run tests ##
4+
###############
5+
6+
#
7+
# Documentation:
8+
# https://help.github.com/en/articles/workflow-syntax-for-github-actions
9+
#
10+
11+
name: Test
12+
on:
13+
pull_request:
14+
push:
15+
branches: [ main ]
16+
17+
##########################
18+
# Prevent duplicate jobs #
19+
##########################
20+
concurrency:
21+
group: ${{ github.repository }}
22+
cancel-in-progress: false
23+
24+
permissions:
25+
id-token: write
26+
contents: read
27+
28+
###############
29+
# Run the job #
30+
###############
31+
jobs:
32+
terraform-test:
33+
name: Terraform Test
34+
runs-on: ubuntu-latest
35+
steps:
36+
############################
37+
# Checkout the source code #
38+
############################
39+
- name: Checkout
40+
uses: actions/checkout@v3
41+
42+
#############################
43+
# Configure AWS credentials #
44+
#############################
45+
- name: Configure AWS credentials
46+
uses: aws-actions/configure-aws-credentials@v2
47+
with:
48+
role-to-assume: arn:aws:iam::${{ vars.AWS_TESTING_ACCOUNT_ID }}:role/${{ vars.AWS_TESTING_ROLE }}
49+
aws-region: ${{ vars.AWS_TESTING_REGION }}
50+
mask-aws-account-id: false
51+
52+
#############
53+
# Run tests #
54+
#############
55+
- name: Run Tests
56+
timeout-minutes: 30
57+
run: terraform init && terraform test

.terraform-docs.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,19 @@ content: |-
2626
# Examples
2727
### Basic Example
2828
```hcl
29-
{{ include "examples/basic-example/main.tf" }}
29+
{{ include "examples/minimal/main.tf" }}
3030
```
3131
3232
### With Rules
3333
```hcl
34-
{{ include "examples/with-rules/main.tf" }}
34+
{{ include "examples/with-predefined-rules/main.tf" }}
3535
```
3636
37+
# Predefined Rules
38+
```hcl
39+
{{ include "rules.tf" }}
40+
```
41+
3742
output:
3843
file: "README.md"
3944
mode: inject

README.md

Lines changed: 124 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
[![Release](https://github.com/geekcell/terraform-aws-backup/actions/workflows/release.yaml/badge.svg)](https://github.com/geekcell/terraform-aws-backup/actions/workflows/release.yaml)
88
[![Validate](https://github.com/geekcell/terraform-aws-backup/actions/workflows/validate.yaml/badge.svg)](https://github.com/geekcell/terraform-aws-backup/actions/workflows/validate.yaml)
99
[![Lint](https://github.com/geekcell/terraform-aws-backup/actions/workflows/linter.yaml/badge.svg)](https://github.com/geekcell/terraform-aws-backup/actions/workflows/linter.yaml)
10+
[![Test](https://github.com/geekcell/terraform-aws-backup/actions/workflows/test.yaml/badge.svg)](https://github.com/geekcell/terraform-aws-backup/actions/workflows/test.yaml)
1011

1112
### Security
1213
[![Infrastructure Tests](https://www.bridgecrew.cloud/badges/github/geekcell/terraform-aws-backup/general)](https://www.bridgecrew.cloud/link/badge?vcs=github&fullRepo=geekcell%2Fterraform-aws-backup&benchmark=INFRASTRUCTURE+SECURITY)
@@ -37,7 +38,7 @@
3738

3839
This Terraform module provides a preconfigured solution for setting up
3940
AWS Backup in your AWS account. With this module, you can easily and
40-
efficiently create and manage backup policies for your AWS resources. Our
41+
efficiently create and manage backups for your AWS resources. Our
4142
team has extensive experience working with AWS Backup and has optimized
4243
this module to provide the best possible experience for users.
4344

@@ -53,19 +54,30 @@ great choice.
5354

5455
| Name | Description | Type | Default | Required |
5556
|------|-------------|------|---------|:--------:|
56-
| <a name="input_backup_name"></a> [backup\_name](#input\_backup\_name) | The display name of a backup plan. | `string` | n/a | yes |
57-
| <a name="input_changeable_for_days"></a> [changeable\_for\_days](#input\_changeable\_for\_days) | The number of days before the lock date. If omitted creates a vault lock in governance mode, otherwise it will create a vault lock in compliance mode. | `number` | `null` | no |
57+
| <a name="input_changeable_for_days"></a> [changeable\_for\_days](#input\_changeable\_for\_days) | The number of days before the lock date. If omitted creates a vault lock in governance mode, otherwise it will create<br> a vault lock in compliance mode. When you apply this setting:<br><br> The vault will become immutable in 3 days after applying. You have 3 days of grace time to manage or delete the vault<br> lock before it becomes immutable. During this time, only those users with specific IAM permissions can make changes.<br><br> Once the vault is locked in compliance mode, it cannot be managed or deleted by anyone, even the root user or AWS.<br> The only way to deactivate the lock is to terminate the account, which will delete all the backups.<br><br> Since you cannot delete the Vault, it will be charged for backups until that date. Be careful! | `number` | `null` | no |
58+
| <a name="input_custom_rules"></a> [custom\_rules](#input\_custom\_rules) | Backup rules to add to the AWS Backup Vault. See examples for usage. | <pre>list(object({<br> name = string<br> schedule = optional(string)<br><br> start_window = optional(number)<br> completion_window = optional(number)<br><br> enable_continuous_backup = optional(bool)<br> recovery_point_tags = optional(map(string), {})<br><br> lifecycle = optional(object({<br> cold_storage_after = optional(number)<br> delete_after = optional(number)<br> }))<br><br> copy_action = optional(object({<br> destination_vault_arn = optional(string)<br> lifecycle = optional(object({<br> cold_storage_after = optional(number)<br> delete_after = optional(number)<br> }))<br> }))<br> }))</pre> | `[]` | no |
59+
| <a name="input_enable_customer_managed_kms"></a> [enable\_customer\_managed\_kms](#input\_enable\_customer\_managed\_kms) | Whether to enable customer managed KMS encryption for the backup vault. | `bool` | `false` | no |
60+
| <a name="input_enable_vault_lock"></a> [enable\_vault\_lock](#input\_enable\_vault\_lock) | Whether to enable Vault Lock for the backup vault. | `bool` | `false` | no |
61+
| <a name="input_enable_windows_vss_backup"></a> [enable\_windows\_vss\_backup](#input\_enable\_windows\_vss\_backup) | Whether to enable Windows VSS backup for the backup plan. | `bool` | `false` | no |
62+
| <a name="input_kms_key_id"></a> [kms\_key\_id](#input\_kms\_key\_id) | The ARN of the KMS Key to use to encrypt your backups. If left empty, the default AWS KMS will be used. | `string` | `null` | no |
5863
| <a name="input_max_retention_days"></a> [max\_retention\_days](#input\_max\_retention\_days) | The maximum retention period that the vault retains its recovery points. | `number` | `365` | no |
5964
| <a name="input_min_retention_days"></a> [min\_retention\_days](#input\_min\_retention\_days) | The minimum retention period that the vault retains its recovery points. | `number` | `7` | no |
60-
| <a name="input_resources"></a> [resources](#input\_resources) | An array of strings that either contain Amazon Resource Names (ARNs) or match patterns of resources to assign to a backup plan. | `list(string)` | n/a | yes |
61-
| <a name="input_rules"></a> [rules](#input\_rules) | Backup rules to add to the AWS Backup Vault. See examples for usage. | <pre>list(object({<br> name = string<br> schedule = string<br> start_window = number<br> completion_window = number<br> enable_continuous_backup = bool<br> lifecycle = map(string)<br> }))</pre> | <pre>[<br> {<br> "completion_window": 240,<br> "enable_continuous_backup": false,<br> "lifecycle": {<br> "cold_storage_after": 1,<br> "delete_after": 365<br> },<br> "name": "weekly-snapshot",<br> "schedule": "cron(0 3 ? * 2,3,4,5,6,7,1 *)",<br> "start_window": 60<br> },<br> {<br> "completion_window": 240,<br> "enable_continuous_backup": false,<br> "lifecycle": {<br> "cold_storage_after": 1,<br> "delete_after": 365<br> },<br> "name": "monthly-snapshot",<br> "schedule": "cron(0 3 1 * ? *)",<br> "start_window": 60<br> },<br> {<br> "completion_window": 240,<br> "enable_continuous_backup": false,<br> "lifecycle": {<br> "cold_storage_after": 1,<br> "delete_after": 730<br> },<br> "name": "quarterly-snapshot",<br> "schedule": "cron(0 3 1 1,4,7,10 ? *)",<br> "start_window": 60<br> },<br> {<br> "completion_window": 240,<br> "enable_continuous_backup": false,<br> "lifecycle": {<br> "cold_storage_after": 1,<br> "delete_after": 3650<br> },<br> "name": "yearly-snapshot",<br> "schedule": "cron(0 3 1 1 ? *)",<br> "start_window": 60<br> },<br> {<br> "completion_window": 240,<br> "enable_continuous_backup": true,<br> "lifecycle": {<br> "cold_storage_after": null,<br> "delete_after": 35<br> },<br> "name": "daily-snapshot",<br> "schedule": "cron(0 3 ? * * *)",<br> "start_window": 60<br> }<br>]</pre> | no |
62-
| <a name="input_service"></a> [service](#input\_service) | The service that the resource belongs to. | `string` | n/a | yes |
65+
| <a name="input_plan_name"></a> [plan\_name](#input\_plan\_name) | The display name of the backup plan. | `string` | n/a | yes |
66+
| <a name="input_predefined_rules"></a> [predefined\_rules](#input\_predefined\_rules) | A list of predefined backup rules to add to the AWS Backup Plan. See examples for usage. | `list(string)` | `[]` | no |
67+
| <a name="input_resources"></a> [resources](#input\_resources) | An array of strings that either contain Amazon Resource Names (ARNs) or match patterns of resources to assign to a backup plan. | `list(string)` | `[]` | no |
68+
| <a name="input_role_arn"></a> [role\_arn](#input\_role\_arn) | The ARN of the IAM role that AWS Backup uses to authenticate when restoring or backing up the target resources. If left empty, a default role will be created. | `string` | `null` | no |
6369
| <a name="input_tags"></a> [tags](#input\_tags) | Tags to add to the AWS Backup. | `map(any)` | `{}` | no |
70+
| <a name="input_vault_force_destroy"></a> [vault\_force\_destroy](#input\_vault\_force\_destroy) | Whether to allow the backup vault to be destroyed even if it contains recovery points. | `string` | `false` | no |
6471
| <a name="input_vault_name"></a> [vault\_name](#input\_vault\_name) | Name of the backup vault to create. | `string` | n/a | yes |
6572

6673
## Outputs
6774

68-
No outputs.
75+
| Name | Description |
76+
|------|-------------|
77+
| <a name="output_backup_plan_arn"></a> [backup\_plan\_arn](#output\_backup\_plan\_arn) | The ARN of the backup plan. |
78+
| <a name="output_backup_plan_id"></a> [backup\_plan\_id](#output\_backup\_plan\_id) | The ID of the backup plan. |
79+
| <a name="output_backup_vault_arn"></a> [backup\_vault\_arn](#output\_backup\_vault\_arn) | The ARN of the backup vault. |
80+
| <a name="output_backup_vault_id"></a> [backup\_vault\_id](#output\_backup\_vault\_id) | The ID of the backup vault. |
6981

7082
## Providers
7183

@@ -75,27 +87,20 @@ No outputs.
7587

7688
## Resources
7789

78-
- resource.aws_backup_plan.main (main.tf#55)
79-
- resource.aws_backup_selection.main (main.tf#48)
80-
- resource.aws_backup_vault.main (main.tf#18)
81-
- resource.aws_backup_vault_lock_configuration.main (main.tf#25)
82-
- resource.aws_iam_role.main (main.tf#96)
83-
- resource.aws_iam_role_policy_attachment.main_backup (main.tf#103)
84-
- resource.aws_iam_role_policy_attachment.main_restore (main.tf#108)
85-
- resource.aws_iam_role_policy_attachment.s3_backup (main.tf#113)
86-
- resource.aws_iam_role_policy_attachment.s3_restore (main.tf#118)
87-
- data source.aws_iam_policy_document.main (data.tf#1)
90+
- resource.aws_backup_plan.main (main.tf#45)
91+
- resource.aws_backup_selection.main (main.tf#103)
92+
- resource.aws_backup_vault.main (main.tf#27)
93+
- resource.aws_backup_vault_lock_configuration.main (main.tf#35)
8894

8995
# Examples
9096
### Basic Example
9197
```hcl
9298
module "basic-example" {
9399
source = "../../"
94100
95-
vault_name = "main"
96-
backup_name = "rds"
97-
service = "s3"
98-
resources = ["arn:aws:s3:::my-bucket"]
101+
vault_name = "main"
102+
plan_name = "s3"
103+
resources = ["arn:aws:s3:::my-bucket"]
99104
}
100105
```
101106

@@ -104,14 +109,14 @@ module "basic-example" {
104109
module "with-rules" {
105110
source = "../../"
106111
107-
vault_name = "main"
108-
backup_name = "rds"
109-
service = "s3"
110-
resources = ["arn:aws:s3:::my-bucket"]
112+
vault_name = "main"
113+
plan_name = "s3"
114+
resources = ["arn:aws:s3:::my-bucket"]
111115
112-
rules = [
116+
predefined_rules = ["daily-snapshot", "monthly-snapshot"]
117+
custom_rules = [
113118
{
114-
name = "weekly-snapshot"
119+
name = "my-custom-rule"
115120
schedule = "cron(0 3 ? * 2,3,4,5,6,7,1 *)"
116121
start_window = 60
117122
completion_window = 240
@@ -125,4 +130,96 @@ module "with-rules" {
125130
]
126131
}
127132
```
133+
134+
# Predefined Rules
135+
```hcl
136+
locals {
137+
predefined_rules = [
138+
# At 03:00 AM UTC, daily
139+
{
140+
name = "daily-snapshot"
141+
schedule = "cron(0 3 ? * * *)"
142+
start_window = 60
143+
completion_window = 240
144+
enable_continuous_backup = true
145+
recovery_point_tags = {}
146+
147+
lifecycle = {
148+
cold_storage_after = null
149+
delete_after = 35 # 5 weeks
150+
}
151+
152+
copy_action = null
153+
},
154+
155+
# At 03:00 AM UTC, every Sunday
156+
{
157+
name = "weekly-snapshot"
158+
schedule = "cron(0 3 ? * SUN *)"
159+
start_window = 60
160+
completion_window = 240
161+
enable_continuous_backup = true
162+
recovery_point_tags = {}
163+
164+
lifecycle = {
165+
cold_storage_after = null
166+
delete_after = 183 # 6 months
167+
}
168+
169+
copy_action = null
170+
},
171+
172+
# At 03:00 AM UTC, on day 1 of the month
173+
{
174+
name = "monthly-snapshot"
175+
schedule = "cron(0 3 1 * ? *)"
176+
start_window = 60
177+
completion_window = 240
178+
enable_continuous_backup = false
179+
recovery_point_tags = {}
180+
181+
lifecycle = {
182+
cold_storage_after = 1 # day
183+
delete_after = 365 # 1 year
184+
}
185+
186+
copy_action = null
187+
},
188+
189+
# At 03:00 AM UTC, on day 1 of the month, only in January, April, July, and October
190+
{
191+
name = "quarterly-snapshot"
192+
schedule = "cron(0 3 1 1,4,7,10 ? *)"
193+
start_window = 60
194+
completion_window = 240
195+
enable_continuous_backup = false
196+
recovery_point_tags = {}
197+
198+
lifecycle = {
199+
cold_storage_after = 1 # day
200+
delete_after = 730 # 2 years
201+
}
202+
203+
copy_action = null
204+
},
205+
206+
# At 03:00 AM UTC, on day 1 of the month, only in January
207+
{
208+
name = "yearly-snapshot"
209+
schedule = "cron(0 3 1 1 ? *)"
210+
start_window = 60
211+
completion_window = 240
212+
enable_continuous_backup = false
213+
recovery_point_tags = {}
214+
215+
lifecycle = {
216+
cold_storage_after = 1 # day
217+
delete_after = 3650 # 10 years
218+
}
219+
220+
copy_action = null
221+
}
222+
]
223+
}
224+
```
128225
<!-- END_TF_DOCS -->

data.tf

Lines changed: 0 additions & 11 deletions
This file was deleted.

docs/20-badges.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[![Release](https://github.com/geekcell/terraform-aws-backup/actions/workflows/release.yaml/badge.svg)](https://github.com/geekcell/terraform-aws-backup/actions/workflows/release.yaml)
55
[![Validate](https://github.com/geekcell/terraform-aws-backup/actions/workflows/validate.yaml/badge.svg)](https://github.com/geekcell/terraform-aws-backup/actions/workflows/validate.yaml)
66
[![Lint](https://github.com/geekcell/terraform-aws-backup/actions/workflows/linter.yaml/badge.svg)](https://github.com/geekcell/terraform-aws-backup/actions/workflows/linter.yaml)
7+
[![Test](https://github.com/geekcell/terraform-aws-backup/actions/workflows/test.yaml/badge.svg)](https://github.com/geekcell/terraform-aws-backup/actions/workflows/test.yaml)
78

89
### Security
910
[![Infrastructure Tests](https://www.bridgecrew.cloud/badges/github/geekcell/terraform-aws-backup/general)](https://www.bridgecrew.cloud/link/badge?vcs=github&fullRepo=geekcell%2Fterraform-aws-backup&benchmark=INFRASTRUCTURE+SECURITY)

examples/basic-example/main.tf

Lines changed: 0 additions & 8 deletions
This file was deleted.

examples/minimal/main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module "basic-example" {
2+
source = "../../"
3+
4+
vault_name = "main"
5+
plan_name = "s3"
6+
resources = ["arn:aws:s3:::my-bucket"]
7+
}

examples/with-rules/main.tf renamed to examples/with-predefined-rules/main.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
module "with-rules" {
22
source = "../../"
33

4-
vault_name = "main"
5-
backup_name = "rds"
6-
service = "s3"
7-
resources = ["arn:aws:s3:::my-bucket"]
4+
vault_name = "main"
5+
plan_name = "s3"
6+
resources = ["arn:aws:s3:::my-bucket"]
87

9-
rules = [
8+
predefined_rules = ["daily-snapshot", "monthly-snapshot"]
9+
custom_rules = [
1010
{
11-
name = "weekly-snapshot"
11+
name = "my-custom-rule"
1212
schedule = "cron(0 3 ? * 2,3,4,5,6,7,1 *)"
1313
start_window = 60
1414
completion_window = 240

0 commit comments

Comments
 (0)