-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from avisi-cloud/add-datasources
add datasource for node join config
- Loading branch information
Showing
8 changed files
with
179 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package acloud | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
|
||
"github.com/avisi-cloud/go-client/pkg/acloudapi" | ||
) | ||
|
||
func dataSourceNodeJoinConfig() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourceNodeJoinConfigRead, | ||
Description: "Provides access to node join configuration for a node pool. Can be used in combination with other terraform providers to provision new Kubernetes Nodes for Bring Your Own Node clusters in Avisi Cloud Kubernetes.", | ||
Schema: map[string]*schema.Schema{ | ||
"id": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"organisation_slug": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Slug of the Organisation", | ||
}, | ||
"environment_slug": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Slug of the environment of the cluster", | ||
}, | ||
"cluster_slug": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Slug of the cluster", | ||
}, | ||
"node_pool_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "ID of the node pool", | ||
}, | ||
"user_data": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Cloud Init user-data (base64)", | ||
}, | ||
"kubelet_config": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"join_command": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"install_script": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Install bash script for joining a node (base64).", | ||
}, | ||
"upgrade_script": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Install bash script for upgrading a node (base64)", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceNodeJoinConfigRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
client := m.(acloudapi.Client) | ||
|
||
organisationSlug := d.Get("organisation_slug").(string) | ||
environmentSlug := d.Get("environment_slug").(string) | ||
clusterSlug := d.Get("cluster_slug").(string) | ||
|
||
cluster, err := client.GetCluster(ctx, organisationSlug, environmentSlug, clusterSlug) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
if cluster == nil { | ||
return diag.FromErr(fmt.Errorf("cluster was not found")) | ||
} | ||
|
||
nodePoolID := d.Get("node_pool_id").(string) | ||
|
||
nodeJoinConfig, err := client.GetNodePoolJoinConfig(ctx, *cluster, acloudapi.NodePool{ | ||
Identity: nodePoolID, | ||
}) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
if nodeJoinConfig == nil { | ||
return diag.FromErr(fmt.Errorf("node join configuration was not found")) | ||
} | ||
|
||
d.SetId(nodePoolID) | ||
d.Set("user_data", nodeJoinConfig.CloudInitUserDataBase64) | ||
d.Set("kubelet_config", nodeJoinConfig.KubeletConfigBase64) | ||
d.Set("join_command", nodeJoinConfig.JoinCommand) | ||
d.Set("install_script", nodeJoinConfig.InstallScriptBase64) | ||
d.Set("upgrade_script", nodeJoinConfig.UpgradeScriptBase64) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "acloud_nodepool_join_config Data Source - terraform-provider-acloud" | ||
subcategory: "" | ||
description: |- | ||
Provides access to node join configuration for a node pool. Can be used in combination with other terraform providers to provision new Kubernetes Nodes for Bring Your Own Node clusters in Avisi Cloud Kubernetes. | ||
--- | ||
|
||
# acloud_nodepool_join_config (Data Source) | ||
|
||
Provides access to node join configuration for a node pool. Can be used in combination with other terraform providers to provision new Kubernetes Nodes for Bring Your Own Node clusters in Avisi Cloud Kubernetes. | ||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `cluster_slug` (String) Slug of the cluster | ||
- `environment_slug` (String) Slug of the environment of the cluster | ||
- `node_pool_id` (String) ID of the node pool | ||
- `organisation_slug` (String) Slug of the Organisation | ||
|
||
### Read-Only | ||
|
||
- `id` (Number) The ID of this resource. | ||
- `install_script` (String) Install bash script for joining a node (base64). | ||
- `join_command` (String) | ||
- `kubelet_config` (String) | ||
- `upgrade_script` (String) Install bash script for upgrading a node (base64) | ||
- `user_data` (String) Cloud Init user-data (base64) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "acloud_update_channel Data Source - terraform-provider-acloud" | ||
subcategory: "" | ||
description: |- | ||
--- | ||
|
||
# acloud_update_channel (Data Source) | ||
|
||
|
||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `name` (String) Name of the update channel | ||
- `organisation` (String) Slug of the Organisation | ||
|
||
### Read-Only | ||
|
||
- `available` (Boolean) Returns if the update channel is available | ||
- `id` (String) The ID of this resource. | ||
- `version` (String) Avisi Cloud Kubernetes Version associated with the Update Channel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters