Skip to content

Commit 5e6b5e4

Browse files
committed
added support for state and health in data source
1 parent a99eefa commit 5e6b5e4

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

docs/data-sources/cluster.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,7 @@ resource "local_file" "admin_kube_config" {
5050
### Read-Only
5151

5252
- `admin_kube_config` (String) The admin kubeconfig file for accessing the cluster. This is computed automatically.
53+
- `health` (String) The current health status of the cluster. This is computed automatically.
5354
- `id` (String) The ID of this resource.
5455
- `kube_config` (String) The kubeconfig file for accessing the cluster as a non-admin user. This is computed automatically.
56+
- `state` (String) The current state of the cluster. This is computed automatically.

spectrocloud/data_source_cluster.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ func dataSourceCluster() *schema.Resource {
4343
Default: false,
4444
Description: "If set to true, the cluster will treated as a virtual cluster. Defaults to `false`.",
4545
},
46+
"state": {
47+
Type: schema.TypeString,
48+
Computed: true,
49+
Description: "The current state of the cluster. This is computed automatically.",
50+
},
51+
"health": {
52+
Type: schema.TypeString,
53+
Computed: true,
54+
Description: "The current health status of the cluster. This is computed automatically.",
55+
},
4656
},
4757
}
4858
}
@@ -73,6 +83,21 @@ func dataSourceClusterRead(_ context.Context, d *schema.ResourceData, m interfac
7383
if err := d.Set("name", cluster.Metadata.Name); err != nil {
7484
return diag.FromErr(err)
7585
}
86+
87+
// Set cluster state
88+
if cluster.Status != nil && cluster.Status.State != "" {
89+
if err := d.Set("state", cluster.Status.State); err != nil {
90+
return diag.FromErr(err)
91+
}
92+
}
93+
94+
// Set cluster health
95+
clusterSummary, summaryErr := c.GetClusterOverview(cluster.Metadata.UID)
96+
if summaryErr == nil && clusterSummary.Status.Health != nil && clusterSummary.Status.Health.State != "" {
97+
if err := d.Set("health", clusterSummary.Status.Health.State); err != nil {
98+
return diag.FromErr(err)
99+
}
100+
}
76101
}
77102
}
78103
return diags

0 commit comments

Comments
 (0)