Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent creating empty replicas record #126

Merged
merged 3 commits into from
Nov 23, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ resource "aws_rds_cluster" "primary" {

# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/rds_cluster#replication_source_identifier
resource "aws_rds_cluster" "secondary" {
count = local.enabled && ! local.is_regional_cluster ? 1 : 0
count = local.enabled && !local.is_regional_cluster ? 1 : 0
Copy link

@bridgecrew bridgecrew bot Nov 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MEDIUM   Ensure RDS instances have backup policy
    Resource: aws_rds_cluster.secondary | ID: BC_AWS_GENERAL_46

How to Fix

resource "aws_rds_cluster" "test" {
  ...
+ backup_retention_period = 35
}

Description

This check examines the attribute **backup_retention_period** this should have a value 1-35, and checks if its set to 0 which would disable the backup.

This check is currently under review and maybe suppressed in future releases.

Dependent Resources



Path Resource Connecting Attribute
/main.tf aws_rds_cluster_instance.default depends_on
cluster coalesce(join(, aws_rds_cluster.primary.*.id), join(, aws_rds_cluster.secondary.*.id)) resource_id

Copy link

@bridgecrew bridgecrew bot Nov 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MEDIUM   Ensure Postgres RDS has Query Logging enabled
    Resource: aws_rds_cluster.secondary | ID: BC_AWS_GENERAL_96

Description

TBD Dependent Resources

Path Resource Connecting Attribute
/main.tf aws_rds_cluster_instance.default depends_on
cluster coalesce(join(, aws_rds_cluster.primary.*.id), join(, aws_rds_cluster.secondary.*.id)) resource_id

Copy link

@bridgecrew bridgecrew bot Nov 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOW   Ensure RDS clusters have an AWS Backup backup plan
    Resource: aws_rds_cluster.secondary | ID: BC_AWS_GENERAL_49

How to Fix

resource "aws_rds_cluster" "rds_cluster_good" {
  cluster_identifier      = "aurora-cluster-demo"
  engine                  = "aurora-mysql"
  engine_version          = "5.7.mysql_aurora.2.03.2"
  availability_zones      = ["us-west-2a", "us-west-2b", "us-west-2c"]
  database_name           = "mydb"
  master_username         = "foo"
  master_password         = "bar"
}


resource "aws_backup_plan" "example" {
  name = "tf_example_backup_plan"

  rule {
    rule_name         = "tf_example_backup_rule"
    target_vault_name = "vault-name"
    schedule          = "cron(0 12 * * ? *)"
  }
}

resource "aws_backup_selection" "backup_good" {
  iam_role_arn = "arn:partition:service:region:account-id:resource-id"
  name         = "tf_example_backup_selection"
  plan_id      = aws_backup_plan.example.id

  resources = [
    aws_rds_cluster.rds_cluster_good.arn
  ]
}

Description

TBA

Dependent Resources



Path Resource Connecting Attribute
/main.tf aws_rds_cluster_instance.default depends_on
cluster coalesce(join(, aws_rds_cluster.primary.*.id), join(, aws_rds_cluster.secondary.*.id)) resource_id

cluster_identifier = var.cluster_identifier == "" ? module.this.id : var.cluster_identifier
database_name = var.db_name
master_username = local.ignore_admin_credentials ? null : var.admin_user
Expand Down Expand Up @@ -328,7 +328,7 @@ module "dns_replicas" {
source = "cloudposse/route53-cluster-hostname/aws"
version = "0.12.2"

enabled = local.enabled && length(var.zone_id) > 0 && local.is_serverless
enabled = local.enabled && length(var.zone_id) > 0 && local.is_serverless && local.cluster_instance_count > 0
dns_name = local.reader_dns_name
zone_id = var.zone_id
records = coalescelist(aws_rds_cluster.primary.*.reader_endpoint, aws_rds_cluster.secondary.*.reader_endpoint, [""])
Expand Down