Skip to content

Commit e2a015b

Browse files
committed
feat: routing through bool for cmk and writing tests
1 parent ba89624 commit e2a015b

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed

provider/resource_rediscloud_pro_subscription.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
2222
)
2323

24+
const CMEK_ENABLED_STRING = "cloud-provider-managed-key"
25+
2426
func containsModule(modules []interface{}, requiredModule string) bool {
2527
for _, m := range modules {
2628
if mod, ok := m.(string); ok && mod == requiredModule {
@@ -539,6 +541,12 @@ func resourceRedisCloudProSubscriptionCreate(ctx context.Context, d *schema.Reso
539541
createSubscriptionRequest.RedisVersion = redis.String(redisVersion)
540542
}
541543

544+
cmekEnabled := d.Get("cmek_enabled").(bool)
545+
546+
if cmekEnabled == true {
547+
createSubscriptionRequest.PersistentStorageEncryptionType = redis.String(CMEK_ENABLED_STRING)
548+
}
549+
542550
subId, err := api.client.Subscription.Create(ctx, createSubscriptionRequest)
543551
if err != nil {
544552
return append(diags, diag.FromErr(err)...)

provider/resource_rediscloud_pro_subscription_test.go

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,30 @@ func testAccCheckProSubscriptionDestroy(s *terraform.State) error {
722722
return nil
723723
}
724724

725+
func TestAccResourceRedisCloudProSubscription_CMEK(t *testing.T) {
726+
727+
//testAccRequiresEnvVar(t, "EXECUTE_TESTS")
728+
729+
name := acctest.RandomWithPrefix(testResourcePrefix)
730+
const resourceName = "rediscloud_subscription.example"
731+
testCloudAccountName := os.Getenv("AWS_TEST_CLOUD_ACCOUNT_NAME")
732+
733+
resource.ParallelTest(t, resource.TestCase{
734+
PreCheck: func() { testAccPreCheck(t); testAccAwsPreExistingCloudAccountPreCheck(t) },
735+
ProviderFactories: providerFactories,
736+
CheckDestroy: testAccCheckProSubscriptionDestroy,
737+
Steps: []resource.TestStep{
738+
{
739+
Config: fmt.Sprintf(testAccResourceRedisCloudProSubscriptionCmekEnabled_part1, testCloudAccountName, name),
740+
Check: resource.ComposeAggregateTestCheckFunc(
741+
resource.TestCheckResourceAttr(resourceName, "name", name),
742+
resource.TestCheckResourceAttr(resourceName, "cloud_provider.0.region.0.preferred_availability_zones.#", "1"),
743+
),
744+
},
745+
},
746+
})
747+
}
748+
725749
// TF config for provisioning a new subscription.
726750
const testAccResourceRedisCloudProSubscription = `
727751
data "rediscloud_payment_method" "card" {
@@ -770,6 +794,78 @@ resource "rediscloud_subscription" "example" {
770794
}
771795
`
772796

797+
const testAccResourceRedisCloudProSubscriptionCmekEnabled_part1 = `
798+
data "rediscloud_payment_method" "card" {
799+
card_type = "Visa"
800+
}
801+
802+
data "rediscloud_cloud_account" "account" {
803+
exclude_internal_account = true
804+
provider_type = "AWS"
805+
name = "%s"
806+
}
807+
808+
resource "rediscloud_subscription" "example" {
809+
810+
name = "%s"
811+
payment_method = "credit-card"
812+
payment_method_id = data.rediscloud_payment_method.card.id
813+
memory_storage = "ram"
814+
cmek_enabled = true
815+
816+
allowlist {
817+
cidrs = ["192.168.0.0/16"]
818+
security_group_ids = []
819+
}
820+
821+
cloud_provider {
822+
provider = data.rediscloud_cloud_account.account.provider_type
823+
cloud_account_id = data.rediscloud_cloud_account.account.id
824+
region {
825+
region = "eu-west-1"
826+
networking_deployment_cidr = "10.0.0.0/24"
827+
preferred_availability_zones = ["eu-west-1a"]
828+
}
829+
}
830+
}
831+
`
832+
833+
const testAccResourceRedisCloudProSubscriptionCmekEnabled_update = `
834+
data "rediscloud_payment_method" "card" {
835+
card_type = "Visa"
836+
}
837+
838+
data "rediscloud_cloud_account" "account" {
839+
exclude_internal_account = true
840+
provider_type = "AWS"
841+
name = "%s"
842+
}
843+
844+
resource "rediscloud_subscription" "example" {
845+
846+
name = "%s"
847+
payment_method = "credit-card"
848+
payment_method_id = data.rediscloud_payment_method.card.id
849+
memory_storage = "ram"
850+
cmek_enabled = true
851+
852+
allowlist {
853+
cidrs = ["192.168.0.0/16"]
854+
security_group_ids = []
855+
}
856+
857+
cloud_provider {
858+
provider = data.rediscloud_cloud_account.account.provider_type
859+
cloud_account_id = data.rediscloud_cloud_account.account.id
860+
region {
861+
region = "eu-west-1"
862+
networking_deployment_cidr = "10.0.0.0/24"
863+
preferred_availability_zones = ["eu-west-1a"]
864+
}
865+
}
866+
}
867+
`
868+
773869
const testAccResourceRedisCloudProSubscriptionWithRedisVersion = `
774870
data "rediscloud_payment_method" "card" {
775871
card_type = "Visa"

0 commit comments

Comments
 (0)