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

feat: add default cluster versions to cluster versions data source #4799

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ func DataSourceIBMContainerClusterVersions() *schema.Resource {
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"default_openshift_version": {
Description: "Default openshift-version",
Type: schema.TypeString,
Computed: true,
},
"default_kube_version": {
Description: "Default kube-version",
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand All @@ -74,16 +84,26 @@ func dataSourceIBMContainerClusterVersionsRead(d *schema.ResourceData, meta inte

availableVersions, _ := verAPI.ListV1(targetEnv)
versions := make([]string, len(availableVersions["kubernetes"]))
var defaultKubeVersion string
for i, version := range availableVersions["kubernetes"] {
versions[i] = fmt.Sprintf("%d%s%d%s%d", version.Major, ".", version.Minor, ".", version.Patch)
if version.Default {
defaultKubeVersion = fmt.Sprintf("%d%s%d%s%d", version.Major, ".", version.Minor, ".", version.Patch)
}
}

openshiftVersions := make([]string, len(availableVersions["openshift"]))
var defaultOpenshiftVersion string
for i, version := range availableVersions["openshift"] {
openshiftVersions[i] = fmt.Sprintf("%d%s%d%s%d", version.Major, ".", version.Minor, ".", version.Patch)
if version.Default {
defaultOpenshiftVersion = fmt.Sprintf("%d%s%d%s%d", version.Major, ".", version.Minor, ".", version.Patch)
}
}
d.SetId(time.Now().UTC().String())
d.Set("valid_kube_versions", versions)
d.Set("valid_openshift_versions", openshiftVersions)
d.Set("default_kube_version", defaultKubeVersion)
d.Set("default_openshift_version", defaultOpenshiftVersion)
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ func TestAccIBMContainerClusterVersionsDataSource_basic(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.ibm_container_cluster_versions.versions", "valid_kube_versions.0"),
resource.TestCheckResourceAttrSet("data.ibm_container_cluster_versions.versions", "valid_openshift_versions.0"),
resource.TestCheckResourceAttrSet("data.ibm_container_cluster_versions.versions", "default_kube_version"),
resource.TestCheckResourceAttrSet("data.ibm_container_cluster_versions.versions", "default_openshift_version"),
),
},
},
Expand Down
2 changes: 2 additions & 0 deletions website/docs/d/container_cluster_versions.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ In addition to all argument reference list, you can access the following attribu
- `id` - (String) The unique identifier of the cluster.
- `valid_kube_versions` - (String) The supported Kubernetes version in IBM Cloud Kubernetes Service clusters.
- `valid_openshift_versions` - (String) The supported OpenShift Container Platform version in Red Hat OpenShift on IBM Cloud clusters.
- `default_kube_version` - (String) The default Kubernetes version in IBM Cloud Kubernetes Service clusters.
- `default_openshift_version` - (String) The default OpenShift Container Platform version in Red Hat OpenShift on IBM Cloud clusters.