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

+23-8
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

+1-1
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

+1-1
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

+1-1
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

+3-3
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

+2-2
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

+23-1
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

+1-1
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

+1-1
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

+1-1
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 {

codefresh/resource_pipeline.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package codefresh
33
import (
44
"fmt"
55
cfClient "github.com/codefresh-io/terraform-provider-codefresh/client"
6-
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
77
"strings"
88
)
99

codefresh/resource_pipeline_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package codefresh
33
import (
44
"fmt"
55
cfClient "github.com/codefresh-io/terraform-provider-codefresh/client"
6-
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
7-
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
8-
"github.com/hashicorp/terraform-plugin-sdk/terraform"
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
99
"regexp"
1010
"testing"
1111
)

codefresh/resource_project.go

+1-1
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 resourceProject() *schema.Resource {

codefresh/resource_project_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package codefresh
33
import (
44
"fmt"
55
cfClient "github.com/codefresh-io/terraform-provider-codefresh/client"
6-
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
7-
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
8-
"github.com/hashicorp/terraform-plugin-sdk/terraform"
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
99
"regexp"
1010
"testing"
1111
)

codefresh/resource_team.go

+1-1
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 resourceTeam() *schema.Resource {

codefresh/resource_user.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package codefresh
33
import (
44
"fmt"
55
cfClient "github.com/codefresh-io/terraform-provider-codefresh/client"
6-
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
77
)
88

99
func resourceUser() *schema.Resource {
@@ -253,7 +253,7 @@ func flattenUserLogins(logins *[]cfClient.Login) []map[string]interface{} {
253253

254254
m["idp"] = []map[string]interface{}{
255255
{
256-
"idp_id": login.IDP.ID,
256+
"idp_id": login.IDP.ID,
257257
"client_type": login.IDP.ClientType,
258258
},
259259
}
@@ -264,8 +264,6 @@ func flattenUserLogins(logins *[]cfClient.Login) []map[string]interface{} {
264264
return res
265265
}
266266

267-
268-
269267
func mapResourceToUser(d *schema.ResourceData) *cfClient.NewUser {
270268

271269
roles := d.Get("roles").(*schema.Set).List()
@@ -291,7 +289,6 @@ func mapResourceToUser(d *schema.ResourceData) *cfClient.NewUser {
291289

292290
logins := d.Get("login").([]interface{})
293291

294-
295292
for idx := range logins {
296293

297294
permissions := convertStringArr(d.Get(fmt.Sprintf("login.%v.credentials.0.permissions", idx)).([]interface{}))

go.mod

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
module github.com/codefresh-io/terraform-provider-codefresh
22

33
require (
4-
github.com/aws/aws-sdk-go v1.30.12
4+
github.com/aws/aws-sdk-go v1.30.12 // indirect
55
github.com/bflad/tfproviderdocs v0.6.0
66
github.com/bflad/tfproviderlint v0.14.0
77
github.com/client9/misspell v0.3.4
88
github.com/golangci/golangci-lint v1.27.0
9-
github.com/google/martian v2.1.0+incompatible
10-
github.com/hashicorp/terraform v0.12.25
11-
github.com/hashicorp/terraform-plugin-sdk v1.7.0
9+
github.com/hashicorp/terraform-config-inspect v0.0.0-20191212124732-c6ae6269b9d7 // indirect
10+
github.com/hashicorp/terraform-plugin-sdk/v2 v2.0.0-rc.2.0.20200717132200-7435e2abc9d1
1211
github.com/imdario/mergo v0.3.9
12+
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 // indirect
1313
)
1414

1515
go 1.13

0 commit comments

Comments
 (0)