Skip to content

Commit

Permalink
Merge branch 'main' into PLT-698
Browse files Browse the repository at this point in the history
  • Loading branch information
nikchern authored Sep 25, 2023
2 parents 0b755cc + eacd334 commit baec177
Show file tree
Hide file tree
Showing 33 changed files with 121 additions and 1 deletion.
8 changes: 8 additions & 0 deletions docs/data-sources/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ resource "local_file" "kubeconfig" {
file_permission = "0644"
directory_permission = "0755"
}
resource "local_file" "adminkubeconfig" {
content = data.spectrocloud_cluster.cluster.admin_kube_config
filename = "admin-client-101.kubeconfig"
file_permission = "0644"
directory_permission = "0755"
}
```

<!-- schema generated by tfplugindocs -->
Expand All @@ -39,6 +46,7 @@ resource "local_file" "kubeconfig" {

### Read-Only

- `admin_kube_config` (String)
- `id` (String) The ID of this resource.
- `kube_config` (String)

Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_aks.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ resource "spectrocloud_cluster_aks" "cluster" {

### Read-Only

- `admin_kube_config` (String) Admin Kube-config for the cluster. This can be used to connect to the cluster using `kubectl`, With admin privilege.
- `cloud_config_id` (String, Deprecated) ID of the cloud config used for the cluster. This cloud config must be of type `azure`.
- `id` (String) The ID of this resource.
- `kubeconfig` (String) Kubeconfig for the cluster. This can be used to connect to the cluster using `kubectl`.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_aws.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ resource "spectrocloud_cluster_aws" "cluster" {

### Read-Only

- `admin_kube_config` (String) Admin Kube-config for the cluster. This can be used to connect to the cluster using `kubectl`, With admin privilege.
- `cloud_config_id` (String, Deprecated) ID of the cloud config used for the cluster. This cloud config must be of type `azure`.
- `id` (String) The ID of this resource.
- `kubeconfig` (String) Kubeconfig for the cluster. This can be used to connect to the cluster using `kubectl`.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_azure.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ resource "spectrocloud_cluster_azure" "cluster" {

### Read-Only

- `admin_kube_config` (String) Admin Kube-config for the cluster. This can be used to connect to the cluster using `kubectl`, With admin privilege.
- `cloud_config_id` (String, Deprecated) ID of the cloud config used for the cluster. This cloud config must be of type `azure`.
- `id` (String) The ID of this resource.
- `kubeconfig` (String) Kubeconfig for the cluster. This can be used to connect to the cluster using `kubectl`.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_coxedge.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ description: |-

### Read-Only

- `admin_kube_config` (String) Admin Kube-config for the cluster. This can be used to connect to the cluster using `kubectl`, With admin privilege.
- `cloud_config_id` (String, Deprecated) ID of the cloud config used for the cluster. This cloud config must be of type `azure`.
- `id` (String) The ID of this resource.
- `kubeconfig` (String) Kubeconfig for the cluster. This can be used to connect to the cluster using `kubectl`.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_edge_native.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ description: |-

### Read-Only

- `admin_kube_config` (String) Admin Kube-config for the cluster. This can be used to connect to the cluster using `kubectl`, With admin privilege.
- `cloud_config_id` (String, Deprecated) ID of the cloud config used for the cluster. This cloud config must be of type `azure`.
- `id` (String) The ID of this resource.
- `kubeconfig` (String) Kubeconfig for the cluster. This can be used to connect to the cluster using `kubectl`.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_edge_vsphere.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ description: |-

### Read-Only

- `admin_kube_config` (String) Admin Kube-config for the cluster. This can be used to connect to the cluster using `kubectl`, With admin privilege.
- `cloud_config_id` (String, Deprecated) ID of the cloud config used for the cluster. This cloud config must be of type `azure`.
- `id` (String) The ID of this resource.
- `kubeconfig` (String) Kubeconfig for the cluster. This can be used to connect to the cluster using `kubectl`.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_eks.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ resource "spectrocloud_cluster_eks" "cluster" {

### Read-Only

- `admin_kube_config` (String) Admin Kube-config for the cluster. This can be used to connect to the cluster using `kubectl`, With admin privilege.
- `cloud_config_id` (String, Deprecated) ID of the cloud config used for the cluster. This cloud config must be of type `azure`.
- `id` (String) The ID of this resource.
- `kubeconfig` (String) Kubeconfig for the cluster. This can be used to connect to the cluster using `kubectl`.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_gcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ resource "spectrocloud_cluster_gcp" "cluster" {

### Read-Only

- `admin_kube_config` (String) Admin Kube-config for the cluster. This can be used to connect to the cluster using `kubectl`, With admin privilege.
- `cloud_config_id` (String, Deprecated) ID of the cloud config used for the cluster. This cloud config must be of type `azure`.
- `id` (String) The ID of this resource.
- `kubeconfig` (String) Kubeconfig for the cluster. This can be used to connect to the cluster using `kubectl`.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_libvirt.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ description: |-

### Read-Only

- `admin_kube_config` (String) Admin Kube-config for the cluster. This can be used to connect to the cluster using `kubectl`, With admin privilege.
- `cloud_config_id` (String, Deprecated) ID of the cloud config used for the cluster. This cloud config must be of type `azure`.
- `id` (String) The ID of this resource.
- `kubeconfig` (String) Kubeconfig for the cluster. This can be used to connect to the cluster using `kubectl`.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_maas.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ resource "spectrocloud_cluster_maas" "cluster" {

### Read-Only

- `admin_kube_config` (String) Admin Kube-config for the cluster. This can be used to connect to the cluster using `kubectl`, With admin privilege.
- `cloud_config_id` (String, Deprecated) ID of the cloud config used for the cluster. This cloud config must be of type `azure`.
- `id` (String) The ID of this resource.
- `kubeconfig` (String) Kubeconfig for the cluster. This can be used to connect to the cluster using `kubectl`.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_openstack.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ resource "spectrocloud_cluster_openstack" "cluster" {

### Read-Only

- `admin_kube_config` (String) Admin Kube-config for the cluster. This can be used to connect to the cluster using `kubectl`, With admin privilege.
- `cloud_config_id` (String, Deprecated) ID of the cloud config used for the cluster. This cloud config must be of type `azure`.
- `id` (String) The ID of this resource.
- `kubeconfig` (String) Kubeconfig for the cluster. This can be used to connect to the cluster using `kubectl`.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_tke.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ description: |-

### Read-Only

- `admin_kube_config` (String) Admin Kube-config for the cluster. This can be used to connect to the cluster using `kubectl`, With admin privilege.
- `cloud_config_id` (String, Deprecated) ID of the cloud config used for the cluster. This cloud config must be of type `azure`.
- `id` (String) The ID of this resource.
- `kubeconfig` (String) Kubeconfig for the cluster. This can be used to connect to the cluster using `kubectl`.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_vsphere.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ description: |-

### Read-Only

- `admin_kube_config` (String) Admin Kube-config for the cluster. This can be used to connect to the cluster using `kubectl`, With admin privilege.
- `cloud_config_id` (String, Deprecated) ID of the cloud config used for the cluster. This cloud config must be of type `azure`.
- `id` (String) The ID of this resource.
- `kubeconfig` (String) Kubeconfig for the cluster. This can be used to connect to the cluster using `kubectl`.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/virtual_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ resource "spectrocloud_virtual_cluster" "cluster" {

### Read-Only

- `admin_kube_config` (String) Admin Kube-config for the cluster. This can be used to connect to the cluster using `kubectl`, With admin privilege.
- `cloud_config_id` (String, Deprecated) ID of the cloud config used for the cluster. This cloud config must be of type `azure`.
- `id` (String) The ID of this resource.
- `kubeconfig` (String) Kubeconfig for the cluster. This can be used to connect to the cluster using `kubectl`.
Expand Down
9 changes: 8 additions & 1 deletion examples/data-sources/spectrocloud_cluster/data-source.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@ resource "local_file" "kubeconfig" {
filename = "client-101.kubeconfig"
file_permission = "0644"
directory_permission = "0755"
}
}

resource "local_file" "adminkubeconfig" {
content = data.spectrocloud_cluster.cluster.admin_kube_config
filename = "admin-client-101.kubeconfig"
file_permission = "0644"
directory_permission = "0755"
}
8 changes: 8 additions & 0 deletions spectrocloud/cluster_common_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 10 additions & 0 deletions spectrocloud/data_source_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions spectrocloud/resource_cluster_aks.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ func resourceClusterAks() *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,
Expand Down
5 changes: 5 additions & 0 deletions spectrocloud/resource_cluster_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions spectrocloud/resource_cluster_azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ func resourceClusterAzure() *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,
Expand Down
5 changes: 5 additions & 0 deletions spectrocloud/resource_cluster_coxedge.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ func resourceClusterCoxEdge() *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,
Expand Down
5 changes: 5 additions & 0 deletions spectrocloud/resource_cluster_edge_native.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ func resourceClusterEdgeNative() *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,
Expand Down
5 changes: 5 additions & 0 deletions spectrocloud/resource_cluster_edge_vsphere.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ func resourceClusterEdgeVsphere() *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,
Expand Down
5 changes: 5 additions & 0 deletions spectrocloud/resource_cluster_eks.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ func resourceClusterEks() *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,
Expand Down
5 changes: 5 additions & 0 deletions spectrocloud/resource_cluster_gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ func resourceClusterGcp() *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,
Expand Down
5 changes: 5 additions & 0 deletions spectrocloud/resource_cluster_libvirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ func resourceClusterLibvirt() *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,
Expand Down
5 changes: 5 additions & 0 deletions spectrocloud/resource_cluster_maas.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ func resourceClusterMaas() *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,
Expand Down
5 changes: 5 additions & 0 deletions spectrocloud/resource_cluster_openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ func resourceClusterOpenStack() *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,
Expand Down
5 changes: 5 additions & 0 deletions spectrocloud/resource_cluster_tke.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ func resourceClusterTke() *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,
Expand Down
5 changes: 5 additions & 0 deletions spectrocloud/resource_cluster_virtual.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ func resourceClusterVirtual() *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,
Expand Down
5 changes: 5 additions & 0 deletions spectrocloud/resource_cluster_vsphere.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ func resourceClusterVsphere() *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,
Expand Down
3 changes: 3 additions & 0 deletions spectrocloud/resource_cluster_vsphere_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@ func TestResourceClusterVsphereRead(t *testing.T) {
GetClusterKubeConfigFn: func(uid string) (string, error) {
return "testKubeConfig", nil
},
GetClusterAdminConfigFn: func(uid string) (string, error) {
return "testAdminKubeConfig", nil
},
GetClusterScanConfigFn: func(uid string) (*models.V1ClusterComplianceScan, error) {
clusterCom := &models.V1ClusterComplianceScan{
Metadata: &models.V1ObjectMeta{
Expand Down

0 comments on commit baec177

Please sign in to comment.