Skip to content

Commit 44f6743

Browse files
author
Kosta Klevensky
committed
provider-sdk-v2 + featuresFlag
1 parent c5490af commit 44f6743

19 files changed

+128
-224
lines changed

client/account.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package client
33
import (
44
"errors"
55
"fmt"
6-
"log"
7-
"strconv"
86

97
"github.com/imdario/mergo"
108
)
@@ -144,12 +142,7 @@ type AccountDetails struct {
144142
func (account *Account) SetFeatures(m map[string]interface{}) {
145143
res := make(map[string]bool)
146144
for k, v := range m {
147-
value := v.(string)
148-
b, err := strconv.ParseBool(value)
149-
if err != nil {
150-
log.Fatalf("[ERROR] Can't parse '%s = %s' as boolean", k, value)
151-
}
152-
res[k] = b
145+
res[k] = v.(bool)
153146
}
154147
account.Features = res
155148
}
@@ -290,6 +283,28 @@ func (client *Client) UpdateAccount(account *Account) (*Account, error) {
290283
if err != nil {
291284
return nil, err
292285
}
286+
287+
// Update Features
288+
var featureUpdatePath string
289+
for k, v := range account.Features{
290+
//body
291+
if v {
292+
featureUpdatePath = fmt.Sprintf("/features/%s", id)
293+
} else {
294+
featureUpdatePath = fmt.Sprintf("/features/switchOff/%s", id)
295+
}
296+
bodyFeatures := []byte(fmt.Sprintf("{\"feature\": \"%s\"}", k))
297+
_, err = client.RequestAPI(&RequestOptions{
298+
Path: featureUpdatePath,
299+
Method: "POST",
300+
Body: bodyFeatures,
301+
})
302+
if err != nil {
303+
return nil, err
304+
}
305+
respAccount.Features[k] = v
306+
}
307+
293308

294309
return &respAccount, nil
295310
}

client/api_key.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package client
33
import (
44
"errors"
55
"fmt"
6-
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
77
"log"
88
"net/http"
99
)

codefresh/data_user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"errors"
55
"fmt"
66
cfClient "github.com/codefresh-io/terraform-provider-codefresh/client"
7-
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
88
)
99

1010
func dataSourceUser() *schema.Resource {

codefresh/data_users.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package codefresh
22

33
import (
44
cfClient "github.com/codefresh-io/terraform-provider-codefresh/client"
5-
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
5+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
66
"time"
77
)
88

codefresh/provider.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ package codefresh
22

33
import (
44
cfClient "github.com/codefresh-io/terraform-provider-codefresh/client"
5-
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
6-
"github.com/hashicorp/terraform-plugin-sdk/terraform"
5+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
6+
//"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
77
"os"
88
)
99

10-
func Provider() terraform.ResourceProvider {
10+
func Provider() *schema.Provider {
1111
return &schema.Provider{
1212
Schema: map[string]*schema.Schema{
1313
"api_url": {

codefresh/provider_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package codefresh
22

33
import (
4-
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
5-
"github.com/hashicorp/terraform-plugin-sdk/terraform"
4+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
5+
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
66
"os"
77
"testing"
88
)

codefresh/resource_account.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package codefresh
22

33
import (
44
cfClient "github.com/codefresh-io/terraform-provider-codefresh/client"
5-
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
5+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
66
)
77

88
func resourceAccount() *schema.Resource {
@@ -26,6 +26,21 @@ func resourceAccount() *schema.Resource {
2626
// Type: schema.TypeString,
2727
// },
2828
// },
29+
30+
"features": {
31+
Type: schema.TypeMap,
32+
Optional: true,
33+
Elem: &schema.Schema{
34+
Type: schema.TypeBool,
35+
},
36+
Default: map[string]bool{
37+
"OfflineLogging": true,
38+
"ssoManagement": true,
39+
"teamsManagement": true,
40+
"abac": true,
41+
"customKubernetesCluster": true,
42+
},
43+
},
2944
"limits": {
3045
Type: schema.TypeList,
3146
Optional: true,
@@ -137,6 +152,10 @@ func mapAccountToResource(account *cfClient.Account, d *schema.ResourceData) err
137152
// if err != nil {
138153
// return err
139154
// }
155+
err = d.Set("features", account.Features)
156+
if err != nil {
157+
return err
158+
}
140159

141160
err = d.Set("limits", []map[string]interface{}{flattenLimits(*account.Limits)})
142161
if err != nil {
@@ -173,6 +192,9 @@ func mapResourceToAccount(d *schema.ResourceData) *cfClient.Account {
173192
// Admins: convertStringArr(admins),
174193
}
175194

195+
if _, ok := d.GetOk("features"); ok {
196+
account.SetFeatures(d.Get("features").(map[string]interface{}))
197+
}
176198
if _, ok := d.GetOk("limits"); ok {
177199
account.Limits = &cfClient.Limits{
178200
Collaborators: cfClient.Collaborators{

codefresh/resource_account_admins.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package codefresh
22

33
import (
44
cfClient "github.com/codefresh-io/terraform-provider-codefresh/client"
5-
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
5+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
66
)
77

88
func resourceAccountAdmins() *schema.Resource {

codefresh/resource_api_key.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"errors"
55
"fmt"
66
cfClient "github.com/codefresh-io/terraform-provider-codefresh/client"
7-
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
88
)
99

1010
func resourceApiKey() *schema.Resource {

codefresh/resource_idp_accounts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package codefresh
22

33
import (
44
cfClient "github.com/codefresh-io/terraform-provider-codefresh/client"
5-
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
5+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
66
)
77

88
func resourceIDPAccounts() *schema.Resource {

0 commit comments

Comments
 (0)