Skip to content

Commit

Permalink
Manually specify global settings agentVsn in terraform provider
Browse files Browse the repository at this point in the history
This should allow the console api to specify the exact agent version as needed so installs remain properly backwards compatible.
  • Loading branch information
michaeljguarino committed May 1, 2024
1 parent 17f9d79 commit bb83de6
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 26 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/mitchellh/go-homedir v1.1.0
github.com/pluralsh/console-client-go v0.4.0
github.com/pluralsh/console-client-go v0.5.3
github.com/pluralsh/plural-cli v0.8.5-0.20240216094552-efc34ee6de37
github.com/pluralsh/polly v0.1.7
github.com/samber/lo v1.38.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,8 @@ github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZ
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
github.com/pluralsh/console-client-go v0.4.0 h1:lgKaVGi8jB7S8wFF6L3P6H/4Xc88e4FozhyW58O1w3Q=
github.com/pluralsh/console-client-go v0.4.0/go.mod h1:eyCiLA44YbXiYyJh8303jk5JdPkt9McgCo5kBjk4lKo=
github.com/pluralsh/console-client-go v0.5.3 h1:RB4XtKlvh8+BM5o1o0h+W6zHculBGbL6q5lI/yRnqJE=
github.com/pluralsh/console-client-go v0.5.3/go.mod h1:eyCiLA44YbXiYyJh8303jk5JdPkt9McgCo5kBjk4lKo=
github.com/pluralsh/gqlclient v1.11.0 h1:FfXW7FiEJLHOfTAa7NxDb8jb3aMZNIpCAcG+bg8uHYA=
github.com/pluralsh/gqlclient v1.11.0/go.mod h1:qSXKUlio1F2DRPy8el4oFYsmpKbkUYspgPB87T4it5I=
github.com/pluralsh/plural-cli v0.8.5-0.20240216094552-efc34ee6de37 h1:DBnaKvKmbTbKwbkrh/2gJBwyHYfaXdxeT3UGh+94K4g=
Expand Down
2 changes: 2 additions & 0 deletions internal/resource/cluster_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ func (c *cluster) UpdateAttributes(ctx context.Context, d diag.Diagnostics) cons
Handle: c.Handle.ValueStringPointer(),
Protect: c.Protect.ValueBoolPointer(),
NodePools: c.NodePoolsAttribute(ctx, d),
Metadata: c.Metadata.ValueStringPointer(),
Tags: c.TagsAttribute(ctx, d),
}
}

Expand Down
28 changes: 22 additions & 6 deletions internal/resource/cluster_operator_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package resource
import (
"context"
"fmt"
"strings"
"time"

"terraform-provider-plural/internal/client"

gqlclient "github.com/pluralsh/console-client-go"
"github.com/pluralsh/plural-cli/pkg/console"
"github.com/pluralsh/plural-cli/pkg/helm"
"github.com/pluralsh/polly/algorithms"
Expand All @@ -33,6 +35,8 @@ type OperatorHandler struct {
// kubeconfig is a model.Kubeconfig data model read from terraform
kubeconfig *Kubeconfig

settings *gqlclient.DeploymentSettingsFragment

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

Expand Down Expand Up @@ -68,6 +72,8 @@ func (oh *OperatorHandler) init() error {
return err
}

oh.initSettings()

err = oh.initRepo()
if err != nil {
return err
Expand All @@ -85,12 +91,26 @@ func (oh *OperatorHandler) init() error {
return nil
}

func (oh *OperatorHandler) initSettings() {
settings, err := oh.client.GetDeploymentSettings(oh.ctx)
if err != nil {
return
}
oh.settings = settings.DeploymentSettings
}

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

func (oh *OperatorHandler) initChart() error {
vsn := ""
if oh.settings != nil {
vsn = oh.settings.AgentVsn
}

client := action.NewInstall(oh.configuration)
client.ChartPathOptions.Version = strings.TrimPrefix(vsn, "v")
locateName := fmt.Sprintf("%s/%s", console.ReleaseName, console.ChartName)
path, err := client.ChartPathOptions.LocateChart(locateName, cli.New())
if err != nil {
Expand Down Expand Up @@ -161,12 +181,8 @@ func (oh *OperatorHandler) values(token string) (map[string]any, error) {
"consoleUrl": fmt.Sprintf("%s/ext/gql", oh.url),
}

setting, err := oh.client.GetDeploymentSettings(oh.ctx)
if err != nil {
return nil, err
}
if setting != nil && setting.DeploymentSettings != nil && setting.DeploymentSettings.AgentHelmValues != nil {
if err := yaml.Unmarshal([]byte(*setting.DeploymentSettings.AgentHelmValues), &globalVals); err != nil {
if oh.settings != nil && oh.settings.AgentHelmValues != nil {
if err := yaml.Unmarshal([]byte(*oh.settings.AgentHelmValues), &globalVals); err != nil {
return nil, err
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/resource/infrastructure_stack_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (isjs *InfrastructureStackJobSpec) ContainersAttributes(ctx context.Context
return result
}

func (isjs *InfrastructureStackJobSpec) From(spec *gqlclient.JobGateSpecFragment, ctx context.Context, d diag.Diagnostics) {
func (isjs *InfrastructureStackJobSpec) From(spec *gqlclient.JobSpecFragment, ctx context.Context, d diag.Diagnostics) {
if isjs == nil {
return
}
Expand Down
36 changes: 18 additions & 18 deletions internal/resource/service_deployment_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,24 +97,24 @@ func (r *ServiceDeploymentResource) schemaKustomize() schema.SingleNestedAttribu
}
}

func (r *ServiceDeploymentResource) schemaConfiguration() schema.SetNestedAttribute {
return schema.SetNestedAttribute{
Optional: true,
Description: "List of [name, value] secrets used to alter this ServiceDeployment configuration.",
MarkdownDescription: "List of [name, value] secrets used to alter this ServiceDeployment configuration.",
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"name": schema.StringAttribute{
Required: true,
},
"value": schema.StringAttribute{
Required: true,
Sensitive: true,
},
},
},
}
}
// func (r *ServiceDeploymentResource) schemaConfiguration() schema.SetNestedAttribute {
// return schema.SetNestedAttribute{
// Optional: true,
// Description: "List of [name, value] secrets used to alter this ServiceDeployment configuration.",
// MarkdownDescription: "List of [name, value] secrets used to alter this ServiceDeployment configuration.",
// NestedObject: schema.NestedAttributeObject{
// Attributes: map[string]schema.Attribute{
// "name": schema.StringAttribute{
// Required: true,
// },
// "value": schema.StringAttribute{
// Required: true,
// Sensitive: true,
// },
// },
// },
// }
// }

func (r *ServiceDeploymentResource) schemaCluster() schema.SingleNestedAttribute {
return schema.SingleNestedAttribute{
Expand Down

0 comments on commit bb83de6

Please sign in to comment.