Skip to content

Commit 41fc56a

Browse files
feat!: Remove deprecated EC2 classic fields removed in AWS provider v5.0 (#86)
* Remove cluster_security_groups attribute, as the aws_redshift_security_group resource has been removed, following the retirement of EC2-Classic. * fix: Update AWS provider version, ensure example is working as intended --------- Co-authored-by: Bryant Biggs <[email protected]>
1 parent 6022138 commit 41fc56a

File tree

10 files changed

+77
-103
lines changed

10 files changed

+77
-103
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.76.0
3+
rev: v1.80.0
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_validate
@@ -23,7 +23,7 @@ repos:
2323
- '--args=--only=terraform_standard_module_structure'
2424
- '--args=--only=terraform_workspace_remote'
2525
- repo: https://github.com/pre-commit/pre-commit-hooks
26-
rev: v4.3.0
26+
rev: v4.4.0
2727
hooks:
2828
- id: check-merge-conflict
2929
- id: end-of-file-fixer

README.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ module "redshift" {
3030
availability_zone_relocation_enabled = true
3131
3232
snapshot_copy = {
33-
useast1 = {
34-
destination_region = "us-east-1"
35-
grant_name = "example-grant"
36-
}
33+
destination_region = "us-east-1"
34+
grant_name = "example-grant"
3735
}
3836
3937
logging = {
@@ -181,14 +179,14 @@ module "redshift" {
181179
| Name | Version |
182180
|------|---------|
183181
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
184-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.17 |
182+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0 |
185183
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 3.0 |
186184

187185
## Providers
188186

189187
| Name | Version |
190188
|------|---------|
191-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.17 |
189+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.0 |
192190
| <a name="provider_random"></a> [random](#provider\_random) | >= 3.0 |
193191

194192
## Modules
@@ -226,7 +224,7 @@ No modules.
226224
| <a name="input_authentication_profiles"></a> [authentication\_profiles](#input\_authentication\_profiles) | Map of authentication profiles to create | `any` | `{}` | no |
227225
| <a name="input_automated_snapshot_retention_period"></a> [automated\_snapshot\_retention\_period](#input\_automated\_snapshot\_retention\_period) | The number of days that automated snapshots are retained. If the value is 0, automated snapshots are disabled. Even if automated snapshots are disabled, you can still create manual snapshots when you want with create-cluster-snapshot. Default is 1 | `number` | `null` | no |
228226
| <a name="input_availability_zone"></a> [availability\_zone](#input\_availability\_zone) | The EC2 Availability Zone (AZ) in which you want Amazon Redshift to provision the cluster. Can only be changed if `availability_zone_relocation_enabled` is `true` | `string` | `null` | no |
229-
| <a name="input_availability_zone_relocation_enabled"></a> [availability\_zone\_relocation\_enabled](#input\_availability\_zone\_relocation\_enabled) | If `true`, the cluster can be relocated to another availabity zone, either automatically by AWS or when requested. Default is `false`. Available for use on clusters from the RA3 instance family | `bool` | `null` | no |
227+
| <a name="input_availability_zone_relocation_enabled"></a> [availability\_zone\_relocation\_enabled](#input\_availability\_zone\_relocation\_enabled) | If `true`, the cluster can be relocated to another availability zone, either automatically by AWS or when requested. Default is `false`. Available for use on clusters from the RA3 instance family | `bool` | `null` | no |
230228
| <a name="input_cluster_identifier"></a> [cluster\_identifier](#input\_cluster\_identifier) | The Cluster Identifier. Must be a lower case string | `string` | `""` | no |
231229
| <a name="input_cluster_timeouts"></a> [cluster\_timeouts](#input\_cluster\_timeouts) | Create, update, and delete timeout configurations for the cluster | `map(string)` | `{}` | no |
232230
| <a name="input_cluster_version"></a> [cluster\_version](#input\_cluster\_version) | The version of the Amazon Redshift engine software that you want to deploy on the cluster. The version selected runs on all the nodes in the cluster | `string` | `null` | no |
@@ -272,7 +270,7 @@ No modules.
272270
| <a name="input_preferred_maintenance_window"></a> [preferred\_maintenance\_window](#input\_preferred\_maintenance\_window) | The weekly time range (in UTC) during which automated cluster maintenance can occur. Format: `ddd:hh24:mi-ddd:hh24:mi` | `string` | `"sat:10:00-sat:10:30"` | no |
273271
| <a name="input_publicly_accessible"></a> [publicly\_accessible](#input\_publicly\_accessible) | If true, the cluster can be accessed from a public network | `bool` | `false` | no |
274272
| <a name="input_random_password_length"></a> [random\_password\_length](#input\_random\_password\_length) | Length of random password to create. Defaults to `16` | `number` | `16` | no |
275-
| <a name="input_scheduled_actions"></a> [scheduled\_actions](#input\_scheduled\_actions) | Map of maps containing scheduled action defintions | `any` | `{}` | no |
273+
| <a name="input_scheduled_actions"></a> [scheduled\_actions](#input\_scheduled\_actions) | Map of maps containing scheduled action definitions | `any` | `{}` | no |
276274
| <a name="input_skip_final_snapshot"></a> [skip\_final\_snapshot](#input\_skip\_final\_snapshot) | Determines whether a final snapshot of the cluster is created before Redshift deletes the cluster. If true, a final cluster snapshot is not created. If false , a final cluster snapshot is created before the cluster is deleted | `bool` | `true` | no |
277275
| <a name="input_snapshot_cluster_identifier"></a> [snapshot\_cluster\_identifier](#input\_snapshot\_cluster\_identifier) | The name of the cluster the source snapshot was created from | `string` | `null` | no |
278276
| <a name="input_snapshot_copy"></a> [snapshot\_copy](#input\_snapshot\_copy) | Configuration of automatic copy of snapshots from one region to another | `any` | `{}` | no |
@@ -286,7 +284,7 @@ No modules.
286284
| <a name="input_subnet_group_tags"></a> [subnet\_group\_tags](#input\_subnet\_group\_tags) | Additional tags to add to the subnet group | `map(string)` | `{}` | no |
287285
| <a name="input_subnet_ids"></a> [subnet\_ids](#input\_subnet\_ids) | An array of VPC subnet IDs to use in the subnet group | `list(string)` | `[]` | no |
288286
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no |
289-
| <a name="input_usage_limits"></a> [usage\_limits](#input\_usage\_limits) | Map of usage limit defintions to create | `any` | `{}` | no |
287+
| <a name="input_usage_limits"></a> [usage\_limits](#input\_usage\_limits) | Map of usage limit definitions to create | `any` | `{}` | no |
290288
| <a name="input_use_snapshot_identifier_prefix"></a> [use\_snapshot\_identifier\_prefix](#input\_use\_snapshot\_identifier\_prefix) | Determines whether the identifier (`snapshot_schedule_identifier`) is used as a prefix | `bool` | `true` | no |
291289
| <a name="input_vpc_security_group_ids"></a> [vpc\_security\_group\_ids](#input\_vpc\_security\_group\_ids) | A list of Virtual Private Cloud (VPC) security groups to be associated with the cluster | `list(string)` | `[]` | no |
292290

@@ -312,7 +310,6 @@ No modules.
312310
| <a name="output_cluster_preferred_maintenance_window"></a> [cluster\_preferred\_maintenance\_window](#output\_cluster\_preferred\_maintenance\_window) | The backup window |
313311
| <a name="output_cluster_public_key"></a> [cluster\_public\_key](#output\_cluster\_public\_key) | The public key for the cluster |
314312
| <a name="output_cluster_revision_number"></a> [cluster\_revision\_number](#output\_cluster\_revision\_number) | The specific revision number of the database in the cluster |
315-
| <a name="output_cluster_security_groups"></a> [cluster\_security\_groups](#output\_cluster\_security\_groups) | The security groups associated with the cluster |
316313
| <a name="output_cluster_subnet_group_name"></a> [cluster\_subnet\_group\_name](#output\_cluster\_subnet\_group\_name) | The name of a cluster subnet group to be associated with this cluster |
317314
| <a name="output_cluster_type"></a> [cluster\_type](#output\_cluster\_type) | The Redshift cluster type |
318315
| <a name="output_cluster_version"></a> [cluster\_version](#output\_cluster\_version) | The version of Redshift engine software |

examples/complete/README.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,14 @@ Note that this example may create resources which cost money. Run `terraform des
2424
| Name | Version |
2525
|------|---------|
2626
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
27-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.17 |
28-
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 3.0 |
27+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0 |
2928

3029
## Providers
3130

3231
| Name | Version |
3332
|------|---------|
34-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.17 |
35-
| <a name="provider_aws.us_east_1"></a> [aws.us\_east\_1](#provider\_aws.us\_east\_1) | >= 4.17 |
36-
| <a name="provider_random"></a> [random](#provider\_random) | >= 3.0 |
33+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.0 |
34+
| <a name="provider_aws.us_east_1"></a> [aws.us\_east\_1](#provider\_aws.us\_east\_1) | >= 5.0 |
3735

3836
## Modules
3937

@@ -43,8 +41,8 @@ Note that this example may create resources which cost money. Run `terraform des
4341
| <a name="module_disabled"></a> [disabled](#module\_disabled) | ../../ | n/a |
4442
| <a name="module_redshift"></a> [redshift](#module\_redshift) | ../../ | n/a |
4543
| <a name="module_s3_logs"></a> [s3\_logs](#module\_s3\_logs) | terraform-aws-modules/s3-bucket/aws | ~> 3.0 |
46-
| <a name="module_security_group"></a> [security\_group](#module\_security\_group) | terraform-aws-modules/security-group/aws//modules/redshift | ~> 4.0 |
47-
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.0 |
44+
| <a name="module_security_group"></a> [security\_group](#module\_security\_group) | terraform-aws-modules/security-group/aws//modules/redshift | ~> 5.0 |
45+
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 5.0 |
4846

4947
## Resources
5048

@@ -54,9 +52,8 @@ Note that this example may create resources which cost money. Run `terraform des
5452
| [aws_kms_key.redshift_us_east_1](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key) | resource |
5553
| [aws_redshift_snapshot_copy_grant.useast1](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/redshift_snapshot_copy_grant) | resource |
5654
| [aws_redshift_subnet_group.endpoint](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/redshift_subnet_group) | resource |
57-
| [random_pet.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource |
55+
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |
5856
| [aws_iam_policy_document.s3_redshift](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
59-
| [aws_redshift_service_account.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/redshift_service_account) | data source |
6057

6158
## Inputs
6259

@@ -84,7 +81,6 @@ No inputs.
8481
| <a name="output_cluster_preferred_maintenance_window"></a> [cluster\_preferred\_maintenance\_window](#output\_cluster\_preferred\_maintenance\_window) | The backup window |
8582
| <a name="output_cluster_public_key"></a> [cluster\_public\_key](#output\_cluster\_public\_key) | The public key for the cluster |
8683
| <a name="output_cluster_revision_number"></a> [cluster\_revision\_number](#output\_cluster\_revision\_number) | The specific revision number of the database in the cluster |
87-
| <a name="output_cluster_security_groups"></a> [cluster\_security\_groups](#output\_cluster\_security\_groups) | The security groups associated with the cluster |
8884
| <a name="output_cluster_subnet_group_name"></a> [cluster\_subnet\_group\_name](#output\_cluster\_subnet\_group\_name) | The name of a cluster subnet group to be associated with this cluster |
8985
| <a name="output_cluster_type"></a> [cluster\_type](#output\_cluster\_type) | The Redshift cluster type |
9086
| <a name="output_cluster_version"></a> [cluster\_version](#output\_cluster\_version) | The version of Redshift engine software |

examples/complete/main.tf

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@ provider "aws" {
77
region = "us-east-1"
88
}
99

10+
data "aws_availability_zones" "available" {}
11+
1012
locals {
11-
name = "ex-${replace(basename(path.cwd), "_", "-")}"
13+
name = "ex-${basename(path.cwd)}"
1214
region = "eu-west-1"
1315

16+
vpc_cidr = "10.0.0.0/16"
17+
azs = slice(data.aws_availability_zones.available.names, 0, 3)
18+
1419
s3_prefix = "redshift/${local.name}/"
1520

1621
tags = {
@@ -48,10 +53,8 @@ module "redshift" {
4853
availability_zone_relocation_enabled = true
4954

5055
snapshot_copy = {
51-
useast1 = {
52-
destination_region = "us-east-1"
53-
grant_name = aws_redshift_snapshot_copy_grant.useast1.snapshot_copy_grant_name
54-
}
56+
destination_region = "us-east-1"
57+
grant_name = aws_redshift_snapshot_copy_grant.useast1.snapshot_copy_grant_name
5558
}
5659

5760
logging = {
@@ -228,14 +231,14 @@ module "disabled" {
228231

229232
module "vpc" {
230233
source = "terraform-aws-modules/vpc/aws"
231-
version = "~> 3.0"
234+
version = "~> 5.0"
232235

233236
name = local.name
234-
cidr = "10.99.0.0/18"
237+
cidr = local.vpc_cidr
235238

236-
azs = ["${local.region}a", "${local.region}b", "${local.region}c"]
237-
private_subnets = ["10.99.0.0/24", "10.99.1.0/24", "10.99.2.0/24"]
238-
redshift_subnets = ["10.99.3.0/24", "10.99.4.0/24", "10.99.5.0/24"]
239+
azs = local.azs
240+
private_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k)]
241+
redshift_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 10)]
239242

240243
# Use subnet group created by module
241244
create_redshift_subnet_group = false
@@ -245,7 +248,7 @@ module "vpc" {
245248

246249
module "security_group" {
247250
source = "terraform-aws-modules/security-group/aws//modules/redshift"
248-
version = "~> 4.0"
251+
version = "~> 5.0"
249252

250253
name = local.name
251254
description = "Redshift security group"
@@ -279,17 +282,15 @@ resource "aws_kms_key" "redshift_us_east_1" {
279282
tags = local.tags
280283
}
281284

282-
data "aws_redshift_service_account" "this" {}
283-
284285
data "aws_iam_policy_document" "s3_redshift" {
285286
statement {
286287
sid = "RedshiftAcl"
287288
actions = ["s3:GetBucketAcl"]
288289
resources = [module.s3_logs.s3_bucket_arn]
289290

290291
principals {
291-
type = "AWS"
292-
identifiers = [data.aws_redshift_service_account.this.arn]
292+
type = "Service"
293+
identifiers = ["redshift.amazonaws.com"]
293294
}
294295
}
295296

@@ -304,34 +305,28 @@ data "aws_iam_policy_document" "s3_redshift" {
304305
}
305306

306307
principals {
307-
type = "AWS"
308-
identifiers = [data.aws_redshift_service_account.this.arn]
308+
type = "Service"
309+
identifiers = ["redshift.amazonaws.com"]
309310
}
310311
}
311312
}
312313

313-
resource "random_pet" "this" {
314-
length = 2
315-
}
316-
317314
module "s3_logs" {
318315
source = "terraform-aws-modules/s3-bucket/aws"
319316
version = "~> 3.0"
320317

321-
bucket = "${local.name}-${random_pet.this.id}"
322-
acl = "log-delivery-write"
318+
bucket_prefix = local.name
319+
acl = "log-delivery-write"
320+
321+
control_object_ownership = true
322+
object_ownership = "ObjectWriter"
323323

324324
attach_policy = true
325325
policy = data.aws_iam_policy_document.s3_redshift.json
326326

327327
attach_deny_insecure_transport_policy = true
328328
force_destroy = true
329329

330-
block_public_acls = true
331-
block_public_policy = true
332-
ignore_public_acls = true
333-
restrict_public_buckets = true
334-
335330
tags = local.tags
336331
}
337332

examples/complete/outputs.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@ output "cluster_encrypted" {
6262
value = module.redshift.cluster_encrypted
6363
}
6464

65-
output "cluster_security_groups" {
66-
description = "The security groups associated with the cluster"
67-
value = module.redshift.cluster_security_groups
68-
}
69-
7065
output "cluster_vpc_security_group_ids" {
7166
description = "The VPC security group ids associated with the cluster"
7267
value = module.redshift.cluster_vpc_security_group_ids

examples/complete/versions.tf

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 4.17"
8-
}
9-
random = {
10-
source = "hashicorp/random"
11-
version = ">= 3.0"
7+
version = ">= 5.0"
128
}
139
}
1410
}

main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ resource "aws_redshift_cluster" "this" {
7272
snapshot_cluster_identifier = var.snapshot_cluster_identifier
7373

7474
dynamic "snapshot_copy" {
75-
for_each = can(var.snapshot_copy.destination_region) ? [var.snapshot_copy] : []
75+
for_each = length(var.snapshot_copy) > 0 ? [var.snapshot_copy] : []
7676

7777
content {
7878
destination_region = snapshot_copy.value.destination_region
@@ -189,15 +189,15 @@ resource "aws_redshift_scheduled_action" "this" {
189189

190190
target_action {
191191
dynamic "pause_cluster" {
192-
for_each = can(each.value.pause_cluster) ? [each.value.pause_cluster] : []
192+
for_each = try([each.value.pause_cluster], [])
193193

194194
content {
195195
cluster_identifier = aws_redshift_cluster.this[0].id
196196
}
197197
}
198198

199199
dynamic "resize_cluster" {
200-
for_each = can(each.value.resize_cluster) ? [each.value.resize_cluster] : []
200+
for_each = try([each.value.resize_cluster], [])
201201

202202
content {
203203
classic = try(resize_cluster.value.classic, null)
@@ -209,7 +209,7 @@ resource "aws_redshift_scheduled_action" "this" {
209209
}
210210

211211
dynamic "resume_cluster" {
212-
for_each = can(each.value.resume_cluster) ? [each.value.resume_cluster] : []
212+
for_each = try([each.value.resume_cluster], [])
213213

214214
content {
215215
cluster_identifier = aws_redshift_cluster.this[0].id

0 commit comments

Comments
 (0)