Add cloudstack_kubernetes_cluster_config data source - #312
Open
sudo87 wants to merge 2 commits into
Open
Conversation
CloudStack's CKS clusters expose their kubeconfig only through the getKubernetesClusterConfig API, with no Terraform-native way to feed it into the kubernetes/helm providers. This adds a data source that fetches it and parses out endpoint, cluster_ca_certificate, client_certificate, and client_key as separate attributes named to match those providers' own arguments, alongside the raw config_data for anything else. Context resolution deliberately refuses to guess: if a kubeconfig's current-context names a cluster or user absent from a list of more than one entry, parsing errors instead of silently falling back, since a wrong guess there would silently serve one cluster's endpoint paired with a different cluster's credentials. Closes #276.
Contributor
There was a problem hiding this comment.
Pull request overview
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Adds a new cloudstack_kubernetes_cluster_config data source to fetch a CKS cluster kubeconfig and expose connection fields suitable for wiring up the kubernetes and helm providers.
Changes:
- Introduces
cloudstack_kubernetes_cluster_configdata source implementation, including kubeconfig parsing and base64 decoding of cert/key material. - Registers the new data source in the provider and adds YAML parsing dependency.
- Adds documentation and unit tests for kubeconfig parsing and context/entry resolution behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| website/docs/d/kubernetes_cluster_config.html.markdown | Documents the new data source, examples for provider wiring, and attribute semantics. |
| go.mod | Adds YAML v3 dependency used for kubeconfig parsing. |
| cloudstack/provider.go | Registers cloudstack_kubernetes_cluster_config in DataSourcesMap. |
| cloudstack/data_source_cloudstack_kubernetes_cluster_config.go | Implements the new data source read + kubeconfig parsing/resolution helpers. |
| cloudstack/data_source_cloudstack_kubernetes_cluster_config_test.go | Adds unit tests covering parsing, resolution, and error cases. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+149
to
+162
| if config.Configdata == "" { | ||
| return fmt.Errorf("Kubernetes Cluster %s returned an empty config; the cluster ID may not "+ | ||
| "exist, the cluster may still be starting, or the Kubernetes service plugin may be disabled", clusterID) | ||
| } | ||
|
|
||
| credentials, err := parseKubernetesClusterConfig(config.Configdata) | ||
| if err != nil { | ||
| return fmt.Errorf("Failed to parse the config of Kubernetes Cluster %s: %s", clusterID, err) | ||
| } | ||
|
|
||
| if *credentials == (kubernetesClusterCredentials{}) { | ||
| return fmt.Errorf("The config of Kubernetes Cluster %s does not contain a cluster endpoint, "+ | ||
| "CA certificate, client certificate or client key; use config_data directly instead", clusterID) | ||
| } |
sureshanaparti
approved these changes
Aug 14, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cloudstack_kubernetes_cluster_config, a data source that reads a CKS cluster's kubeconfigand exposes
endpoint,cluster_ca_certificate,client_certificate,client_key, and rawconfig_data, so thekubernetes/helmproviders can be wired to a CKS cluster directly.multi-entry list, to avoid silently serving mismatched credentials.
config_dataandclient_keyare markedSensitive.Test plan
TestParseKubernetesClusterConfig— 12 unit cases covering context resolution, missingsections, and malformed input
make build,make test,make vet,gofmt -lcleanTestProvider/TestProvider_implconfirm registration and schema validity