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

suppress schema diff in CCE version #666

Merged
merged 10 commits into from
Oct 28, 2020
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] {
outcatcher marked this conversation as resolved.
Show resolved Hide resolved
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)