-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6ca4f10
commit 7f0ac37
Showing
3 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters