-
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.
* PLT-1470: Added data source support for team.
- Loading branch information
1 parent
f5d27fc
commit 8ef7f1e
Showing
8 changed files
with
159 additions
and
3 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "spectrocloud_team Data Source - terraform-provider-spectrocloud" | ||
subcategory: "" | ||
description: |- | ||
--- | ||
|
||
# spectrocloud_team (Data Source) | ||
|
||
|
||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "spectrocloud_team" "team1" { | ||
name = "team2" | ||
# (alternatively) | ||
# id = "5fd0ca727c411c71b55a359c" | ||
} | ||
output "team-id" { | ||
value = data.spectrocloud_team.team1.id | ||
} | ||
output "team-role-ids" { | ||
value = data.spectrocloud_team.team1.role_ids | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Optional | ||
|
||
- `id` (String) The unique ID of the team. If provided, `name` cannot be used. | ||
- `name` (String) The name of the team. If provided, `id` cannot be used. | ||
|
||
### Read-Only | ||
|
||
- `role_ids` (List of String) The roles id's assigned to the team. |
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,14 @@ | ||
data "spectrocloud_team" "team1" { | ||
name = "team2" | ||
|
||
# (alternatively) | ||
# id = "5fd0ca727c411c71b55a359c" | ||
} | ||
|
||
output "team-id" { | ||
value = data.spectrocloud_team.team1.id | ||
} | ||
|
||
output "team-role-ids" { | ||
value = data.spectrocloud_team.team1.role_ids | ||
} |
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,28 @@ | ||
terraform { | ||
required_providers { | ||
spectrocloud = { | ||
version = ">= 0.1" | ||
source = "spectrocloud/spectrocloud" | ||
} | ||
} | ||
} | ||
|
||
variable "sc_host" { | ||
description = "Spectro Cloud Endpoint" | ||
default = "api.spectrocloud.com" | ||
} | ||
|
||
variable "sc_api_key" { | ||
description = "Spectro Cloud API key" | ||
} | ||
|
||
variable "sc_project_name" { | ||
description = "Spectro Cloud Project (e.g: Default)" | ||
default = "Default" | ||
} | ||
|
||
provider "spectrocloud" { | ||
host = var.sc_host | ||
api_key = var.sc_api_key | ||
project_name = var.sc_project_name | ||
} |
4 changes: 4 additions & 0 deletions
4
examples/data-sources/spectrocloud_team/terraform.template.tfvars
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,4 @@ | ||
# Spectro Cloud credentials | ||
sc_host = "{Enter Spectro Cloud API Host}" #e.g: api.spectrocloud.com (for SaaS) | ||
sc_api_key = "{Enter Spectro Cloud API Key}" | ||
sc_project_name = "{Enter Spectro Cloud Project Name}" #e.g: Default |
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
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,66 @@ | ||
package spectrocloud | ||
|
||
import ( | ||
"context" | ||
"github.com/spectrocloud/palette-sdk-go/api/models" | ||
|
||
"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.", | ||
}, | ||
"role_ids": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
Description: "The roles id's assigned to the team.", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceTeamRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
c := getV1ClientWithResourceContext(m, "") | ||
var diags diag.Diagnostics | ||
var team *models.V1Team | ||
var err error | ||
if v, ok := d.GetOk("name"); ok { | ||
team, err = c.GetTeamWithName(v.(string)) | ||
if 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) | ||
} | ||
} | ||
} | ||
if team != nil { | ||
d.SetId(team.Metadata.UID) | ||
if err := d.Set("name", team.Metadata.Name); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
if err := d.Set("role_ids", team.Spec.Roles); 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