From 59002baa57ffcebebce7d8ca9bd4efed2c2ddc88 Mon Sep 17 00:00:00 2001 From: Sivaanand Murugesan Date: Tue, 12 Sep 2023 16:44:38 +0530 Subject: [PATCH] PLT-678: Added support for admin kube config --- .../data-sources/spectrocloud_cluster/data-source.tf | 9 ++++++++- go.mod | 2 +- spectrocloud/cluster_common_fields.go | 8 ++++++++ spectrocloud/data_source_cluster.go | 10 ++++++++++ spectrocloud/resource_cluster_aws.go | 5 +++++ 5 files changed, 32 insertions(+), 2 deletions(-) diff --git a/examples/data-sources/spectrocloud_cluster/data-source.tf b/examples/data-sources/spectrocloud_cluster/data-source.tf index 873ad88d..f785e0f0 100644 --- a/examples/data-sources/spectrocloud_cluster/data-source.tf +++ b/examples/data-sources/spectrocloud_cluster/data-source.tf @@ -8,4 +8,11 @@ resource "local_file" "kubeconfig" { filename = "client-101.kubeconfig" file_permission = "0644" directory_permission = "0755" -} \ No newline at end of file +} + +resource "local_file" "adminkubeconfig" { + content = data.spectrocloud_cluster.cluster.admin_kube_config + filename = "admin-client-101.kubeconfig" + file_permission = "0644" + directory_permission = "0755" +} diff --git a/go.mod b/go.mod index 17b2ff01..0b1d8292 100644 --- a/go.mod +++ b/go.mod @@ -120,4 +120,4 @@ require ( ) //replace github.com/spectrocloud/hapi => ../hapi -//replace github.com/spectrocloud/palette-sdk-go => ../palette-sdk-go +replace github.com/spectrocloud/palette-sdk-go => ../palette-sdk-go diff --git a/spectrocloud/cluster_common_fields.go b/spectrocloud/cluster_common_fields.go index 1b49acdc..96f028eb 100644 --- a/spectrocloud/cluster_common_fields.go +++ b/spectrocloud/cluster_common_fields.go @@ -21,6 +21,14 @@ func readCommonFields(c *client.V1Client, d *schema.ResourceData, cluster *model return diag.FromErr(err), true } + adminKubeConfig, err := c.GetClusterAdminKubeConfig(d.Id(), ClusterContext) + if err != nil { + return diag.FromErr(err), true + } + if err := d.Set("admin_kube_config", adminKubeConfig); err != nil { + return diag.FromErr(err), true + } + if err := d.Set("tags", flattenTags(cluster.Metadata.Labels)); err != nil { return diag.FromErr(err), true } diff --git a/spectrocloud/data_source_cluster.go b/spectrocloud/data_source_cluster.go index f400a556..fd42f7c5 100644 --- a/spectrocloud/data_source_cluster.go +++ b/spectrocloud/data_source_cluster.go @@ -20,6 +20,10 @@ func dataSourceCluster() *schema.Resource { Required: true, ForceNew: true, }, + "admin_kube_config": { + Type: schema.TypeString, + Computed: true, + }, "kube_config": { Type: schema.TypeString, Computed: true, @@ -50,6 +54,12 @@ func dataSourceClusterRead(_ context.Context, d *schema.ResourceData, m interfac if err := d.Set("kube_config", kubeConfig); err != nil { return diag.FromErr(err) } + adminKubeConfig, _ := c.GetClusterAdminKubeConfig(cluster.Metadata.UID, ClusterContext) + if adminKubeConfig != "" { + if err := d.Set("admin_kube_config", adminKubeConfig); err != nil { + return diag.FromErr(err) + } + } d.SetId(cluster.Metadata.UID) if err := d.Set("name", cluster.Metadata.Name); err != nil { return diag.FromErr(err) diff --git a/spectrocloud/resource_cluster_aws.go b/spectrocloud/resource_cluster_aws.go index cbec77d6..1536c861 100644 --- a/spectrocloud/resource_cluster_aws.go +++ b/spectrocloud/resource_cluster_aws.go @@ -98,6 +98,11 @@ func resourceClusterAws() *schema.Resource { Computed: true, Description: "Kubeconfig for the cluster. This can be used to connect to the cluster using `kubectl`.", }, + "admin_kube_config": { + Type: schema.TypeString, + Computed: true, + Description: "Admin Kube-config for the cluster. This can be used to connect to the cluster using `kubectl`, With admin privilege.", + }, "cloud_config": { Type: schema.TypeList, ForceNew: true,