Skip to content

Commit

Permalink
feat!: Remove deprecated EC2 classic fields removed in AWS provider v…
Browse files Browse the repository at this point in the history
…5.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 <bryantbiggs@gmail.com>
  • Loading branch information
matt-dancer-adwanted and bryantbiggs authored Jun 6, 2023
1 parent 6022138 commit 41fc56a
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 103 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.76.0
rev: v1.80.0
hooks:
- id: terraform_fmt
- id: terraform_validate
Expand All @@ -23,7 +23,7 @@ repos:
- '--args=--only=terraform_standard_module_structure'
- '--args=--only=terraform_workspace_remote'
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.0
hooks:
- id: check-merge-conflict
- id: end-of-file-fixer
17 changes: 7 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ module "redshift" {
availability_zone_relocation_enabled = true
snapshot_copy = {
useast1 = {
destination_region = "us-east-1"
grant_name = "example-grant"
}
destination_region = "us-east-1"
grant_name = "example-grant"
}
logging = {
Expand Down Expand Up @@ -181,14 +179,14 @@ module "redshift" {
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.17 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0 |
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 3.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.17 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.0 |
| <a name="provider_random"></a> [random](#provider\_random) | >= 3.0 |

## Modules
Expand Down Expand Up @@ -226,7 +224,7 @@ No modules.
| <a name="input_authentication_profiles"></a> [authentication\_profiles](#input\_authentication\_profiles) | Map of authentication profiles to create | `any` | `{}` | no |
| <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 |
| <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 |
| <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 |
| <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 |
| <a name="input_cluster_identifier"></a> [cluster\_identifier](#input\_cluster\_identifier) | The Cluster Identifier. Must be a lower case string | `string` | `""` | no |
| <a name="input_cluster_timeouts"></a> [cluster\_timeouts](#input\_cluster\_timeouts) | Create, update, and delete timeout configurations for the cluster | `map(string)` | `{}` | no |
| <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 |
Expand Down Expand Up @@ -272,7 +270,7 @@ No modules.
| <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 |
| <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 |
| <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 |
| <a name="input_scheduled_actions"></a> [scheduled\_actions](#input\_scheduled\_actions) | Map of maps containing scheduled action defintions | `any` | `{}` | no |
| <a name="input_scheduled_actions"></a> [scheduled\_actions](#input\_scheduled\_actions) | Map of maps containing scheduled action definitions | `any` | `{}` | no |
| <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 |
| <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 |
| <a name="input_snapshot_copy"></a> [snapshot\_copy](#input\_snapshot\_copy) | Configuration of automatic copy of snapshots from one region to another | `any` | `{}` | no |
Expand All @@ -286,7 +284,7 @@ No modules.
| <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 |
| <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 |
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no |
| <a name="input_usage_limits"></a> [usage\_limits](#input\_usage\_limits) | Map of usage limit defintions to create | `any` | `{}` | no |
| <a name="input_usage_limits"></a> [usage\_limits](#input\_usage\_limits) | Map of usage limit definitions to create | `any` | `{}` | no |
| <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 |
| <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 |

Expand All @@ -312,7 +310,6 @@ No modules.
| <a name="output_cluster_preferred_maintenance_window"></a> [cluster\_preferred\_maintenance\_window](#output\_cluster\_preferred\_maintenance\_window) | The backup window |
| <a name="output_cluster_public_key"></a> [cluster\_public\_key](#output\_cluster\_public\_key) | The public key for the cluster |
| <a name="output_cluster_revision_number"></a> [cluster\_revision\_number](#output\_cluster\_revision\_number) | The specific revision number of the database in the cluster |
| <a name="output_cluster_security_groups"></a> [cluster\_security\_groups](#output\_cluster\_security\_groups) | The security groups associated with the cluster |
| <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 |
| <a name="output_cluster_type"></a> [cluster\_type](#output\_cluster\_type) | The Redshift cluster type |
| <a name="output_cluster_version"></a> [cluster\_version](#output\_cluster\_version) | The version of Redshift engine software |
Expand Down
16 changes: 6 additions & 10 deletions examples/complete/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,14 @@ Note that this example may create resources which cost money. Run `terraform des
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.17 |
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 3.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0 |

## Providers

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

## Modules

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

## Resources

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

## Inputs

Expand Down Expand Up @@ -84,7 +81,6 @@ No inputs.
| <a name="output_cluster_preferred_maintenance_window"></a> [cluster\_preferred\_maintenance\_window](#output\_cluster\_preferred\_maintenance\_window) | The backup window |
| <a name="output_cluster_public_key"></a> [cluster\_public\_key](#output\_cluster\_public\_key) | The public key for the cluster |
| <a name="output_cluster_revision_number"></a> [cluster\_revision\_number](#output\_cluster\_revision\_number) | The specific revision number of the database in the cluster |
| <a name="output_cluster_security_groups"></a> [cluster\_security\_groups](#output\_cluster\_security\_groups) | The security groups associated with the cluster |
| <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 |
| <a name="output_cluster_type"></a> [cluster\_type](#output\_cluster\_type) | The Redshift cluster type |
| <a name="output_cluster_version"></a> [cluster\_version](#output\_cluster\_version) | The version of Redshift engine software |
Expand Down
51 changes: 23 additions & 28 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ provider "aws" {
region = "us-east-1"
}

data "aws_availability_zones" "available" {}

locals {
name = "ex-${replace(basename(path.cwd), "_", "-")}"
name = "ex-${basename(path.cwd)}"
region = "eu-west-1"

vpc_cidr = "10.0.0.0/16"
azs = slice(data.aws_availability_zones.available.names, 0, 3)

s3_prefix = "redshift/${local.name}/"

tags = {
Expand Down Expand Up @@ -48,10 +53,8 @@ module "redshift" {
availability_zone_relocation_enabled = true

snapshot_copy = {
useast1 = {
destination_region = "us-east-1"
grant_name = aws_redshift_snapshot_copy_grant.useast1.snapshot_copy_grant_name
}
destination_region = "us-east-1"
grant_name = aws_redshift_snapshot_copy_grant.useast1.snapshot_copy_grant_name
}

logging = {
Expand Down Expand Up @@ -228,14 +231,14 @@ module "disabled" {

module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 3.0"
version = "~> 5.0"

name = local.name
cidr = "10.99.0.0/18"
cidr = local.vpc_cidr

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

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

module "security_group" {
source = "terraform-aws-modules/security-group/aws//modules/redshift"
version = "~> 4.0"
version = "~> 5.0"

name = local.name
description = "Redshift security group"
Expand Down Expand Up @@ -279,17 +282,15 @@ resource "aws_kms_key" "redshift_us_east_1" {
tags = local.tags
}

data "aws_redshift_service_account" "this" {}

data "aws_iam_policy_document" "s3_redshift" {
statement {
sid = "RedshiftAcl"
actions = ["s3:GetBucketAcl"]
resources = [module.s3_logs.s3_bucket_arn]

principals {
type = "AWS"
identifiers = [data.aws_redshift_service_account.this.arn]
type = "Service"
identifiers = ["redshift.amazonaws.com"]
}
}

Expand All @@ -304,34 +305,28 @@ data "aws_iam_policy_document" "s3_redshift" {
}

principals {
type = "AWS"
identifiers = [data.aws_redshift_service_account.this.arn]
type = "Service"
identifiers = ["redshift.amazonaws.com"]
}
}
}

resource "random_pet" "this" {
length = 2
}

module "s3_logs" {
source = "terraform-aws-modules/s3-bucket/aws"
version = "~> 3.0"

bucket = "${local.name}-${random_pet.this.id}"
acl = "log-delivery-write"
bucket_prefix = local.name
acl = "log-delivery-write"

control_object_ownership = true
object_ownership = "ObjectWriter"

attach_policy = true
policy = data.aws_iam_policy_document.s3_redshift.json

attach_deny_insecure_transport_policy = true
force_destroy = true

block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true

tags = local.tags
}

Expand Down
5 changes: 0 additions & 5 deletions examples/complete/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ output "cluster_encrypted" {
value = module.redshift.cluster_encrypted
}

output "cluster_security_groups" {
description = "The security groups associated with the cluster"
value = module.redshift.cluster_security_groups
}

output "cluster_vpc_security_group_ids" {
description = "The VPC security group ids associated with the cluster"
value = module.redshift.cluster_vpc_security_group_ids
Expand Down
6 changes: 1 addition & 5 deletions examples/complete/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4.17"
}
random = {
source = "hashicorp/random"
version = ">= 3.0"
version = ">= 5.0"
}
}
}
8 changes: 4 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ resource "aws_redshift_cluster" "this" {
snapshot_cluster_identifier = var.snapshot_cluster_identifier

dynamic "snapshot_copy" {
for_each = can(var.snapshot_copy.destination_region) ? [var.snapshot_copy] : []
for_each = length(var.snapshot_copy) > 0 ? [var.snapshot_copy] : []

content {
destination_region = snapshot_copy.value.destination_region
Expand Down Expand Up @@ -189,15 +189,15 @@ resource "aws_redshift_scheduled_action" "this" {

target_action {
dynamic "pause_cluster" {
for_each = can(each.value.pause_cluster) ? [each.value.pause_cluster] : []
for_each = try([each.value.pause_cluster], [])

content {
cluster_identifier = aws_redshift_cluster.this[0].id
}
}

dynamic "resize_cluster" {
for_each = can(each.value.resize_cluster) ? [each.value.resize_cluster] : []
for_each = try([each.value.resize_cluster], [])

content {
classic = try(resize_cluster.value.classic, null)
Expand All @@ -209,7 +209,7 @@ resource "aws_redshift_scheduled_action" "this" {
}

dynamic "resume_cluster" {
for_each = can(each.value.resume_cluster) ? [each.value.resume_cluster] : []
for_each = try([each.value.resume_cluster], [])

content {
cluster_identifier = aws_redshift_cluster.this[0].id
Expand Down
Loading

0 comments on commit 41fc56a

Please sign in to comment.