Skip to content

Commit

Permalink
add repo url
Browse files Browse the repository at this point in the history
  • Loading branch information
maciaszczykm committed Apr 17, 2024
1 parent 43b517a commit 123351f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
3 changes: 2 additions & 1 deletion docs/resources/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ A representation of a cluster you can deploy to.
- `cloud` (String) The cloud provider used to create this cluster.
- `cloud_settings` (Attributes) Cloud-specific settings for this cluster. (see [below for nested schema](#nestedatt--cloud_settings))
- `handle` (String) A short, unique human-readable name used to identify this cluster. Does not necessarily map to the cloud resource name.
- `helm_values` (String) Additional helm values you'd like to use in deployment agent helm installs. This is useful for BYOK clusters that need to use custom images or other constructs.
- `helm_repo_url` (String) Helm repository URL you'd like to use in deployment agent Helm install.
- `helm_values` (String) Additional Helm values you'd like to use in deployment agent Helm installs. This is useful for BYOK clusters that need to use custom images or other constructs.
- `kubeconfig` (Attributes) (see [below for nested schema](#nestedatt--kubeconfig))
- `metadata` (String) Arbitrary JSON metadata to store user-specific state of this cluster (e.g. IAM roles for add-ons).
- `node_pools` (Attributes Map) **Experimental, not ready for production use.** Map of node pool specs managed by this cluster, where the key is name of the node pool and value contains the spec. Leave empty for bring your own cluster. (see [below for nested schema](#nestedatt--node_pools))
Expand Down
2 changes: 1 addition & 1 deletion internal/resource/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (r *clusterResource) Create(ctx context.Context, req resource.CreateRequest
return
}

handler, err := NewOperatorHandler(ctx, data.GetKubeconfig(), data.HelmValues.ValueStringPointer(), r.consoleUrl)
handler, err := NewOperatorHandler(ctx, data.GetKubeconfig(), data.HelmRepoUrl.String(), data.HelmValues.ValueStringPointer(), r.consoleUrl)
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to init operator handler, got error: %s", err))
return
Expand Down
1 change: 1 addition & 0 deletions internal/resource/cluster_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type cluster struct {
Bindings *common.ClusterBindings `tfsdk:"bindings"`
NodePools types.Map `tfsdk:"node_pools"`
CloudSettings *ClusterCloudSettings `tfsdk:"cloud_settings"`
HelmRepoUrl types.String `tfsdk:"helm_repo_url"`
HelmValues types.String `tfsdk:"helm_values"`
Kubeconfig *Kubeconfig `tfsdk:"kubeconfig"`
}
Expand Down
10 changes: 8 additions & 2 deletions internal/resource/cluster_operator_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ import (

type OperatorHandler struct {
ctx context.Context

// kubeconfig is a model.Kubeconfig data model read from terraform
kubeconfig *Kubeconfig

// url is an url to the Console API, i.e. https://console.mycluster.onplural.sh
url string

// repoUrl is an URL of the deployment agent chart.
repoUrl string

// additional values used on install
vals map[string]interface{}

Expand Down Expand Up @@ -67,7 +72,7 @@ func (oh *OperatorHandler) init() error {
}

func (oh *OperatorHandler) initRepo() error {
return helm.AddRepo(console.ReleaseName, console.RepoUrl)
return helm.AddRepo(console.ReleaseName, oh.repoUrl)
}

func (oh *OperatorHandler) initChart() error {
Expand Down Expand Up @@ -171,7 +176,7 @@ func (oh *OperatorHandler) Uninstall() error {
return err
}

func NewOperatorHandler(ctx context.Context, kubeconfig *Kubeconfig, values *string, consoleUrl string) (*OperatorHandler, error) {
func NewOperatorHandler(ctx context.Context, kubeconfig *Kubeconfig, repoUrl string, values *string, consoleUrl string) (*OperatorHandler, error) {
vals := map[string]interface{}{}
if values != nil {
if err := yaml.Unmarshal([]byte(*values), &vals); err != nil {
Expand All @@ -182,6 +187,7 @@ func NewOperatorHandler(ctx context.Context, kubeconfig *Kubeconfig, values *str
handler := &OperatorHandler{
ctx: ctx,
kubeconfig: kubeconfig,
repoUrl: repoUrl,
url: consoleUrl,
vals: vals,
}
Expand Down
12 changes: 10 additions & 2 deletions internal/resource/cluster_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resource

import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
"github.com/pluralsh/plural-cli/pkg/console"

"terraform-provider-plural/internal/common"
"terraform-provider-plural/internal/defaults"
Expand Down Expand Up @@ -114,9 +115,16 @@ func (r *clusterResource) schema() schema.Schema {
},
PlanModifiers: []planmodifier.Object{objectplanmodifier.RequiresReplace()},
},
"helm_repo_url": schema.StringAttribute{
Description: "Helm repository URL you'd like to use in deployment agent Helm install.",
MarkdownDescription: "Helm repository URL you'd like to use in deployment agent Helm install.",
Optional: true,
Computed: true,
Default: stringdefault.StaticString(console.RepoUrl),
},
"helm_values": schema.StringAttribute{
Description: "Additional helm values you'd like to use in deployment agent helm installs. This is useful for BYOK clusters that need to use custom images or other constructs.",
MarkdownDescription: "Additional helm values you'd like to use in deployment agent helm installs. This is useful for BYOK clusters that need to use custom images or other constructs.",
Description: "Additional Helm values you'd like to use in deployment agent Helm installs. This is useful for BYOK clusters that need to use custom images or other constructs.",
MarkdownDescription: "Additional Helm values you'd like to use in deployment agent Helm installs. This is useful for BYOK clusters that need to use custom images or other constructs.",
Optional: true,
},
"kubeconfig": r.kubeconfigSchema(false),
Expand Down

0 comments on commit 123351f

Please sign in to comment.