Skip to content

Commit d702a9d

Browse files
Merge pull request #33 from pluralsh/mjg/eng-2030-use-agentvsn-from-the-deploymentsettings-query-in-api-to
Manually specify global settings agentVsn in terraform provider
2 parents 17f9d79 + bb83de6 commit d702a9d

File tree

6 files changed

+46
-26
lines changed

6 files changed

+46
-26
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0
1313
github.com/hashicorp/terraform-plugin-log v0.9.0
1414
github.com/mitchellh/go-homedir v1.1.0
15-
github.com/pluralsh/console-client-go v0.4.0
15+
github.com/pluralsh/console-client-go v0.5.3
1616
github.com/pluralsh/plural-cli v0.8.5-0.20240216094552-efc34ee6de37
1717
github.com/pluralsh/polly v0.1.7
1818
github.com/samber/lo v1.38.1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,8 @@ github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZ
858858
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
859859
github.com/pluralsh/console-client-go v0.4.0 h1:lgKaVGi8jB7S8wFF6L3P6H/4Xc88e4FozhyW58O1w3Q=
860860
github.com/pluralsh/console-client-go v0.4.0/go.mod h1:eyCiLA44YbXiYyJh8303jk5JdPkt9McgCo5kBjk4lKo=
861+
github.com/pluralsh/console-client-go v0.5.3 h1:RB4XtKlvh8+BM5o1o0h+W6zHculBGbL6q5lI/yRnqJE=
862+
github.com/pluralsh/console-client-go v0.5.3/go.mod h1:eyCiLA44YbXiYyJh8303jk5JdPkt9McgCo5kBjk4lKo=
861863
github.com/pluralsh/gqlclient v1.11.0 h1:FfXW7FiEJLHOfTAa7NxDb8jb3aMZNIpCAcG+bg8uHYA=
862864
github.com/pluralsh/gqlclient v1.11.0/go.mod h1:qSXKUlio1F2DRPy8el4oFYsmpKbkUYspgPB87T4it5I=
863865
github.com/pluralsh/plural-cli v0.8.5-0.20240216094552-efc34ee6de37 h1:DBnaKvKmbTbKwbkrh/2gJBwyHYfaXdxeT3UGh+94K4g=

internal/resource/cluster_model.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ func (c *cluster) UpdateAttributes(ctx context.Context, d diag.Diagnostics) cons
9090
Handle: c.Handle.ValueStringPointer(),
9191
Protect: c.Protect.ValueBoolPointer(),
9292
NodePools: c.NodePoolsAttribute(ctx, d),
93+
Metadata: c.Metadata.ValueStringPointer(),
94+
Tags: c.TagsAttribute(ctx, d),
9395
}
9496
}
9597

internal/resource/cluster_operator_handler.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ package resource
33
import (
44
"context"
55
"fmt"
6+
"strings"
67
"time"
78

89
"terraform-provider-plural/internal/client"
910

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

38+
settings *gqlclient.DeploymentSettingsFragment
39+
3640
// url is an url to the Console API, i.e. https://console.mycluster.onplural.sh
3741
url string
3842

@@ -68,6 +72,8 @@ func (oh *OperatorHandler) init() error {
6872
return err
6973
}
7074

75+
oh.initSettings()
76+
7177
err = oh.initRepo()
7278
if err != nil {
7379
return err
@@ -85,12 +91,26 @@ func (oh *OperatorHandler) init() error {
8591
return nil
8692
}
8793

94+
func (oh *OperatorHandler) initSettings() {
95+
settings, err := oh.client.GetDeploymentSettings(oh.ctx)
96+
if err != nil {
97+
return
98+
}
99+
oh.settings = settings.DeploymentSettings
100+
}
101+
88102
func (oh *OperatorHandler) initRepo() error {
89103
return helm.AddRepo(console.ReleaseName, oh.repoUrl)
90104
}
91105

92106
func (oh *OperatorHandler) initChart() error {
107+
vsn := ""
108+
if oh.settings != nil {
109+
vsn = oh.settings.AgentVsn
110+
}
111+
93112
client := action.NewInstall(oh.configuration)
113+
client.ChartPathOptions.Version = strings.TrimPrefix(vsn, "v")
94114
locateName := fmt.Sprintf("%s/%s", console.ReleaseName, console.ChartName)
95115
path, err := client.ChartPathOptions.LocateChart(locateName, cli.New())
96116
if err != nil {
@@ -161,12 +181,8 @@ func (oh *OperatorHandler) values(token string) (map[string]any, error) {
161181
"consoleUrl": fmt.Sprintf("%s/ext/gql", oh.url),
162182
}
163183

164-
setting, err := oh.client.GetDeploymentSettings(oh.ctx)
165-
if err != nil {
166-
return nil, err
167-
}
168-
if setting != nil && setting.DeploymentSettings != nil && setting.DeploymentSettings.AgentHelmValues != nil {
169-
if err := yaml.Unmarshal([]byte(*setting.DeploymentSettings.AgentHelmValues), &globalVals); err != nil {
184+
if oh.settings != nil && oh.settings.AgentHelmValues != nil {
185+
if err := yaml.Unmarshal([]byte(*oh.settings.AgentHelmValues), &globalVals); err != nil {
170186
return nil, err
171187
}
172188
}

internal/resource/infrastructure_stack_model.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ func (isjs *InfrastructureStackJobSpec) ContainersAttributes(ctx context.Context
276276
return result
277277
}
278278

279-
func (isjs *InfrastructureStackJobSpec) From(spec *gqlclient.JobGateSpecFragment, ctx context.Context, d diag.Diagnostics) {
279+
func (isjs *InfrastructureStackJobSpec) From(spec *gqlclient.JobSpecFragment, ctx context.Context, d diag.Diagnostics) {
280280
if isjs == nil {
281281
return
282282
}

internal/resource/service_deployment_schema.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -97,24 +97,24 @@ func (r *ServiceDeploymentResource) schemaKustomize() schema.SingleNestedAttribu
9797
}
9898
}
9999

100-
func (r *ServiceDeploymentResource) schemaConfiguration() schema.SetNestedAttribute {
101-
return schema.SetNestedAttribute{
102-
Optional: true,
103-
Description: "List of [name, value] secrets used to alter this ServiceDeployment configuration.",
104-
MarkdownDescription: "List of [name, value] secrets used to alter this ServiceDeployment configuration.",
105-
NestedObject: schema.NestedAttributeObject{
106-
Attributes: map[string]schema.Attribute{
107-
"name": schema.StringAttribute{
108-
Required: true,
109-
},
110-
"value": schema.StringAttribute{
111-
Required: true,
112-
Sensitive: true,
113-
},
114-
},
115-
},
116-
}
117-
}
100+
// func (r *ServiceDeploymentResource) schemaConfiguration() schema.SetNestedAttribute {
101+
// return schema.SetNestedAttribute{
102+
// Optional: true,
103+
// Description: "List of [name, value] secrets used to alter this ServiceDeployment configuration.",
104+
// MarkdownDescription: "List of [name, value] secrets used to alter this ServiceDeployment configuration.",
105+
// NestedObject: schema.NestedAttributeObject{
106+
// Attributes: map[string]schema.Attribute{
107+
// "name": schema.StringAttribute{
108+
// Required: true,
109+
// },
110+
// "value": schema.StringAttribute{
111+
// Required: true,
112+
// Sensitive: true,
113+
// },
114+
// },
115+
// },
116+
// }
117+
// }
118118

119119
func (r *ServiceDeploymentResource) schemaCluster() schema.SingleNestedAttribute {
120120
return schema.SingleNestedAttribute{

0 commit comments

Comments
 (0)