Skip to content

Commit

Permalink
suppress schema diff in CCE version (#666)
Browse files Browse the repository at this point in the history
suppress schema diff in CCE version

Reviewed-by: Anton Kachurin <katchuring@gmail.com>
             https://github.com/outcatcher
  • Loading branch information
anton-sidelnikov authored Oct 28, 2020
1 parent 9b98bcb commit 5302ce0
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
19 changes: 19 additions & 0 deletions opentelekomcloud/diff_suppress_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"net/url"
"reflect"
"regexp"
"sort"
"strings"

Expand Down Expand Up @@ -138,3 +139,21 @@ func suppressLBWhitelistDiffs(k, old, new string, d *schema.ResourceData) bool {

return reflect.DeepEqual(old_array, new_array)
}

func suppressSmartVersionDiff(k, old, new string, d *schema.ResourceData) bool {
compiledVer := regexp.MustCompile(`v(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:-(\w+))?$`)
oldArray := compiledVer.FindStringSubmatch(old)
newArray := compiledVer.FindStringSubmatch(new)
if oldArray == nil {
return false
}
for i := 1; i < len(newArray); i++ {
if oldArray[i] == "" || newArray[i] == "" {
return true
}
if oldArray[i] != newArray[i] {
return false
}
}
return false
}
9 changes: 5 additions & 4 deletions opentelekomcloud/resource_opentelekomcloud_cce_cluster_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ func resourceCCEClusterV3() *schema.Resource {
ForceNew: true,
},
"cluster_version": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
DiffSuppressFunc: suppressSmartVersionDiff,
},
"cluster_type": {
Type: schema.TypeString,
Expand Down
32 changes: 32 additions & 0 deletions opentelekomcloud/resource_opentelekomcloud_cce_cluster_v3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,26 @@ func testAccCheckCCEClusterV3Exists(n string, cluster *clusters.Clusters) resour
}
}

func TestAccCCEClusterV3_withVersionDiff(t *testing.T) {
var cluster clusters.Clusters

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckCCEClusterV3Destroy,
Steps: []resource.TestStep{
{
Config: testAccCCEClusterV3_withInvalidVersion,
Check: resource.ComposeTestCheckFunc(
testAccCheckCCEClusterV3Exists("opentelekomcloud_cce_cluster_v3.cluster_1", &cluster),
resource.TestCheckResourceAttr(
"opentelekomcloud_cce_cluster_v3.cluster_1", "name", "opentelekomcloud-cce"),
),
},
},
})
}

var testAccCCEClusterV3_basic = fmt.Sprintf(`
resource "opentelekomcloud_cce_cluster_v3" "cluster_1" {
name = "opentelekomcloud-cce"
Expand Down Expand Up @@ -166,3 +186,15 @@ resource "opentelekomcloud_cce_cluster_v3" "cluster_1" {
multi_az = true
}
`, OS_VPC_ID, OS_NETWORK_ID)

var testAccCCEClusterV3_withInvalidVersion = fmt.Sprintf(`
resource "opentelekomcloud_cce_cluster_v3" "cluster_1" {
name = "opentelekomcloud-cce"
cluster_type="VirtualMachine"
flavor_id="cce.s1.small"
cluster_version = "v1.9.2"
vpc_id="%s"
subnet_id="%s"
container_network_type="overlay_l2"
description="new description"
}`, OS_VPC_ID, OS_NETWORK_ID)

0 comments on commit 5302ce0

Please sign in to comment.