Skip to content

Commit 2a2fbdc

Browse files
magreenbaumantonbabenkobryantbiggs
authored
feat: Logging and Snapshot copy resources converted to standalone resource equivalents, MSV of Terraform raised to v1.3 (#99)
* logging and snapshot copy * add upgrade readme * Apply suggestions from code review Co-authored-by: Anton Babenko <[email protected]> * bump terraform msv to 1.3 * Update UPGRADE-6.0.md --------- Co-authored-by: Anton Babenko <[email protected]> Co-authored-by: Bryant Biggs <[email protected]>
1 parent 0531a5a commit 2a2fbdc

File tree

7 files changed

+173
-35
lines changed

7 files changed

+173
-35
lines changed

README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,15 @@ module "redshift" {
178178

179179
| Name | Version |
180180
|------|---------|
181-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
182-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.35 |
181+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
182+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.45 |
183183
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 3.0 |
184184

185185
## Providers
186186

187187
| Name | Version |
188188
|------|---------|
189-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.35 |
189+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.45 |
190190
| <a name="provider_random"></a> [random](#provider\_random) | >= 3.0 |
191191

192192
## Modules
@@ -204,8 +204,10 @@ No modules.
204204
| [aws_redshift_cluster.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/redshift_cluster) | resource |
205205
| [aws_redshift_cluster_iam_roles.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/redshift_cluster_iam_roles) | resource |
206206
| [aws_redshift_endpoint_access.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/redshift_endpoint_access) | resource |
207+
| [aws_redshift_logging.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/redshift_logging) | resource |
207208
| [aws_redshift_parameter_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/redshift_parameter_group) | resource |
208209
| [aws_redshift_scheduled_action.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/redshift_scheduled_action) | resource |
210+
| [aws_redshift_snapshot_copy.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/redshift_snapshot_copy) | resource |
209211
| [aws_redshift_snapshot_schedule.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/redshift_snapshot_schedule) | resource |
210212
| [aws_redshift_snapshot_schedule_association.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/redshift_snapshot_schedule_association) | resource |
211213
| [aws_redshift_subnet_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/redshift_subnet_group) | resource |

UPGRADE-6.0.md

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Upgrade from v5.x to v6.x
2+
3+
Please consult the `examples` directory for reference example configurations. If you find a bug, please open an issue with supporting configuration to reproduce.
4+
5+
## List of backwards incompatible changes
6+
7+
- Minimum supported version of Terraform AWS provider updated to `v5.45` to support latest resources
8+
- Minimum supported version of Terraform raised to `v1.3`
9+
- logging block within the `aws_redshift_cluster` resource has been replaced with a standalone resource. After upgrade, a new resource for logging will be created.
10+
- snapshot_copy block within the `aws_redshift_cluster` resource has been replaced with a standalone resource. After upgrade, to prevent errors due to already existing `snapshot_copy` configurations, import of the new resource is required.
11+
12+
## Additional changes
13+
14+
### Added
15+
16+
- `aws_redshift_logging` has been added to replace `logging` block in `aws_redshift_cluster`
17+
- `aws_redshift_snapshot_copy` has been added to replace `snapshot_copy` block in `aws_redshift_cluster`
18+
19+
### Modified
20+
21+
- None
22+
23+
### Removed
24+
25+
- `logging` block in `aws_redshift_cluster`
26+
- `snapshot_copy` block in `aws_redshift_cluster`
27+
28+
### Variable and output changes
29+
30+
1. Removed variables:
31+
32+
- Cluster
33+
- `var.logging.enable` has been removed
34+
35+
2. Renamed variables:
36+
37+
- None
38+
39+
3. Added variables:
40+
41+
- Snapshot Copy
42+
- `var.snapshot_copy.manual_snapshot_retention_period`
43+
44+
4. Removed outputs:
45+
46+
- None
47+
48+
5. Renamed outputs:
49+
50+
- None
51+
52+
6. Added outputs:
53+
54+
- None
55+
56+
## Upgrade Migration
57+
58+
### Before v5.x Example
59+
60+
```hcl
61+
module "redshift" {
62+
source = "terraform-aws-modules/redshift/aws"
63+
version = "~> 5.0"
64+
65+
snapshot_copy = {
66+
destination_region = "us-east-1"
67+
grant_name = aws_redshift_snapshot_copy_grant.useast1.snapshot_copy_grant_name
68+
}
69+
70+
logging = {
71+
enable = true
72+
bucket_name = module.s3_logs.s3_bucket_id
73+
s3_key_prefix = local.s3_prefix
74+
}
75+
}
76+
```
77+
78+
### After v6.x Example
79+
80+
```hcl
81+
module "redshift" {
82+
source = "terraform-aws-modules/redshift/aws"
83+
version = "~> 6.0"
84+
85+
snapshot_copy = {
86+
destination_region = "us-east-1"
87+
grant_name = aws_redshift_snapshot_copy_grant.useast1.snapshot_copy_grant_name
88+
}
89+
90+
logging = {
91+
bucket_name = module.s3_logs.s3_bucket_id
92+
s3_key_prefix = local.s3_prefix
93+
}
94+
}
95+
```
96+
97+
### Diff of Before vs After
98+
99+
```diff
100+
# module.redshift.aws_redshift_logging.this[0] will be created
101+
+ resource "aws_redshift_logging" "this" {
102+
+ bucket_name = "ex-complete20240414012816938100000003"
103+
+ cluster_identifier = "ex-complete"
104+
+ id = (known after apply)
105+
+ s3_key_prefix = "redshift/ex-complete/"
106+
}
107+
108+
# module.redshift.aws_redshift_snapshot_copy.this[0] will be created
109+
+ resource "aws_redshift_snapshot_copy" "this" {
110+
+ cluster_identifier = "ex-complete"
111+
+ destination_region = "us-east-1"
112+
+ id = (known after apply)
113+
+ manual_snapshot_retention_period = (known after apply)
114+
+ retention_period = (known after apply)
115+
+ snapshot_copy_grant_name = "ex-complete-us-east-1"
116+
}
117+
```
118+
The `aws_redshift_logging` can be applied or imported. If setting the `log_destination_type`, an apply following an import will be required to clear the remaining diff.
119+
The `aws_redshift_snapshot_copy` resource requires importing if an existing snapshot_copy configuration exists.
120+
121+
### State Move Commands
122+
123+
None required
124+
125+
### State Import Commands
126+
127+
During the migration to v6.x of this module, logging and snapshot_copy resources will be created by this module if those settings are configured. In order to guarantee the best experience and prevent data loss, you will need to import them into terraform state using commands like these:
128+
129+
```bash
130+
terraform import 'module.redshift.aws_redshift_logging.this[0]' <cluster-id>
131+
terraform import 'module.redshift.aws_redshift_snapshot_copy.this[0]' <cluster-id>
132+
```

examples/complete/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ Note that this example may create resources which cost money. Run `terraform des
2323

2424
| Name | Version |
2525
|------|---------|
26-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
27-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.35 |
26+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
27+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.45 |
2828

2929
## Providers
3030

3131
| Name | Version |
3232
|------|---------|
33-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.35 |
34-
| <a name="provider_aws.us_east_1"></a> [aws.us\_east\_1](#provider\_aws.us\_east\_1) | >= 5.35 |
33+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.45 |
34+
| <a name="provider_aws.us_east_1"></a> [aws.us\_east\_1](#provider\_aws.us\_east\_1) | >= 5.45 |
3535

3636
## Modules
3737

examples/complete/main.tf

-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ module "redshift" {
6464
}
6565

6666
logging = {
67-
enable = true
6867
bucket_name = module.s3_logs.s3_bucket_id
6968
s3_key_prefix = local.s3_prefix
7069
}
@@ -221,7 +220,6 @@ module "with_cloudwatch_logging" {
221220
create_cloudwatch_log_group = true
222221
cloudwatch_log_group_retention_in_days = 7
223222
logging = {
224-
enable = true
225223
log_destination_type = "cloudwatch"
226224
log_exports = ["connectionlog", "userlog", "useractivitylog"]
227225
}

examples/complete/versions.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
terraform {
2-
required_version = ">= 1.0"
2+
required_version = ">= 1.3"
33

44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.35"
7+
version = ">= 5.45"
88
}
99
}
1010
}

main.tf

+28-22
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,6 @@ resource "aws_redshift_cluster" "this" {
4646

4747
# iam_roles and default_iam_roles are managed in the aws_redshift_cluster_iam_roles resource below
4848

49-
dynamic "logging" {
50-
for_each = can(var.logging.enable) ? [var.logging] : []
51-
52-
content {
53-
bucket_name = try(logging.value.bucket_name, null)
54-
enable = logging.value.enable
55-
log_destination_type = try(logging.value.log_destination_type, null)
56-
log_exports = try(logging.value.log_exports, null)
57-
s3_key_prefix = try(logging.value.s3_key_prefix, null)
58-
}
59-
}
60-
6149
maintenance_track_name = var.maintenance_track_name
6250
manual_snapshot_retention_period = var.manual_snapshot_retention_period
6351
manage_master_password = var.manage_master_password ? var.manage_master_password : null
@@ -74,16 +62,6 @@ resource "aws_redshift_cluster" "this" {
7462
skip_final_snapshot = var.skip_final_snapshot
7563
snapshot_cluster_identifier = var.snapshot_cluster_identifier
7664

77-
dynamic "snapshot_copy" {
78-
for_each = length(var.snapshot_copy) > 0 ? [var.snapshot_copy] : []
79-
80-
content {
81-
destination_region = snapshot_copy.value.destination_region
82-
grant_name = try(snapshot_copy.value.grant_name, null)
83-
retention_period = try(snapshot_copy.value.retention_period, null)
84-
}
85-
}
86-
8765
snapshot_identifier = var.snapshot_identifier
8866
vpc_security_group_ids = var.vpc_security_group_ids
8967

@@ -322,6 +300,34 @@ resource "aws_redshift_authentication_profile" "this" {
322300
authentication_profile_content = jsonencode(each.value.content)
323301
}
324302

303+
################################################################################
304+
# Logging
305+
################################################################################
306+
307+
resource "aws_redshift_logging" "this" {
308+
count = var.create && length(var.logging) > 0 ? 1 : 0
309+
310+
cluster_identifier = aws_redshift_cluster.this[0].id
311+
bucket_name = try(var.logging.bucket_name, null)
312+
log_destination_type = try(var.logging.log_destination_type, null)
313+
log_exports = try(var.logging.log_exports, null)
314+
s3_key_prefix = try(var.logging.s3_key_prefix, null)
315+
}
316+
317+
################################################################################
318+
# Snapshot Copy
319+
################################################################################
320+
321+
resource "aws_redshift_snapshot_copy" "this" {
322+
count = var.create && length(var.snapshot_copy) > 0 ? 1 : 0
323+
324+
cluster_identifier = aws_redshift_cluster.this[0].id
325+
destination_region = var.snapshot_copy.destination_region
326+
manual_snapshot_retention_period = try(var.snapshot_copy.manual_snapshot_retention_period, null)
327+
retention_period = try(var.snapshot_copy.retention_period, null)
328+
snapshot_copy_grant_name = try(var.snapshot_copy.grant_name, null)
329+
}
330+
325331
################################################################################
326332
# CloudWatch Log Group
327333
################################################################################

versions.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
terraform {
2-
required_version = ">= 1.0"
2+
required_version = ">= 1.3"
33

44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.35"
7+
version = ">= 5.45"
88
}
99

1010
random = {

0 commit comments

Comments
 (0)