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

feat: defaults when node_count is 1 #859

Merged
merged 1 commit into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all 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 aws-redis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ provision:
prohibit_update: true
- field_name: multi_az_enabled
type: boolean
details: Whether to enable Multi-AZ Support for the replication group. If true, `node_count` must be greater than 1.
details: Whether to enable Multi-AZ Support for the replication group. Only applies when `node_count` is greater than 1.
default: true
- field_name: kms_key_id
type: string
Expand All @@ -118,7 +118,7 @@ provision:
prohibit_update: true
- field_name: automatic_failover_enabled
type: boolean
details: Automatically promote replica to primary if the existing primary fails. If enabled, node_count must be greater than 1.
details: Automatically promote replica to primary if the existing primary fails. Only applies when `node_count` is greater than 1.
default: true
- <<: &nullable_string
type: string
Expand Down
30 changes: 15 additions & 15 deletions terraform-tests/redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
tfjson "github.com/hashicorp/terraform-json"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
. "github.com/onsi/gomega/gstruct"
)

Expand Down Expand Up @@ -244,20 +243,6 @@ var _ = Describe("Redis", Label("redis-terraform"), Ordered, func() {
})
})

Context("multi_az_enabled", func() {
When("invalid combination", func() {
It("should not be passed", func() {
vars := buildVars(defaultVars, map[string]any{"node_count": 1, "multi_az_enabled": true, "automatic_failover_enabled": false})
session, err := FailPlan(terraformProvisionDir, vars)

Expect(session.ExitCode()).NotTo(Equal(0), "Terraform plan should return and error upon exit")
Expect(session.Err).To(gbytes.Say("automatic_failover_enabled must be true if multi_az_enabled is true"))

Expect(err).NotTo(HaveOccurred())
})
})
})

Context("preferred_azs are passed", func() {
BeforeAll(func() {
plan = ShowPlan(terraformProvisionDir, buildVars(defaultVars, map[string]any{
Expand Down Expand Up @@ -400,6 +385,21 @@ var _ = Describe("Redis", Label("redis-terraform"), Ordered, func() {
})
})
})

Context("node_count is 1", func() {
BeforeAll(func() {
plan = ShowPlan(terraformProvisionDir, buildVars(defaultVars, map[string]any{
"node_count": 1,
}))
})

It("sets `automatic_failover_enabled` and `multi_az_enabled` to false", func() {
Expect(AfterValuesForType(plan, resource)).To(MatchKeys(IgnoreExtras, Keys{
"automatic_failover_enabled": BeFalse(),
"multi_az_enabled": BeFalse(),
}))
})
})
})

func getExpectedResources() []string {
Expand Down
4 changes: 2 additions & 2 deletions terraform/redis/cluster/provision/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ resource "random_password" "auth_token" {
}

resource "aws_elasticache_replication_group" "redis" {
automatic_failover_enabled = var.automatic_failover_enabled
multi_az_enabled = var.multi_az_enabled
automatic_failover_enabled = var.node_count == 1 ? false : var.automatic_failover_enabled
multi_az_enabled = var.node_count == 1 ? false : var.multi_az_enabled
replication_group_id = var.instance_name
description = format("%s redis", var.instance_name)
node_type = local.node_type
Expand Down