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
12 changes: 12 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 @@ -139,3 +140,14 @@ func suppressLBWhitelistDiffs(k, old, new string, d *schema.ResourceData) bool {

return reflect.DeepEqual(old_array, new_array)
}

func suppressCceMinorVersionDiff(k, old, new string, d *schema.ResourceData) bool {
compiled_ver := regexp.MustCompile(`v(\d+\.)?(\d+\.)?(\*|\d+)`)
compiled_patch := regexp.MustCompile(`(-\w+)`)

if strings.ToLower(compiled_ver.FindString(old)) == strings.ToLower(compiled_ver.FindString(new)) &&
strings.ToLower(compiled_patch.FindString(old)) == strings.ToLower(compiled_patch.FindString(new)) {
return true
}
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: suppressCceMinorVersionDiff,
},
"cluster_type": {
Type: schema.TypeString,
Expand Down
39 changes: 39 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,33 @@ func testAccCheckCCEClusterV3Exists(n string, cluster *clusters.Clusters) resour
}
}

func TestAccCCEClusterV3_update_with_version_diff(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_basic,
Check: resource.ComposeTestCheckFunc(
testAccCheckCCEClusterV3Exists("opentelekomcloud_cce_cluster_v3.cluster_1", &cluster),
resource.TestCheckResourceAttr(
"opentelekomcloud_cce_cluster_v3.cluster_1", "name", "opentelekomcloud-cce"),
),
},
{
Config: testAccCCEClusterV3_update_with_invalid_version,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"opentelekomcloud_cce_cluster_v3.cluster_1", "description", "new description"),
),
},
},
})
}

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

var testAccCCEClusterV3_update_with_invalid_version = 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)