Skip to content

Commit

Permalink
Fix empty payment when updating subscriptions (#149)
Browse files Browse the repository at this point in the history
* Fix empty payment_method_id in HTTP PUT requests for the /subscriptions/<id> endpoint

* add tests

* Add a flag to include/exclude tests for contract associated accounts

* - Skip only the contract test
- payment_method_id as a computed attribute.

* Reverts the introduction of contract_payment_method_id and sets computed on the original payment_method_id

* Reproduce the issue in tests

* Reproduce the issue in tests

* retrigger checks

Co-authored-by: Hieu Doan <hiieu@users.noreply.github.com>
Co-authored-by: Trent Rosenbaum <trent.rosenbaum@opencredo.com>
  • Loading branch information
3 people committed Nov 10, 2021
1 parent fff4be2 commit 19c23b5
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/provider/resource_rediscloud_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func resourceRedisCloudSubscription() *schema.Resource {
Optional: true,
},
"payment_method_id": {
Computed: true,
Description: "A valid payment method pre-defined in the current account",
Type: schema.TypeString,
ValidateDiagFunc: validateDiagFunc(validation.StringMatch(regexp.MustCompile("^\\d+$"), "must be a number")),
Expand Down
89 changes: 89 additions & 0 deletions internal/provider/resource_rediscloud_subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package provider

import (
"context"
"flag"
"fmt"
"os"
"regexp"
Expand All @@ -14,6 +15,9 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

var contractFlag = flag.Bool("contract", false,
"Add this flag '-contract' to run tests for contract associated accounts")

func TestAccResourceRedisCloudSubscription_createWithDatabase(t *testing.T) {

name := acctest.RandomWithPrefix(testResourcePrefix)
Expand Down Expand Up @@ -320,6 +324,49 @@ func TestAccResourceRedisCloudSubscription_AddManageDatabaseReplication(t *testi
})
}

func TestAccResourceRedisCloudSubscription_createUpdateContractPayment(t *testing.T) {

if !*contractFlag {
t.Skip("The '-contract' parameter wasn't provided in the test command.")
}

name := acctest.RandomWithPrefix(testResourcePrefix)
updatedName := fmt.Sprintf("%v-updatedName", name)
password := acctest.RandString(20)
resourceName := "rediscloud_subscription.example"
testCloudAccountName := os.Getenv("AWS_TEST_CLOUD_ACCOUNT_NAME")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccAwsPreExistingCloudAccountPreCheck(t) },
ProviderFactories: providerFactories,
CheckDestroy: testAccCheckSubscriptionDestroy,
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(testAccResourceRedisCloudSubscriptionContractPayment, testCloudAccountName, name, 1, password),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "cloud_provider.0.provider", "AWS"),
resource.TestCheckResourceAttr(resourceName, "cloud_provider.0.region.0.preferred_availability_zones.#", "1"),
resource.TestCheckResourceAttrSet(resourceName, "cloud_provider.0.region.0.networks.0.networking_subnet_id"),
resource.TestCheckResourceAttr(resourceName, "database.#", "1"),
resource.TestMatchResourceAttr(resourceName, "database.0.db_id", regexp.MustCompile("^[1-9][0-9]*$")),
resource.TestCheckResourceAttrSet(resourceName, "database.0.password"),
resource.TestCheckResourceAttr(resourceName, "database.0.name", "tf-database"),
resource.TestCheckResourceAttr(resourceName, "database.0.memory_limit_in_gb", "1"),
resource.TestCheckResourceAttrSet(resourceName, "payment_method_id"),
),
},
{
Config: fmt.Sprintf(testAccResourceRedisCloudSubscriptionContractPayment, testCloudAccountName, updatedName, 1, password),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "payment_method_id"),
resource.TestCheckResourceAttr(resourceName, "name", updatedName),
),
},
},
})
}

func testAccCheckSubscriptionDestroy(s *terraform.State) error {
client := testProvider.Meta().(*apiClient)

Expand Down Expand Up @@ -676,3 +723,45 @@ resource "rediscloud_subscription" "replica" {
}
`

const testAccResourceRedisCloudSubscriptionContractPayment = `
data "rediscloud_cloud_account" "account" {
exclude_internal_account = true
provider_type = "AWS"
name = "%s"
}
resource "rediscloud_subscription" "example" {
name = "%s"
memory_storage = "ram"
allowlist {
cidrs = ["192.168.0.0/16"]
}
cloud_provider {
provider = data.rediscloud_cloud_account.account.provider_type
cloud_account_id = data.rediscloud_cloud_account.account.id
region {
region = "eu-west-1"
networking_deployment_cidr = "10.0.0.0/24"
preferred_availability_zones = ["eu-west-1a"]
}
}
database {
name = "tf-database"
protocol = "redis"
memory_limit_in_gb = %d
support_oss_cluster_api = true
data_persistence = "none"
replication = false
throughput_measurement_by = "operations-per-second"
password = "%s"
throughput_measurement_value = 10000
source_ips = ["10.0.0.0/8"]
}
}
`

0 comments on commit 19c23b5

Please sign in to comment.