Skip to content

Commit

Permalink
inital draft for user mgmt
Browse files Browse the repository at this point in the history
  • Loading branch information
SivaanandM committed Nov 5, 2024
1 parent 6ca4f10 commit 7f0ac37
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,4 @@ require (
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
)

//replace github.com/spectrocloud/palette-sdk-go => ../palette-sdk-go
replace github.com/spectrocloud/palette-sdk-go => ../palette-sdk-go
58 changes: 58 additions & 0 deletions spectrocloud/data_source_team.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package spectrocloud

import (
"context"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func dataSourceTeam() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceTeamRead,

Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ConflictsWith: []string{"name"},
Description: "The unique ID of the team. If provided, `name` cannot be used.",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "The name of the team. If provided, `id` cannot be used.",
},
},
}
}

func dataSourceTeamRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := getV1ClientWithResourceContext(m, "")
var diags diag.Diagnostics

if v, ok := d.GetOk("name"); ok {
team, err := c.GetTeam(v.(string))
if err != nil {
return diag.FromErr(err)
}
d.SetId(team.Metadata.UID)
if err := d.Set("email", team.Metadata.Name); err != nil {
return diag.FromErr(err)
}
} else {
if val, okay := d.GetOk("id"); okay && val != "" {
team, err := c.GetTeam(val.(string))
if err != nil {
return diag.FromErr(err)
}
d.SetId(team.Metadata.UID)
if err := d.Set("email", team.Metadata.Name); err != nil {
return diag.FromErr(err)
}
}

}
return diags
}
2 changes: 2 additions & 0 deletions spectrocloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ func New(_ string) func() *schema.Provider {
"spectrocloud_ssh_key": resourceSSHKey(),
},
DataSourcesMap: map[string]*schema.Resource{
"spectrocloud_team": dataSourceTeam(),

"spectrocloud_user": dataSourceUser(),
"spectrocloud_project": dataSourceProject(),

Expand Down

0 comments on commit 7f0ac37

Please sign in to comment.