Skip to content

Commit

Permalink
provider-sdk-v2 + featuresFlag
Browse files Browse the repository at this point in the history
  • Loading branch information
Kosta Klevensky committed Jul 22, 2020
1 parent c5490af commit 44f6743
Show file tree
Hide file tree
Showing 19 changed files with 128 additions and 224 deletions.
31 changes: 23 additions & 8 deletions client/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package client
import (
"errors"
"fmt"
"log"
"strconv"

"github.com/imdario/mergo"
)
Expand Down Expand Up @@ -144,12 +142,7 @@ type AccountDetails struct {
func (account *Account) SetFeatures(m map[string]interface{}) {
res := make(map[string]bool)
for k, v := range m {
value := v.(string)
b, err := strconv.ParseBool(value)
if err != nil {
log.Fatalf("[ERROR] Can't parse '%s = %s' as boolean", k, value)
}
res[k] = b
res[k] = v.(bool)
}
account.Features = res
}
Expand Down Expand Up @@ -290,6 +283,28 @@ func (client *Client) UpdateAccount(account *Account) (*Account, error) {
if err != nil {
return nil, err
}

// Update Features
var featureUpdatePath string
for k, v := range account.Features{
//body
if v {
featureUpdatePath = fmt.Sprintf("/features/%s", id)
} else {
featureUpdatePath = fmt.Sprintf("/features/switchOff/%s", id)
}
bodyFeatures := []byte(fmt.Sprintf("{\"feature\": \"%s\"}", k))
_, err = client.RequestAPI(&RequestOptions{
Path: featureUpdatePath,
Method: "POST",
Body: bodyFeatures,
})
if err != nil {
return nil, err
}
respAccount.Features[k] = v
}


return &respAccount, nil
}
Expand Down
2 changes: 1 addition & 1 deletion client/api_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package client
import (
"errors"
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"log"
"net/http"
)
Expand Down
2 changes: 1 addition & 1 deletion codefresh/data_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"fmt"
cfClient "github.com/codefresh-io/terraform-provider-codefresh/client"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func dataSourceUser() *schema.Resource {
Expand Down
2 changes: 1 addition & 1 deletion codefresh/data_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package codefresh

import (
cfClient "github.com/codefresh-io/terraform-provider-codefresh/client"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"time"
)

Expand Down
6 changes: 3 additions & 3 deletions codefresh/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package codefresh

import (
cfClient "github.com/codefresh-io/terraform-provider-codefresh/client"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
//"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"os"
)

func Provider() terraform.ResourceProvider {
func Provider() *schema.Provider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"api_url": {
Expand Down
4 changes: 2 additions & 2 deletions codefresh/provider_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package codefresh

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"os"
"testing"
)
Expand Down
24 changes: 23 additions & 1 deletion codefresh/resource_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package codefresh

import (
cfClient "github.com/codefresh-io/terraform-provider-codefresh/client"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func resourceAccount() *schema.Resource {
Expand All @@ -26,6 +26,21 @@ func resourceAccount() *schema.Resource {
// Type: schema.TypeString,
// },
// },

"features": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeBool,
},
Default: map[string]bool{
"OfflineLogging": true,
"ssoManagement": true,
"teamsManagement": true,
"abac": true,
"customKubernetesCluster": true,
},
},
"limits": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -137,6 +152,10 @@ func mapAccountToResource(account *cfClient.Account, d *schema.ResourceData) err
// if err != nil {
// return err
// }
err = d.Set("features", account.Features)
if err != nil {
return err
}

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

if _, ok := d.GetOk("features"); ok {
account.SetFeatures(d.Get("features").(map[string]interface{}))
}
if _, ok := d.GetOk("limits"); ok {
account.Limits = &cfClient.Limits{
Collaborators: cfClient.Collaborators{
Expand Down
2 changes: 1 addition & 1 deletion codefresh/resource_account_admins.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package codefresh

import (
cfClient "github.com/codefresh-io/terraform-provider-codefresh/client"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func resourceAccountAdmins() *schema.Resource {
Expand Down
2 changes: 1 addition & 1 deletion codefresh/resource_api_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"fmt"
cfClient "github.com/codefresh-io/terraform-provider-codefresh/client"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func resourceApiKey() *schema.Resource {
Expand Down
2 changes: 1 addition & 1 deletion codefresh/resource_idp_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package codefresh

import (
cfClient "github.com/codefresh-io/terraform-provider-codefresh/client"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func resourceIDPAccounts() *schema.Resource {
Expand Down
2 changes: 1 addition & 1 deletion codefresh/resource_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package codefresh
import (
"fmt"
cfClient "github.com/codefresh-io/terraform-provider-codefresh/client"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"strings"
)

Expand Down
6 changes: 3 additions & 3 deletions codefresh/resource_pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package codefresh
import (
"fmt"
cfClient "github.com/codefresh-io/terraform-provider-codefresh/client"
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"regexp"
"testing"
)
Expand Down
2 changes: 1 addition & 1 deletion codefresh/resource_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package codefresh

import (
cfClient "github.com/codefresh-io/terraform-provider-codefresh/client"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func resourceProject() *schema.Resource {
Expand Down
6 changes: 3 additions & 3 deletions codefresh/resource_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package codefresh
import (
"fmt"
cfClient "github.com/codefresh-io/terraform-provider-codefresh/client"
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"regexp"
"testing"
)
Expand Down
2 changes: 1 addition & 1 deletion codefresh/resource_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package codefresh

import (
cfClient "github.com/codefresh-io/terraform-provider-codefresh/client"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func resourceTeam() *schema.Resource {
Expand Down
7 changes: 2 additions & 5 deletions codefresh/resource_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package codefresh
import (
"fmt"
cfClient "github.com/codefresh-io/terraform-provider-codefresh/client"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

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

m["idp"] = []map[string]interface{}{
{
"idp_id": login.IDP.ID,
"idp_id": login.IDP.ID,
"client_type": login.IDP.ClientType,
},
}
Expand All @@ -264,8 +264,6 @@ func flattenUserLogins(logins *[]cfClient.Login) []map[string]interface{} {
return res
}



func mapResourceToUser(d *schema.ResourceData) *cfClient.NewUser {

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

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


for idx := range logins {

permissions := convertStringArr(d.Get(fmt.Sprintf("login.%v.credentials.0.permissions", idx)).([]interface{}))
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module github.com/codefresh-io/terraform-provider-codefresh

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

go 1.13
Loading

0 comments on commit 44f6743

Please sign in to comment.