Skip to content

Commit

Permalink
Keep up with unleash API latest (4.13) (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdelucaa authored Jul 1, 2022
1 parent dca1661 commit fde3e69
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 76 deletions.
8 changes: 8 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ Thank you for opening an issue. Please note that we try to keep the Terraform is
### Terraform Version
Run `terraform -v` to show the version. If you are not running the latest version of Terraform, please upgrade because your issue may have already been fixed.

### Provider Version
Please indicate the Provider version you are using.
If you are not running the latest version of the Provider, please upgrade because your issue may have already been fixed.

### Unleash Server Version
Please indicate the Unleash server version you are using.
We try to keep up to date with the changes in the Unleash API, the latest version of the provider should be compatible with the latest version of the Unleash server.

### Affected Resource(s)
Please list the resources as a list, for example:
- opc_instance
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ provider "unleash" {

To generate or update documentation, run `go generate`.

## Issues

Before opening any issues, please make sure you are running the latest version of the provider and the unleash server, we try to keep up to date with the changes in the Unleash API. :)

## LICENSE

License is MIT
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ go 1.16
require (
github.com/hashicorp/terraform-plugin-docs v0.11.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.17.0
github.com/philips-labs/go-unleash-api v0.1.1
github.com/philips-labs/go-unleash-api v1.0.0
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce h1:RPclfga2SEJmgMmz2k
github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce/go.mod h1:uFMI8w+ref4v2r9jz+c9i1IfIttS/OkmLfrk1jne5hs=
github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/philips-labs/go-unleash-api v0.1.1 h1:qakJasNmEHPTfOiYCPNjIrXiZ62C3n9gMjTBLCowNEQ=
github.com/philips-labs/go-unleash-api v0.1.1/go.mod h1:7iJbdxlvMu9VlRLpitWFavCifH8IsfYPc7EkDY3PFv4=
github.com/philips-labs/go-unleash-api v1.0.0 h1:/E/27iY/USyZmKeG1W3PHg1VjA3Nw/63QOit2dmOFt8=
github.com/philips-labs/go-unleash-api v1.0.0/go.mod h1:7iJbdxlvMu9VlRLpitWFavCifH8IsfYPc7EkDY3PFv4=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
22 changes: 7 additions & 15 deletions internal/provider/resource_strategy_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,12 @@ func resourceStrategyAssignmentCreate(ctx context.Context, d *schema.ResourceDat
return diag.FromErr(api.ErrNotFound)
}

if len(givenParams) != len(strategy.Parameters) {
return diag.FromErr(ErrStrategyParametersRequired)
}
convertedParams := make(map[string]interface{}) // convert provided params from string to the actual param type
convertedParams := make(map[string]interface{})
for _, param := range strategy.Parameters {
if _, ok := givenParams[param.Name]; !ok {
if _, ok := givenParams[param.Name]; !ok && param.Required {
return diag.FromErr(ErrStrategyParametersRequired)
}
value := givenParams[param.Name].(string)
convertedParams[param.Name] = newParameterInputConvertion()[param.Type](value)
convertedParams[param.Name] = givenParams[param.Name].(string)
}

featureStrategy.Parameters = convertedParams
Expand Down Expand Up @@ -151,7 +147,7 @@ func resourceStrategyAssignmentRead(ctx context.Context, d *schema.ResourceData,
convertedParams := make(map[string]interface{}) // convert actual param type back to string
retrievedParams := featureStrategy.Parameters
for _, param := range strategy.Parameters {
convertedParams[param.Name] = newParameterOutputConvertion()[param.Type](retrievedParams.(map[string]interface{})[param.Name])
convertedParams[param.Name] = retrievedParams.(map[string]interface{})[param.Name].(string)
}
_ = d.Set("parameters", convertedParams)
}
Expand Down Expand Up @@ -186,16 +182,12 @@ func resourceStrategyAssignmentUpdate(ctx context.Context, d *schema.ResourceDat
return diag.FromErr(api.ErrNotFound)
}

if len(vv) != len(found.Parameters) {
return diag.FromErr(ErrStrategyParametersRequired)
}
convertedParams := make(map[string]interface{}) // convert provided params from string to the actual param type
convertedParams := make(map[string]interface{})
for _, param := range found.Parameters {
if _, ok := vv[param.Name]; !ok {
if _, ok := vv[param.Name]; !ok && param.Required {
return diag.FromErr(ErrStrategyParametersRequired)
}
value := vv[param.Name].(string)
convertedParams[param.Name] = newParameterInputConvertion()[param.Type](value)
convertedParams[param.Name] = vv[param.Name].(string)
}

strategy.Parameters = convertedParams
Expand Down
61 changes: 61 additions & 0 deletions internal/provider/resource_strategy_assingment_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package provider

import (
"fmt"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/philips-labs/terraform-provider-unleash/utils"
)

func TestAccResourceStrategyAssignment(t *testing.T) {
resource.UnitTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: testAccResourceStrategyAssignment,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestMatchResourceAttr("unleash_strategy_assignment.foo", "feature_name", regexp.MustCompile("^bar")),
resource.TestMatchResourceAttr("unleash_strategy_assignment.foo", "project_id", regexp.MustCompile("^default$")),
resource.TestMatchResourceAttr("unleash_strategy_assignment.foo", "environment", regexp.MustCompile("^development$")),
resource.TestMatchResourceAttr("unleash_strategy_assignment.foo", "strategy_name", regexp.MustCompile("^flexibleRollout$")),
resource.TestMatchResourceAttr("unleash_strategy_assignment.foo", "parameters.rollout", regexp.MustCompile("^68$")),
resource.TestMatchResourceAttr("unleash_strategy_assignment.foo", "parameters.stickiness", regexp.MustCompile("^random$")),
resource.TestMatchResourceAttr("unleash_strategy_assignment.foo", "parameters.groupId", regexp.MustCompile("^toggle$")),
resource.TestMatchResourceAttr("unleash_strategy_assignment.foo2", "strategy_name", regexp.MustCompile("^userWithId$")),
resource.TestMatchResourceAttr("unleash_strategy_assignment.foo2", "parameters.userIds", regexp.MustCompile("xyz,bar")),
),
},
},
})
}

var testAccResourceStrategyAssignment = fmt.Sprintf(`
resource "unleash_feature" "foo" {
name = "bar%s"
project_id = "default"
type = "release"
}
resource "unleash_strategy_assignment" "foo" {
feature_name = unleash_feature.foo.name
project_id = "default"
environment = "development"
strategy_name = "flexibleRollout"
parameters = {
rollout = "68"
stickiness = "random"
groupId = "toggle"
}
}
resource "unleash_strategy_assignment" "foo2" {
feature_name = unleash_feature.foo.name
project_id = "default"
environment = "development"
strategy_name = "userWithId"
parameters = {
userIds = "xyz,bar"
}
}
`, utils.RandomString(4))
58 changes: 0 additions & 58 deletions internal/provider/strategy_params_convertion.go

This file was deleted.

0 comments on commit fde3e69

Please sign in to comment.