Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrade to newest client #180

Merged
merged 4 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/Masterminds/semver v1.5.0
github.com/Unleash/unleash-server-api-go v0.2.9
github.com/Unleash/unleash-server-api-go v0.3.0
github.com/fatih/structs v1.1.0
github.com/hashicorp/terraform-plugin-docs v0.18.0
github.com/hashicorp/terraform-plugin-framework v1.4.2
Expand Down Expand Up @@ -81,6 +81,7 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect
google.golang.org/grpc v1.57.1 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/validator.v2 v2.0.1 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c h1:kMFnB0vCcX
github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0=
github.com/Unleash/unleash-server-api-go v0.2.9 h1:IfMQZBhhZy9voRoZo6w5vOqY16rsNMoQIkG+DwfZyMk=
github.com/Unleash/unleash-server-api-go v0.2.9/go.mod h1:w0ZJ50HuUBS50Wn8I8TYW8RPcR5vqSbRCa9DcRgVNvw=
github.com/Unleash/unleash-server-api-go v0.3.0 h1:0XyTE7D339LQBJEHndct/b55QWsPZtIV59TXhbjJklI=
github.com/Unleash/unleash-server-api-go v0.3.0/go.mod h1:/IvCtBfBrOVOa67elCLig45kt6NYkk79oxmRW80WOFY=
github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE=
github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec=
Expand Down Expand Up @@ -266,6 +268,8 @@ google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/validator.v2 v2.0.1 h1:xF0KWyGWXm/LM2G1TrEjqOu4pa6coO9AlWSf3msVfDY=
gopkg.in/validator.v2 v2.0.1/go.mod h1:lIUZBlB3Im4s/eYp39Ry/wkR02yOPhZ9IwIRBjuPuG8=
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/project_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (r *projectResource) Create(ctx context.Context, req resource.CreateRequest

createProjectRequest := *unleash.NewCreateProjectSchemaWithDefaults()
createProjectRequest.Name = *plan.Name.ValueStringPointer()
createProjectRequest.Id = *plan.Id.ValueStringPointer()
createProjectRequest.Id = plan.Id.ValueStringPointer()
if !plan.Description.IsNull() {
createProjectRequest.Description = *unleash.NewNullableString(plan.Description.ValueStringPointer())
}
Expand Down
18 changes: 0 additions & 18 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,6 @@ func checkIsSupportedVersion(version string, diags *diag.Diagnostics) {
}
}

func versionCheck(ctx context.Context, client *unleash.APIClient, diags *diag.Diagnostics) {
unleashConfig, api_response, err := client.AdminUIAPI.GetUiConfig(ctx).Execute()

if !ValidateApiResponse(api_response, 200, diags, err) {
return
}

if !unleashConfig.VersionInfo.IsLatest {
diags.AddWarning("You're not using the latest Unleash version, consider upgrading",
fmt.Sprintf("You're using version %s, the latest unleash-server is %s, while the latest enterprise version is: %s", unleashConfig.Version, *unleashConfig.VersionInfo.Latest.Oss, *unleashConfig.VersionInfo.Latest.Enterprise))
}

checkIsSupportedVersion(unleashConfig.Version, diags)
tflog.Info(ctx, fmt.Sprintf("Found a supported Unleash version: %s", unleashConfig.Version))
}

func (p *UnleashProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) {
var config UnleashConfiguration

Expand All @@ -168,8 +152,6 @@ func (p *UnleashProvider) Configure(ctx context.Context, req provider.ConfigureR
return
}

versionCheck(ctx, client, &resp.Diagnostics)

if resp.Diagnostics.HasError() {
return
}
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/user_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ func (d *userDataSource) Read(ctx context.Context, req datasource.ReadRequest, r
Id: types.StringValue(fmt.Sprintf("%v", user.Id)),
RootRole: types.Int64Value(int64(*user.RootRole)),
}
if user.Username != nil {
state.Username = types.StringValue(*user.Username)
if user.Username.IsSet() {
state.Username = types.StringValue(*user.Username.Get())
} else {
state.Username = types.StringNull()
}
Expand Down
12 changes: 6 additions & 6 deletions internal/provider/user_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ func (r *userResource) Create(ctx context.Context, req resource.CreateRequest, r
// Update model with response
plan.Id = types.StringValue(fmt.Sprintf("%v", user.Id))
plan.RootRole = types.Int64Value(int64(*user.RootRole.Int32))
if user.Username != nil {
plan.Username = types.StringValue(*user.Username)
if user.Username.IsSet() {
plan.Username = types.StringValue(*user.Username.Get())
} else {
plan.Username = types.StringNull()
}
Expand Down Expand Up @@ -192,8 +192,8 @@ func (r *userResource) Read(ctx context.Context, req resource.ReadRequest, resp
} else {
state.Email = types.StringNull()
}
if user.Username != nil {
state.Username = types.StringValue(*user.Username)
if user.Username.IsSet() {
state.Username = types.StringValue(*user.Username.Get())
} else {
state.Username = types.StringNull()
}
Expand Down Expand Up @@ -253,8 +253,8 @@ func (r *userResource) Update(ctx context.Context, req resource.UpdateRequest, r
} else {
state.Email = types.StringNull()
}
if user.Username != nil {
state.Username = types.StringValue(*user.Username)
if user.Username.IsSet() {
state.Username = types.StringValue(*user.Username.Get())
} else {
state.Username = types.StringNull()
}
Expand Down
Loading